mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 00:44:52 +01:00
Merge branch 'hotfix/celaction-workfile-versioning'
This commit is contained in:
commit
1370af1ca8
1 changed files with 2 additions and 50 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import shutil
|
import shutil
|
||||||
import re
|
import pype
|
||||||
import pyblish.api
|
import pyblish.api
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -12,57 +12,9 @@ class VersionUpScene(pyblish.api.ContextPlugin):
|
||||||
|
|
||||||
def process(self, context):
|
def process(self, context):
|
||||||
current_file = context.data.get('currentFile')
|
current_file = context.data.get('currentFile')
|
||||||
v_up = get_version_up(current_file)
|
v_up = pype.lib.version_up(current_file)
|
||||||
self.log.debug('Current file is: {}'.format(current_file))
|
self.log.debug('Current file is: {}'.format(current_file))
|
||||||
self.log.debug('Version up: {}'.format(v_up))
|
self.log.debug('Version up: {}'.format(v_up))
|
||||||
|
|
||||||
shutil.copy2(current_file, v_up)
|
shutil.copy2(current_file, v_up)
|
||||||
self.log.info('Scene saved into new version: {}'.format(v_up))
|
self.log.info('Scene saved into new version: {}'.format(v_up))
|
||||||
|
|
||||||
|
|
||||||
def version_get(string, prefix, suffix=None):
|
|
||||||
"""Extract version information from filenames used by DD (and Weta, apparently)
|
|
||||||
These are _v# or /v# or .v# where v is a prefix string, in our case
|
|
||||||
we use "v" for render version and "c" for camera track version.
|
|
||||||
See the version.py and camera.py plugins for usage."""
|
|
||||||
|
|
||||||
if string is None:
|
|
||||||
raise ValueError("Empty version string - no match")
|
|
||||||
|
|
||||||
regex = r"[/_.]{}\d+".format(prefix)
|
|
||||||
matches = re.findall(regex, string, re.IGNORECASE)
|
|
||||||
if not len(matches):
|
|
||||||
msg = f"No `_{prefix}#` found in `{string}`"
|
|
||||||
raise ValueError(msg)
|
|
||||||
return (matches[-1:][0][1], re.search(r"\d+", matches[-1:][0]).group())
|
|
||||||
|
|
||||||
|
|
||||||
def version_set(string, prefix, oldintval, newintval):
|
|
||||||
"""Changes version information from filenames used by DD (and Weta, apparently)
|
|
||||||
These are _v# or /v# or .v# where v is a prefix string, in our case
|
|
||||||
we use "v" for render version and "c" for camera track version.
|
|
||||||
See the version.py and camera.py plugins for usage."""
|
|
||||||
|
|
||||||
regex = r"[/_.]{}\d+".format(prefix)
|
|
||||||
matches = re.findall(regex, string, re.IGNORECASE)
|
|
||||||
if not len(matches):
|
|
||||||
return ""
|
|
||||||
|
|
||||||
# Filter to retain only version strings with matching numbers
|
|
||||||
matches = filter(lambda s: int(s[2:]) == oldintval, matches)
|
|
||||||
|
|
||||||
# Replace all version strings with matching numbers
|
|
||||||
for match in matches:
|
|
||||||
# use expression instead of expr so 0 prefix does not make octal
|
|
||||||
fmt = "%%(#)0%dd" % (len(match) - 2)
|
|
||||||
newfullvalue = match[0] + prefix + str(fmt % {"#": newintval})
|
|
||||||
string = re.sub(match, newfullvalue, string)
|
|
||||||
return string
|
|
||||||
|
|
||||||
|
|
||||||
def get_version_up(path):
|
|
||||||
""" Returns the next version of the path """
|
|
||||||
|
|
||||||
(prefix, v) = version_get(path, 'v')
|
|
||||||
v = int(v)
|
|
||||||
return version_set(path, prefix, v, v + 1)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue