integrate ftrack note add notes to each integrated asset version

This commit is contained in:
iLLiCiTiT 2020-01-31 12:13:20 +01:00
parent eb50cd369d
commit e4ba53ac15

View file

@ -6,29 +6,45 @@ import six
class IntegrateFtrackNote(pyblish.api.InstancePlugin): class IntegrateFtrackNote(pyblish.api.InstancePlugin):
"""Create comments in Ftrack.""" """Create comments in Ftrack."""
order = pyblish.api.IntegratorOrder # Must be after integrate asset new
label = "Integrate Comments to Ftrack." order = pyblish.api.IntegratorOrder + 0.4999
label = "Integrate Ftrack note"
families = ["ftrack"] families = ["ftrack"]
optional = True optional = True
def process(self, instance): def process(self, instance):
comment = (instance.context.data.get("comment") or "").strip() comment = (instance.context.data.get("comment") or "").strip()
if not comment: if not comment:
self.log.info("Comment is not set.")
return return
self.log.debug("Comment is set to {}".format(comment))
asset_versions_key = "ftrackIntegratedAssetVersions" asset_versions_key = "ftrackIntegratedAssetVersions"
asset_versions = instance.data.get(asset_versions_key) asset_versions = instance.data.get(asset_versions_key)
if not asset_versions: if not asset_versions:
self.log.info("There are any integrated AssetVersions")
return return
session = context.data["ftrackSession"] session = instance.context.data["ftrackSession"]
user = session.query(
"User where username is \"{}\"".format(session.api_user)
).first()
if not user:
self.log.warning(
"Was not able to query current User {}".format(
session.api_user
)
)
note = session.create("Note", {"content": comment})
for asset_version in asset_versions: for asset_version in asset_versions:
asset_version["notes"].extend(note) asset_version.create_note(comment, author=user)
try: try:
session.commit() session.commit()
self.log.debug("Note added to AssetVersion \"{}\"".format(
str(asset_version)
))
except Exception: except Exception:
tp, value, tb = sys.exc_info() tp, value, tb = sys.exc_info()
session.rollback() session.rollback()