feat(fusion): update from colorbleed

This commit is contained in:
Jakub Jezek 2020-08-19 10:38:37 +02:00
parent 9943f94f64
commit a2ecd25201
No known key found for this signature in database
GPG key ID: C4B96E101D2A47F3
2 changed files with 46 additions and 89 deletions

View file

@ -95,6 +95,15 @@ def _format_filepath(session):
def _update_savers(comp, session):
"""Update all savers of the current comp to ensure the output is correct
This will refactor the Saver file outputs to the renders of the new session
that is provided.
In the case the original saver path had a path set relative to a /fusion/
folder then that relative path will be matched with the exception of all
"version" (e.g. v010) references will be reset to v001. Otherwise only a
version folder will be computed in the new session's work "render" folder
to dump the files in and keeping the original filenames.
Args:
comp (object): current comp instance
session (dict): the current Avalon session
@ -114,8 +123,36 @@ def _update_savers(comp, session):
savers = comp.GetToolList(False, "Saver").values()
for saver in savers:
filepath = saver.GetAttrs("TOOLST_Clip_Name")[1.0]
filename = os.path.basename(filepath)
new_path = os.path.join(renders_version, filename)
# Get old relative path to the "fusion" app folder so we can apply
# the same relative path afterwards. If not found fall back to
# using just a version folder with the filename in it.
# todo: can we make this less magical?
relpath = filepath.replace("\\", "/").rsplit("/fusion/", 1)[-1]
if os.path.isabs(relpath):
# If not relative to a "/fusion/" folder then just use filename
filename = os.path.basename(filepath)
log.warning("Can't parse relative path, refactoring to only"
"filename in a version folder: %s" % filename)
new_path = os.path.join(renders_version, filename)
else:
# Else reuse the relative path
# Reset version in folder and filename in the relative path
# to v001. The version should be is only detected when prefixed
# with either `_v` (underscore) or `/v` (folder)
version_pattern = r"(/|_)v[0-9]+"
if re.search(version_pattern, relpath):
new_relpath = re.sub(version_pattern,
r"\1v001",
relpath)
log.info("Resetting version folders to v001: "
"%s -> %s" % (relpath, new_relpath))
relpath = new_relpath
new_path = os.path.join(new_work, relpath)
saver["Clip"] = new_path
@ -138,6 +175,13 @@ def update_frame_range(comp, representations):
versions = io.find({"type": "version", "_id": {"$in": version_ids}})
versions = list(versions)
versions = [v for v in versions
if v["data"].get("startFrame", None) is not None]
if not versions:
log.warning("No versions loaded to match frame range to.\n")
return
start = min(v["data"]["frameStart"] for v in versions)
end = max(v["data"]["frameEnd"] for v in versions)

View file

@ -1,87 +0,0 @@
"""This module is used for command line publishing of image sequences."""
import os
import sys
import logging
handler = logging.basicConfig()
log = logging.getLogger("Publish Image Sequences")
log.setLevel(logging.DEBUG)
error_format = "Failed {plugin.__name__}: {error} -- {error.traceback}"
def publish(paths, gui=False):
"""Publish rendered image sequences based on the job data
Args:
paths (list): a list of paths where to publish from
gui (bool, Optional): Choose to show Pyblish GUI, default is False
Returns:
None
"""
assert isinstance(paths, (list, tuple)), "Must be list of paths"
log.info(paths)
assert any(paths), "No paths found in the list"
# Set the paths to publish for the collector if any provided
if paths:
os.environ["FILESEQUENCE"] = os.pathsep.join(paths)
# Install Avalon with shell as current host
from avalon import api, shell
api.install(shell)
# Register target and host
import pyblish.api
pyblish.api.register_target("filesequence")
pyblish.api.register_host("shell")
# Publish items
if gui:
import pyblish_qml
pyblish_qml.show(modal=True)
else:
import pyblish.util
context = pyblish.util.publish()
if not context:
log.warning("Nothing collected.")
sys.exit(1)
# Collect errors, {plugin name: error}
error_results = [r for r in context.data["results"] if r["error"]]
if error_results:
log.error(" Errors occurred ...")
for result in error_results:
log.error(error_format.format(**result))
sys.exit(2)
def __main__():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--paths",
nargs="*",
default=[],
help="The filepaths to publish. This can be a "
"directory or a path to a .json publish "
"configuration.")
parser.add_argument("--gui",
default=False,
action="store_true",
help="Whether to run Pyblish in GUI mode.")
kwargs, args = parser.parse_known_args()
print("Running publish imagesequence...")
print("Paths: {}".format(kwargs.paths or [os.getcwd()]))
publish(kwargs.paths, gui=kwargs.gui)
if __name__ == '__main__':
__main__()