-
Notifications
You must be signed in to change notification settings - Fork 63
Add support for removing version AND (not or) framenumber. #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 '.####' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice catch! my cut and paste error. |
||
| # 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops! |
||
| # 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): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggest making the new arg
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, my suggestion is ambiguous... but do you mean 'strip_version' in this case?... because currently, with sequence = False, the version is removed, but if sequence=True, then the version remains. So we need both strip_version and strip_frame I think... and to cover all bases you might as well add a strip_ext option too!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My preference here would be to include the most common behaviors, keeping the interface fairly clean. Now that I'm looking at this again, maybe we should have just done something like this from the start:
Maybe that would be sufficient and keep things simple (for most cases) and consistent. Anything beyond that would imply taking over the hook. Curious what you think. |
||
| """ | ||
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we don't need the additional regex? Can we make this a 2-pass process if the additional arg is supplied? if the assumption is that the frame number is always after the version number (when both are included) maybe the logic should be: if strip_frame and frame_pattern_match:
# remove the frame number with the existing frame regex
# continue with the existing logic...
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the best approach. I did consider that this might be possible, but in the end went with the simple option of formulating a specific regex. |
||
|
|
||
| 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: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comments above. |
||
| # 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 | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guessing this was left by accident?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed.