collector collect context from workfile metadata and update it (except project name)

This commit is contained in:
iLLiCiTiT 2020-12-01 15:52:40 +01:00
parent 762789d145
commit 8fb95d5c52

View file

@ -1,6 +1,8 @@
import os
import json
import pyblish.api
import avalon.api
from avalon.tvpaint import pipeline, lib
@ -10,26 +12,58 @@ class CollectWorkfileData(pyblish.api.ContextPlugin):
hosts = ["tvpaint"]
def process(self, context):
# Collect and store current context to have reference
current_context = {
"project": avalon.api.Session["AVALON_PROJECT"],
"asset": avalon.api.Session["AVALON_ASSET"],
"task": avalon.api.Session["AVALON_TASK"]
}
context.data["previous_context"] = current_context
self.log.debug("Current context is: {}".format(current_context))
# Collect context from workfile metadata
self.log.info("Collecting workfile context")
workfile_context = pipeline.get_current_workfile_context()
if workfile_context:
# Change current context with context from workfile
key_map = (("AVALON_ASSET", "asset"), ("AVALON_TASK", "task"))
for env_key, key in key_map:
avalon.api.Session[env_key] = workfile_context[key]
os.environ[env_key] = workfile_context[key]
else:
# Handle older workfiles or workfiles without metadata
self.log.warning(
"Workfile does not contain information about context."
" Using current Session context."
)
workfile_context = current_context.copy()
context.data["workfile_context"] = workfile_context
self.log.info("Context changed to: {}".format(workfile_context))
# Collect instances
self.log.info("Collecting instance data from workfile")
instance_data = pipeline.list_instances()
context.data["workfileInstances"] = instance_data
self.log.debug(
"Instance data:\"{}".format(json.dumps(instance_data, indent=4))
)
context.data["workfileInstances"] = instance_data
# Collect information about layers
self.log.info("Collecting layers data from workfile")
layers_data = lib.layers_data()
context.data["layersData"] = layers_data
self.log.debug(
"Layers data:\"{}".format(json.dumps(layers_data, indent=4))
)
context.data["layersData"] = layers_data
# Collect information about groups
self.log.info("Collecting groups data from workfile")
group_data = lib.groups_data()
context.data["groupsData"] = group_data
self.log.debug(
"Group data:\"{}".format(json.dumps(group_data, indent=4))
)
context.data["groupsData"] = group_data
self.log.info("Collecting scene data from workfile")
workfile_info_parts = lib.execute_george("tv_projectinfo").split(" ")