From 2e431b32e1f894a398a3865b4bb2ea4e8ecd06b4 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 9 Apr 2020 14:27:02 +0200 Subject: [PATCH] collect anatomy was split into 2 plugins to be able to collect anatomy obj before collect rendered files --- ...omy.py => collect_anatomy_context_data.py} | 45 +++++++++++-------- .../global/publish/collect_anatomy_object.py | 34 ++++++++++++++ 2 files changed, 61 insertions(+), 18 deletions(-) rename pype/plugins/global/publish/{collect_anatomy.py => collect_anatomy_context_data.py} (63%) create mode 100644 pype/plugins/global/publish/collect_anatomy_object.py diff --git a/pype/plugins/global/publish/collect_anatomy.py b/pype/plugins/global/publish/collect_anatomy_context_data.py similarity index 63% rename from pype/plugins/global/publish/collect_anatomy.py rename to pype/plugins/global/publish/collect_anatomy_context_data.py index 7fd2056213..e1e6c12ee9 100644 --- a/pype/plugins/global/publish/collect_anatomy.py +++ b/pype/plugins/global/publish/collect_anatomy_context_data.py @@ -1,13 +1,14 @@ -"""Collect Anatomy and global anatomy data. +"""Collect global context Anatomy data. Requires: + context -> anatomy + context -> projectEntity + context -> assetEntity + context -> username + context -> datetimeData session -> AVALON_TASK - projectEntity, assetEntity -> collect_avalon_entities *(pyblish.api.CollectorOrder) - username -> collect_pype_user *(pyblish.api.CollectorOrder + 0.001) - datetimeData -> collect_datetime_data *(pyblish.api.CollectorOrder) Provides: - context -> anatomy (pypeapp.Anatomy) context -> anatomyData """ @@ -15,15 +16,31 @@ import os import json from avalon import api, lib -from pypeapp import Anatomy import pyblish.api -class CollectAnatomy(pyblish.api.ContextPlugin): - """Collect Anatomy into Context""" +class CollectAnatomyContextData(pyblish.api.ContextPlugin): + """Collect Anatomy Context data. + + Example: + context.data["anatomyData"] = { + "project": { + "name": "MyProject", + "code": "myproj" + }, + "asset": "AssetName", + "hierarchy": "path/to/asset", + "task": "Working", + "username": "MeDespicable", + + *** OPTIONAL *** + "app": "maya" # Current application base name + + mutliple keys from `datetimeData` # see it's collector + } + """ order = pyblish.api.CollectorOrder + 0.002 - label = "Collect Anatomy" + label = "Collect Anatomy Context Data" def process(self, context): task_name = api.Session["AVALON_TASK"] @@ -31,13 +48,6 @@ class CollectAnatomy(pyblish.api.ContextPlugin): project_entity = context.data["projectEntity"] asset_entity = context.data["assetEntity"] - project_name = project_entity["name"] - - context.data["anatomy"] = Anatomy(project_name) - self.log.info( - "Anatomy object collected for project \"{}\".".format(project_name) - ) - hierarchy_items = asset_entity["data"]["parents"] hierarchy = "" if hierarchy_items: @@ -45,13 +55,12 @@ class CollectAnatomy(pyblish.api.ContextPlugin): context_data = { "project": { - "name": project_name, + "name": project_entity["name"], "code": project_entity["data"].get("code") }, "asset": asset_entity["name"], "hierarchy": hierarchy.replace("\\", "/"), "task": task_name, - "username": context.data["user"] } diff --git a/pype/plugins/global/publish/collect_anatomy_object.py b/pype/plugins/global/publish/collect_anatomy_object.py new file mode 100644 index 0000000000..d9e6964050 --- /dev/null +++ b/pype/plugins/global/publish/collect_anatomy_object.py @@ -0,0 +1,34 @@ +"""Collect Anatomy object. + +Requires: + os.environ -> AVALON_PROJECT + +Provides: + context -> anatomy (pypeapp.Anatomy) +""" + +from avalon import io +from pypeapp import Anatomy +import pyblish.api + + +class CollectAnatomyObject(pyblish.api.ContextPlugin): + """Collect Anatomy object into Context""" + + order = pyblish.api.CollectorOrder - 0.11 + label = "Collect Anatomy Object" + + def process(self, context): + io.install() + project_name = io.Session.get("AVALON_PROJECT") + if project_name is None: + raise AssertionError( + "Environment `AVALON_PROJECT` is not set." + "Could not initialize project's Anatomy." + ) + + context.data["anatomy"] = Anatomy(project_name) + + self.log.info( + "Anatomy object collected for project \"{}\".".format(project_name) + )