From a0dc2d7bffdab00925dde7dbbdaedb244731cb8c Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Mon, 18 Mar 2024 15:11:58 +0100 Subject: [PATCH] refactored how data structure in collect hierarchy is created --- .../plugins/publish/collect_hierarchy.py | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/client/ayon_core/plugins/publish/collect_hierarchy.py b/client/ayon_core/plugins/publish/collect_hierarchy.py index a16ca27e5c..0751bf305b 100644 --- a/client/ayon_core/plugins/publish/collect_hierarchy.py +++ b/client/ayon_core/plugins/publish/collect_hierarchy.py @@ -17,17 +17,19 @@ class CollectHierarchy(pyblish.api.ContextPlugin): hosts = ["resolve", "hiero", "flame"] def process(self, context): - temp_context = {} project_name = context.data["projectName"] - final_context = {} - final_context[project_name] = {} - final_context[project_name]["entity_type"] = "project" + temp_context = {} + final_context = { + project_name: { + "entity_type": "project", + "children": temp_context + }, + } for instance in context: self.log.debug("Processing instance: `{}` ...".format(instance)) # shot data dict - shot_data = {} product_type = instance.data["productType"] families = instance.data["families"] @@ -41,23 +43,25 @@ class CollectHierarchy(pyblish.api.ContextPlugin): if not instance.data.get("heroTrack"): continue - shot_data["entity_type"] = "folder" - # suppose that all instances are Shots - shot_data["folder_type"] = "Shot" - shot_data['tasks'] = instance.data.get("tasks") or {} - shot_data["comments"] = instance.data.get("comments", []) - - shot_data['attributes'] = { - "handleStart": instance.data["handleStart"], - "handleEnd": instance.data["handleEnd"], - "frameStart": instance.data["frameStart"], - "frameEnd": instance.data["frameEnd"], - "clipIn": instance.data["clipIn"], - "clipOut": instance.data["clipOut"], - "fps": instance.data["fps"], - "resolutionWidth": instance.data["resolutionWidth"], - "resolutionHeight": instance.data["resolutionHeight"], - "pixelAspect": instance.data["pixelAspect"] + shot_data = { + "entity_type": "folder", + # WARNING Default folder type is hardcoded + # suppose that all instances are Shots + "folder_type": "Shot", + "tasks": instance.data.get("tasks") or {}, + "comments": instance.data.get("comments", []), + "attributes": { + "handleStart": instance.data["handleStart"], + "handleEnd": instance.data["handleEnd"], + "frameStart": instance.data["frameStart"], + "frameEnd": instance.data["frameEnd"], + "clipIn": instance.data["clipIn"], + "clipOut": instance.data["clipOut"], + "fps": instance.data["fps"], + "resolutionWidth": instance.data["resolutionWidth"], + "resolutionHeight": instance.data["resolutionHeight"], + "pixelAspect": instance.data["pixelAspect"], + }, } # Split by '/' for AYON where asset is a path name = instance.data["folderPath"].split("/")[-1] @@ -71,6 +75,16 @@ class CollectHierarchy(pyblish.api.ContextPlugin): next_dict[parent_name]["folder_type"] = parent[ "entity_type"].capitalize() next_dict[parent_name]["children"] = actual + + for parent in reversed(instance.data["parents"]): + parent_name = parent["entity_name"] + next_dict = { + parent_name: { + "entity_type": "folder", + "folder_type": parent["entity_type"].capitalize(), + "children": actual + } + } actual = next_dict temp_context = self._update_dict(temp_context, actual) @@ -79,8 +93,6 @@ class CollectHierarchy(pyblish.api.ContextPlugin): if not temp_context: return - final_context[project_name]['children'] = temp_context - # adding hierarchy context to context context.data["hierarchyContext"] = final_context self.log.debug("context.data[hierarchyContext] is: {}".format(