diff --git a/.github/workflows/automate-projects.yml b/.github/workflows/automate-projects.yml new file mode 100644 index 0000000000..b605071c2d --- /dev/null +++ b/.github/workflows/automate-projects.yml @@ -0,0 +1,19 @@ +name: Automate Projects + +on: + issues: + types: [opened, labeled] +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + assign_one_project: + runs-on: ubuntu-latest + name: Assign to One Project + steps: + - name: Assign NEW bugs to triage + uses: srggrs/assign-one-project-github-action@1.2.0 + if: contains(github.event.issue.labels.*.name, 'bug') + with: + project: 'https://github.com/pypeclub/pype/projects/2' + column_name: 'Needs triage' diff --git a/pype/harmony/__init__.py b/pype/harmony/__init__.py new file mode 100644 index 0000000000..b3edca7d15 --- /dev/null +++ b/pype/harmony/__init__.py @@ -0,0 +1,39 @@ +import os + +from avalon import api, harmony +import pyblish.api + + +def install(): + print("Installing Pype config...") + + plugins_directory = os.path.join( + os.path.dirname(os.path.dirname(__file__)), "plugins", "harmony" + ) + + pyblish.api.register_plugin_path( + os.path.join(plugins_directory, "publish") + ) + api.register_plugin_path( + api.Loader, os.path.join(plugins_directory, "load") + ) + api.register_plugin_path( + api.Creator, os.path.join(plugins_directory, "create") + ) + + pyblish.api.register_callback( + "instanceToggled", on_pyblish_instance_toggled + ) + + +def on_pyblish_instance_toggled(instance, old_value, new_value): + """Toggle node enabling on instance toggles.""" + func = """function func(args) + { + node.setEnable(args[0], args[1]) + } + func + """ + harmony.send( + {"function": func, "args": [instance[0], new_value]} + ) diff --git a/pype/plugins/global/publish/extract_review.py b/pype/plugins/global/publish/extract_review.py index 228b4cd6f4..4dd85a9810 100644 --- a/pype/plugins/global/publish/extract_review.py +++ b/pype/plugins/global/publish/extract_review.py @@ -22,7 +22,7 @@ class ExtractReview(pyblish.api.InstancePlugin): label = "Extract Review" order = pyblish.api.ExtractorOrder + 0.02 families = ["review"] - hosts = ["nuke", "maya", "shell", "nukestudio", "premiere"] + hosts = ["nuke", "maya", "shell", "nukestudio", "premiere", "harmony"] # Supported extensions image_exts = ["exr", "jpg", "jpeg", "png", "dpx"] diff --git a/pype/plugins/global/publish/integrate_new.py b/pype/plugins/global/publish/integrate_new.py index bd908901cc..fd76b19eb9 100644 --- a/pype/plugins/global/publish/integrate_new.py +++ b/pype/plugins/global/publish/integrate_new.py @@ -81,7 +81,8 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): "assembly", "fbx", "textures", - "action" + "action", + "harmony.template" ] exclude_families = ["clip"] db_representation_context_keys = [ diff --git a/pype/plugins/harmony/create/create_render.py b/pype/plugins/harmony/create/create_render.py new file mode 100644 index 0000000000..493c585a09 --- /dev/null +++ b/pype/plugins/harmony/create/create_render.py @@ -0,0 +1,25 @@ +from avalon import harmony + + +class CreateRender(harmony.Creator): + """Composite node for publishing renders.""" + + name = "renderDefault" + label = "Render" + family = "render" + node_type = "WRITE" + + def __init__(self, *args, **kwargs): + super(CreateRender, self).__init__(*args, **kwargs) + + def setup_node(self, node): + func = """function func(args) + { + node.setTextAttr(args[0], "DRAWING_TYPE", 1, "PNG4"); + node.setTextAttr(args[0], "DRAWING_NAME", 1, args[1]); + node.setTextAttr(args[0], "MOVIE_PATH", 1, args[1]); + } + func + """ + path = "{0}/{0}".format(node.split("/")[-1]) + harmony.send({"function": func, "args": [node, path]}) diff --git a/pype/plugins/harmony/create/create_template.py b/pype/plugins/harmony/create/create_template.py new file mode 100644 index 0000000000..babc3fe8d7 --- /dev/null +++ b/pype/plugins/harmony/create/create_template.py @@ -0,0 +1,12 @@ +from avalon import harmony + + +class CreateTemplate(harmony.Creator): + """Composite node for publishing to templates.""" + + name = "templateDefault" + label = "Template" + family = "harmony.template" + + def __init__(self, *args, **kwargs): + super(CreateTemplate, self).__init__(*args, **kwargs) diff --git a/pype/plugins/harmony/load/load_template.py b/pype/plugins/harmony/load/load_template.py new file mode 100644 index 0000000000..0bc9706407 --- /dev/null +++ b/pype/plugins/harmony/load/load_template.py @@ -0,0 +1,48 @@ +import tempfile +import zipfile +import os +import shutil + +from avalon import api, harmony + + +class ImportTemplateLoader(api.Loader): + """Import templates.""" + + families = ["harmony.template"] + representations = ["*"] + label = "Import Template" + + def load(self, context, name=None, namespace=None, data=None): + temp_dir = tempfile.mkdtemp() + zip_file = api.get_representation_path(context["representation"]) + template_path = os.path.join(temp_dir, "temp.tpl") + with zipfile.ZipFile(zip_file, "r") as zip_ref: + zip_ref.extractall(template_path) + + func = """function func(args) + { + var template_path = args[0]; + var drag_object = copyPaste.copyFromTemplate( + template_path, 0, 0, copyPaste.getCurrentCreateOptions() + ); + copyPaste.pasteNewNodes( + drag_object, "", copyPaste.getCurrentPasteOptions() + ); + } + func + """ + + func = """function func(args) + { + var template_path = args[0]; + var drag_object = copyPaste.pasteTemplateIntoGroup( + template_path, "Top", 1 + ); + } + func + """ + + harmony.send({"function": func, "args": [template_path]}) + + shutil.rmtree(temp_dir) diff --git a/pype/plugins/harmony/publish/collect_current_file.py b/pype/plugins/harmony/publish/collect_current_file.py new file mode 100644 index 0000000000..aab66c2b62 --- /dev/null +++ b/pype/plugins/harmony/publish/collect_current_file.py @@ -0,0 +1,27 @@ +import os + +import pyblish.api +from avalon import harmony + + +class CollectCurrentFile(pyblish.api.ContextPlugin): + """Inject the current working file into context""" + + order = pyblish.api.CollectorOrder - 0.5 + label = "Current File" + hosts = ["harmony"] + + def process(self, context): + """Inject the current working file""" + func = """function func() + { + return ( + scene.currentProjectPath() + "/" + + scene.currentVersionName() + ".xstage" + ); + } + func + """ + + current_file = harmony.send({"function": func})["result"] + context.data["currentFile"] = os.path.normpath(current_file) diff --git a/pype/plugins/harmony/publish/collect_instances.py b/pype/plugins/harmony/publish/collect_instances.py new file mode 100644 index 0000000000..9626cb3693 --- /dev/null +++ b/pype/plugins/harmony/publish/collect_instances.py @@ -0,0 +1,56 @@ +import json + +import pyblish.api +from avalon import harmony + + +class CollectInstances(pyblish.api.ContextPlugin): + """Gather instances by nodes metadata. + + This collector takes into account assets that are associated with + a composite node and marked with a unique identifier; + + Identifier: + id (str): "pyblish.avalon.instance" + """ + + label = "Instances" + order = pyblish.api.CollectorOrder + hosts = ["harmony"] + families_mapping = { + "render": ["imagesequence", "review"], + "harmony.template": [] + } + + def process(self, context): + nodes = harmony.send( + {"function": "node.subNodes", "args": ["Top"]} + )["result"] + + for node in nodes: + data = harmony.read(node) + + # Skip non-tagged nodes. + if not data: + continue + + # Skip containers. + if "container" in data["id"]: + continue + + instance = context.create_instance(node.split("/")[-1]) + instance.append(node) + instance.data.update(data) + instance.data["publish"] = harmony.send( + {"function": "node.getEnable", "args": [node]} + )["result"] + instance.data["families"] = self.families_mapping[data["family"]] + instance.data["families"].append("ftrack") + + # Produce diagnostic message for any graphical + # user interface interested in visualising it. + self.log.info( + "Found: \"{0}\": \n{1}".format( + instance.data["name"], json.dumps(instance.data, indent=4) + ) + ) diff --git a/pype/plugins/harmony/publish/extract_render.py b/pype/plugins/harmony/publish/extract_render.py new file mode 100644 index 0000000000..de6e8b9008 --- /dev/null +++ b/pype/plugins/harmony/publish/extract_render.py @@ -0,0 +1,100 @@ +import os +import tempfile + +import pyblish.api +from avalon import harmony +import pype.lib + +import clique + + +class ExtractRender(pyblish.api.InstancePlugin): + """Produce a flattened image file from instance. + This plug-in only takes into account the nodes connected to the composite. + """ + + label = "Extract Render" + order = pyblish.api.ExtractorOrder + hosts = ["harmony"] + families = ["render"] + + def process(self, instance): + # Collect scene data. + func = """function func(write_node) + { + return [ + about.getApplicationPath(), + scene.currentProjectPath(), + scene.currentScene(), + scene.getFrameRate(), + scene.getStartFrame(), + scene.getStopFrame() + ] + } + func + """ + result = harmony.send( + {"function": func, "args": [instance[0]]} + )["result"] + application_path = result[0] + project_path = result[1] + scene_path = os.path.join(result[1], result[2] + ".xstage") + frame_rate = result[3] + frame_start = result[4] + frame_end = result[5] + + # Set output path to temp folder. + path = tempfile.mkdtemp() + func = """function func(args) + { + node.setTextAttr(args[0], "DRAWING_NAME", 1, args[1]); + } + func + """ + result = harmony.send( + { + "function": func, + "args": [instance[0], path + "/" + instance.data["name"]] + } + ) + harmony.save_scene() + + # Execute rendering. + output = pype.lib._subprocess([application_path, "-batch", scene_path]) + self.log.info(output) + + # Collect rendered files. + files = os.listdir(path) + collections, remainder = clique.assemble(files, minimum_items=1) + assert not remainder, ( + "There should not be a remainder for {0}: {1}".format( + instance[0], remainder + ) + ) + assert len(collections) == 1, ( + "There should only be one image sequence in {}. Found: {}".format( + path, len(collections) + ) + ) + + extension = os.path.splitext(list(collections[0])[0])[-1][1:] + representation = { + "name": extension, + "ext": extension, + "files": list(collections[0]), + "stagingDir": path, + "frameStart": frame_start, + "frameEnd": frame_end, + "fps": frame_rate, + "preview": True, + "tags": ["review"] + } + instance.data["representations"] = [representation] + self.log.info(frame_rate) + + # Required for extract_review plugin (L222 onwards). + instance.data["frameStart"] = frame_start + instance.data["frameEnd"] = frame_end + instance.data["fps"] = frame_rate + + self.log.info("Extracted {instance} to {path}".format(**locals())) diff --git a/pype/plugins/harmony/publish/extract_template.py b/pype/plugins/harmony/publish/extract_template.py new file mode 100644 index 0000000000..78184217dc --- /dev/null +++ b/pype/plugins/harmony/publish/extract_template.py @@ -0,0 +1,90 @@ +import os +import shutil + +import pype.api +from avalon import harmony + + +class ExtractTemplate(pype.api.Extractor): + """Extract the connected nodes to the composite instance.""" + label = "Extract Template" + hosts = ["harmony"] + families = ["harmony.template"] + + def process(self, instance): + staging_dir = self.staging_dir(instance) + + self.log.info("Outputting template to %s" % staging_dir) + + self.dependencies = [] + self.get_dependencies(instance[0]) + + func = """function func(args) + { + var nodes = args[0]; + selection.clearSelection(); + for (var i = 0 ; i < nodes.length; i++) + { + selection.addNodeToSelection(nodes[i]); + } + } + func + """ + harmony.send({"function": func, "args": [self.dependencies]}) + func = """function func(args) + { + copyPaste.createTemplateFromSelection(args[0], args[1]); + } + func + """ + harmony.send( + { + "function": func, + "args": ["{}.tpl".format(instance.name), staging_dir] + } + ) + + os.chdir(staging_dir) + shutil.make_archive( + "{}".format(instance.name), + "zip", + os.path.join(staging_dir, "{}.tpl".format(instance.name)) + ) + + representation = { + "name": "tpl", + "ext": "zip", + "files": "{}.zip".format(instance.name), + "stagingDir": staging_dir, + } + instance.data["representations"] = [representation] + + def get_dependencies(self, node): + func = """function func(args) + { + var target_node = args[0]; + var numInput = node.numberOfInputPorts(target_node); + var dependencies = []; + for (var i = 0 ; i < numInput; i++) + { + dependencies.push(node.srcNode(target_node, i)); + } + return dependencies; + } + func + """ + + current_dependencies = harmony.send( + {"function": func, "args": [node]} + )["result"] + + for dependency in current_dependencies: + if not dependency: + continue + + if dependency in self.dependencies: + continue + + self.dependencies.append(dependency) + + self.get_dependencies(dependency) diff --git a/pype/version.py b/pype/version.py index 892994aa6c..43ce13db01 100644 --- a/pype/version.py +++ b/pype/version.py @@ -1 +1 @@ -__version__ = "2.8.0" +__version__ = "2.9.0"