From 84ef2926ae0d0ee567b77e6758faae3643c3e485 Mon Sep 17 00:00:00 2001 From: aardschok Date: Wed, 16 Aug 2017 17:57:39 +0200 Subject: [PATCH] added image sequence collector --- .../plugins/publish/collect_imagesequences.py | 57 +++++++++++++++++++ .../publish/collect_shell_workspace.py | 14 +++++ 2 files changed, 71 insertions(+) create mode 100644 colorbleed/plugins/publish/collect_imagesequences.py create mode 100644 colorbleed/plugins/publish/collect_shell_workspace.py diff --git a/colorbleed/plugins/publish/collect_imagesequences.py b/colorbleed/plugins/publish/collect_imagesequences.py new file mode 100644 index 0000000000..bdb703f421 --- /dev/null +++ b/colorbleed/plugins/publish/collect_imagesequences.py @@ -0,0 +1,57 @@ +import pyblish.api + + +class CollectMindbenderImageSequences(pyblish.api.ContextPlugin): + """Gather image sequnences from working directory""" + + order = pyblish.api.CollectorOrder + hosts = ["shell"] + label = "Image Sequences" + + def process(self, context): + import os + import json + from avalon.vendor import clique + + workspace = context.data["workspaceDir"] + + base, dirs, _ = next(os.walk(workspace)) + for renderlayer in dirs: + abspath = os.path.join(base, renderlayer) + files = os.listdir(abspath) + collections, remainder = clique.assemble(files, minimum_items=1) + assert not remainder, ( + "There shouldn't have been a remainder for '%s': " + "%s" % (renderlayer, remainder)) + + # Maya 2017 compatibility, it inexplicably prefixes layers + # with "rs_" without warning. + compatpath = os.path.join(base, renderlayer.split("rs_", 1)[-1]) + + for fname in (abspath, compatpath): + try: + with open(fname + ".json") as f: + metadata = json.load(f) + break + + except OSError: + continue + + else: + raise Exception("%s was not published correctly " + "(missing metadata)" % renderlayer) + + for collection in collections: + instance = context.create_instance(str(collection)) + + data = dict(metadata["instance"], **{ + "name": instance.name, + "family": "Image Sequences", + "families": ["colorbleed.imagesequence"], + "subset": collection.head[:-1], + "stagingDir": os.path.join(workspace, renderlayer), + "files": [list(collection)], + "metadata": metadata + }) + + instance.data.update(data) diff --git a/colorbleed/plugins/publish/collect_shell_workspace.py b/colorbleed/plugins/publish/collect_shell_workspace.py new file mode 100644 index 0000000000..566b348ab9 --- /dev/null +++ b/colorbleed/plugins/publish/collect_shell_workspace.py @@ -0,0 +1,14 @@ +import os +import pyblish.api + + +class CollectShellWorkspace(pyblish.api.ContextPlugin): + """Inject the current workspace into context""" + + order = pyblish.api.CollectorOrder - 0.5 + label = "Shell Workspace" + + hosts = ["shell"] + + def process(self, context): + context.data["workspaceDir"] = os.getcwd()