mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
integrate description can use optional keys
This commit is contained in:
parent
23601cb244
commit
c4fce5fea9
1 changed files with 49 additions and 20 deletions
|
|
@ -6,9 +6,11 @@ Requires:
|
|||
"""
|
||||
|
||||
import sys
|
||||
import json
|
||||
|
||||
import six
|
||||
import pyblish.api
|
||||
from openpype.lib import StringTemplate
|
||||
|
||||
|
||||
class IntegrateFtrackDescription(pyblish.api.InstancePlugin):
|
||||
|
|
@ -25,6 +27,10 @@ class IntegrateFtrackDescription(pyblish.api.InstancePlugin):
|
|||
description_template = "{comment}"
|
||||
|
||||
def process(self, instance):
|
||||
if not self.description_template:
|
||||
self.log.info("Skipping. Description template is not set.")
|
||||
return
|
||||
|
||||
# Check if there are any integrated AssetVersion entities
|
||||
asset_versions_key = "ftrackIntegratedAssetVersionsData"
|
||||
asset_versions_data_by_id = instance.data.get(asset_versions_key)
|
||||
|
|
@ -38,39 +44,62 @@ class IntegrateFtrackDescription(pyblish.api.InstancePlugin):
|
|||
else:
|
||||
self.log.debug("Comment is set to `{}`".format(comment))
|
||||
|
||||
session = instance.context.data["ftrackSession"]
|
||||
|
||||
intent = instance.context.data.get("intent")
|
||||
intent_label = None
|
||||
if intent and isinstance(intent, dict):
|
||||
intent_val = intent.get("value")
|
||||
intent_label = intent.get("label")
|
||||
else:
|
||||
intent_val = intent
|
||||
if intent and "{intent}" in self.description_template:
|
||||
value = intent.get("value")
|
||||
if value:
|
||||
intent = intent.get("label") or value
|
||||
|
||||
if not intent_label:
|
||||
intent_label = intent_val or ""
|
||||
if not intent and not comment:
|
||||
self.log.info("Skipping. Intent and comment are empty.")
|
||||
return
|
||||
|
||||
# if intent label is set then format comment
|
||||
# - it is possible that intent_label is equal to "" (empty string)
|
||||
if intent_label:
|
||||
self.log.debug(
|
||||
"Intent label is set to `{}`.".format(intent_label)
|
||||
)
|
||||
|
||||
if intent:
|
||||
self.log.debug("Intent is set to `{}`.".format(intent))
|
||||
else:
|
||||
self.log.debug("Intent is not set.")
|
||||
|
||||
# If we would like to use more "optional" possibilities we would have
|
||||
# come up with some expressions in templates or speicifc templates
|
||||
# for all 3 possible combinations when comment and intent are
|
||||
# set or not (when both are not set then description does not
|
||||
# make sense).
|
||||
fill_data = {}
|
||||
if comment:
|
||||
fill_data["comment"] = comment
|
||||
if intent:
|
||||
fill_data["intent"] = intent
|
||||
|
||||
description = StringTemplate.format_template(
|
||||
self.description_template, fill_data
|
||||
)
|
||||
if not description.solved:
|
||||
self.log.warning((
|
||||
"Couldn't solve template \"{}\" with data {}"
|
||||
).format(
|
||||
self.description_template, json.dumps(fill_data, indent=4)
|
||||
))
|
||||
return
|
||||
|
||||
if not description:
|
||||
self.log.debug((
|
||||
"Skipping. Result of template is empty string."
|
||||
" Template \"{}\" Fill data: {}"
|
||||
).format(
|
||||
self.description_template, json.dumps(fill_data, indent=4)
|
||||
))
|
||||
return
|
||||
|
||||
session = instance.context.data["ftrackSession"]
|
||||
for asset_version_data in asset_versions_data_by_id.values():
|
||||
asset_version = asset_version_data["asset_version"]
|
||||
|
||||
# Backwards compatibility for older settings using
|
||||
# attribute 'note_with_intent_template'
|
||||
comment = self.description_template.format(**{
|
||||
"intent": intent_label,
|
||||
"comment": comment
|
||||
})
|
||||
asset_version["comment"] = comment
|
||||
|
||||
asset_version["comment"] = description
|
||||
|
||||
try:
|
||||
session.commit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue