From 48faec38032756ce6c9e6936ff48df01a624c9a7 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 30 Mar 2021 10:23:38 +0200 Subject: [PATCH] bulk mov instance collecting separated from batch instances --- .../publish/collect_batch_instances.py | 11 +-- .../publish/collect_bulk_mov_instances.py | 98 +++++++++++++++++++ 2 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 pype/hosts/standalonepublisher/plugins/publish/collect_bulk_mov_instances.py diff --git a/pype/hosts/standalonepublisher/plugins/publish/collect_batch_instances.py b/pype/hosts/standalonepublisher/plugins/publish/collect_batch_instances.py index 545efcb303..4ca1f72cc4 100644 --- a/pype/hosts/standalonepublisher/plugins/publish/collect_batch_instances.py +++ b/pype/hosts/standalonepublisher/plugins/publish/collect_batch_instances.py @@ -9,12 +9,11 @@ class CollectBatchInstances(pyblish.api.InstancePlugin): label = "Collect Batch Instances" order = pyblish.api.CollectorOrder + 0.489 hosts = ["standalonepublisher"] - families = ["background_batch", "render_mov_batch"] + families = ["background_batch"] # presets default_subset_task = { - "background_batch": "background", - "render_mov_batch": "compositing" + "background_batch": "background" } subsets = { "background_batch": { @@ -30,12 +29,6 @@ class CollectBatchInstances(pyblish.api.InstancePlugin): "task": "background", "family": "workfile" } - }, - "render_mov_batch": { - "renderCompositingDefault": { - "task": "compositing", - "family": "render" - } } } unchecked_by_default = [] diff --git a/pype/hosts/standalonepublisher/plugins/publish/collect_bulk_mov_instances.py b/pype/hosts/standalonepublisher/plugins/publish/collect_bulk_mov_instances.py new file mode 100644 index 0000000000..cbb9d95e01 --- /dev/null +++ b/pype/hosts/standalonepublisher/plugins/publish/collect_bulk_mov_instances.py @@ -0,0 +1,98 @@ +import copy +import json +import pyblish.api + +from avalon import io +from pype.lib import get_subset_name + + +class CollectBulkMovInstances(pyblish.api.InstancePlugin): + """Collect all available instances for batch publish.""" + + label = "Collect Bulk Mov Instances" + order = pyblish.api.CollectorOrder + 0.489 + hosts = ["standalonepublisher"] + families = ["render_mov_batch"] + + new_instance_family = "render" + instance_task_names = [ + "compositing", + "comp" + ] + default_task_name = "compositing" + subset_name_variant = "Default" + + def process(self, instance): + context = instance.context + asset_name = instance.data["asset"] + + asset_doc = io.find_one( + { + "type": "asset", + "name": asset_name + }, + { + "_id": 1, + "data.tasks": 1 + } + ) + if not asset_doc: + raise AssertionError(( + "Couldn't find Asset document with name \"{}\"" + ).format(asset_name)) + + available_task_names = {} + asset_tasks = asset_doc.get("data", {}).get("tasks") or {} + for task_name in asset_tasks.keys(): + available_task_names[task_name.lower()] = task_name + + task_name = self.default_task_name + for _task_name in self.instance_task_names: + _task_name_low = _task_name.lower() + if _task_name_low in available_task_names: + task_name = available_task_names[_task_name_low] + break + + subset_name = get_subset_name( + self.new_instance_family, + self.subset_name_variant, + task_name, + asset_doc["_id"], + io.Session["AVALON_PROJECT"] + ) + instance_name = f"{asset_name}_{subset_name}" + + # create new instance + new_instance = context.create_instance(instance_name) + new_instance_data = { + "name": instance_name, + "label": instance_name, + "family": self.new_instance_family, + "subset": subset_name, + "task": task_name + } + new_instance.data.update(new_instance_data) + # add original instance data except name key + for key, value in instance.data.items(): + if key in new_instance_data: + continue + # Make sure value is copy since value may be object which + # can be shared across all new created objects + new_instance.data[key] = copy.deepcopy(value) + + # Add `render_mov_batch` for specific validators + if "families" not in new_instance.data: + new_instance.data["families"] = [] + new_instance.data["families"].append("render_mov_batch") + + # delete original instance + context.remove(instance) + + self.log.info(f"Created new instance: {instance_name}") + + def convertor(value): + return str(value) + + self.log.debug("Instance data: {}".format( + json.dumps(new_instance.data, indent=4, default=convertor) + ))