From 0e9248e80426a6d264f12dd5643779cbb94bcd77 Mon Sep 17 00:00:00 2001 From: Patrick Macdonald <4705216+reformstudios@users.noreply.github.com> Date: Wed, 11 Apr 2018 11:17:41 +0100 Subject: [PATCH] Add support for removing version AND (not or) framenumber. The existing regex patterns only handle either removing the version number from a non-sequence path or the frame-number from a sequence path, not both together (removing the version and converting the frame number to padding). This update adds a new regex pattern that should(I'm a regex novice) allow removal of version number from a sequence and conversion of framenumber to padding. --- hooks/path_info.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/hooks/path_info.py b/hooks/path_info.py index 3f1db80d..62b8291d 100644 --- a/hooks/path_info.py +++ b/hooks/path_info.py @@ -1,3 +1,7 @@ +''' +(.*)([._-])v(.*)([._-])(\d+)\.([^.]+)$ +''' + # Copyright (c) 2017 Shotgun Software Inc. # # CONFIDENTIAL AND PROPRIETARY @@ -24,18 +28,24 @@ VERSION_REGEX = re.compile("(.*)([._-])v(\d+)\.?([^.]+)?$", re.IGNORECASE) # a regular expression used to extract the frame number from the file. -# this implementation assumes the version number is of the form '.####' +# this implementation assumes the frame number is of the form '.####' # coming just before the extension in the filename and just after a '.', '_', # or '-'. FRAME_REGEX = re.compile("(.*)([._-])(\d+)\.([^.]+)$", re.IGNORECASE) +# a regular expression used to extrand the frame number AND version from the file. +# this implementation assumes the frame number is of the form '.####' +# coming just before the extension in the filename and just after a '.', '_', +# or '-'. +# also assuming the version number is of the form 'v###' coming before the frame number and frame seperator. +VERSION_FRAME_REGEX = re.compile("(.*)([._-])v(.*)([._-])(\d+)\.([^.]+)$", re.IGNORECASE) class BasicPathInfo(HookBaseClass): """ Methods for basic file path parsing. """ - def get_publish_name(self, path, sequence=False): + def get_publish_name(self, path, sequence=False, version=False): """ Given a file path, return the display name to use for publishing. @@ -70,6 +80,7 @@ def get_publish_name(self, path, sequence=False): version_pattern_match = re.search(VERSION_REGEX, filename) frame_pattern_match = re.search(FRAME_REGEX, filename) + version_frame_pattern_match = re.search(VERSION_FRAME_REGEX, filename) if version_pattern_match: # found a version number, use the other groups to remove it @@ -88,6 +99,17 @@ def get_publish_name(self, path, sequence=False): extension = frame_pattern_match.group(4) or "" publish_name = "%s%s%s.%s" % ( prefix, frame_sep, display_str, extension) + elif version_frame_pattern_match and sequence and version: + # found a frame number, meplace it with #s + prefix = version_frame_pattern_match.group(1) + version_sep = version_frame_pattern_match.group(2) + version = version_frame_pattern_match.group(3) + frame_sep = version_frame_pattern_match.group(4) + frame = version_frame_pattern_match.group(5) + display_str = "#" * len(frame) + extension = version_frame_pattern_match.group(6) or "" + publish_name = "%s%s%s.%s" % ( + prefix, frame_sep, display_str, extension) else: publish_name = filename