mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge pull request #766 from pypeclub/bugfix/764-mixed-up-file-name-during-publishing
TVPaint store context to workfile metadata (764)
This commit is contained in:
commit
e1de7f1aac
2 changed files with 80 additions and 3 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import os
|
||||
import json
|
||||
|
||||
import pyblish.api
|
||||
import avalon.api
|
||||
from avalon.tvpaint import pipeline, lib
|
||||
|
||||
|
||||
|
|
@ -10,26 +12,64 @@ class CollectWorkfileData(pyblish.api.ContextPlugin):
|
|||
hosts = ["tvpaint"]
|
||||
|
||||
def process(self, context):
|
||||
current_project_id = lib.execute_george("tv_projectcurrentid")
|
||||
lib.execute_george("tv_projectselect {}".format(current_project_id))
|
||||
|
||||
# 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(" ")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
import os
|
||||
import pyblish.api
|
||||
|
||||
|
||||
class ValidateWorkfileProjectName(pyblish.api.ContextPlugin):
|
||||
"""Validate project name stored in workfile metadata.
|
||||
|
||||
It is not possible to publish from different project than is set in
|
||||
environment variable "AVALON_PROJECT".
|
||||
"""
|
||||
|
||||
label = "Validate Workfile Project Name"
|
||||
order = pyblish.api.ValidatorOrder
|
||||
|
||||
def process(self, context):
|
||||
workfile_context = context.data["workfile_context"]
|
||||
workfile_project_name = workfile_context["project"]
|
||||
env_project_name = os.environ["AVALON_PROJECT"]
|
||||
if workfile_project_name == env_project_name:
|
||||
self.log.info((
|
||||
"Both workfile project and environment project are same. {}"
|
||||
).format(env_project_name))
|
||||
return
|
||||
|
||||
# Raise an error
|
||||
raise AssertionError((
|
||||
# Short message
|
||||
"Workfile from different Project ({})."
|
||||
# Description what's wrong
|
||||
" It is not possible to publish when TVPaint was launched in"
|
||||
"context of different project. Current context project is \"{}\"."
|
||||
" Launch TVPaint in context of project \"{}\" and then publish."
|
||||
).format(
|
||||
workfile_project_name,
|
||||
env_project_name,
|
||||
workfile_project_name,
|
||||
))
|
||||
Loading…
Add table
Add a link
Reference in a new issue