Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
integrate description can use optional keys
Browse files Browse the repository at this point in the history
  • Loading branch information
iLLiCiTiT committed Aug 3, 2022
1 parent 9d8a05d commit 9bf98e0
Showing 1 changed file with 49 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"""

import sys
import json

import six
import pyblish.api
from openpype.lib import StringTemplate


class IntegrateFtrackDescription(pyblish.api.InstancePlugin):
Expand All @@ -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)
Expand All @@ -38,39 +44,62 @@ def process(self, instance):
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()
Expand Down

0 comments on commit 9bf98e0

Please sign in to comment.