Bases: FtrackPublishInstancePlugin
Add description to AssetVersions in ftrack.
Source code in client/ayon_ftrack/plugins/publish/integrate_ftrack_description.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 | class IntegrateFtrackDescription(plugin.FtrackPublishInstancePlugin):
"""Add description to AssetVersions in ftrack."""
# Must be after IntegrateAsset plugin in ayon_core
order = pyblish.api.IntegratorOrder + 0.4999
label = "Integrate ftrack description"
families = ["ftrack"]
optional = True
# Can be set in settings:
# - Allows `intent` and `comment` keys
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)
if not asset_versions_data_by_id:
self.log.info("There are any integrated AssetVersions")
return
comment = instance.data["comment"]
if not comment:
self.log.debug("Comment is not set.")
else:
self.log.debug("Comment is set to `{}`".format(comment))
intent = instance.context.data.get("intent")
if intent and "{intent}" in self.description_template:
value = intent.get("value")
if value:
intent = intent.get("label") or value
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:
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'
asset_version["comment"] = description
try:
session.commit()
self.log.debug("Comment added to AssetVersion \"{}\"".format(
str(asset_version)
))
except Exception as exc:
session.rollback()
session._configure_locations()
raise exc
|