From 8b0e6410167d34a21d71bec3665ac67cb240b032 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 7 Oct 2022 12:30:21 +0200 Subject: [PATCH] OP-3939 - added plugin to update tags for thumbnail representation Integration of thumbnail could be explicitly controlled on one place, overwriting implicit state from host implementations. --- .../preintegrate_thumbnail_representation.py | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 openpype/plugins/publish/preintegrate_thumbnail_representation.py diff --git a/openpype/plugins/publish/preintegrate_thumbnail_representation.py b/openpype/plugins/publish/preintegrate_thumbnail_representation.py new file mode 100644 index 0000000000..0c3ba4057c --- /dev/null +++ b/openpype/plugins/publish/preintegrate_thumbnail_representation.py @@ -0,0 +1,68 @@ +""" Marks thumbnail representation for integrate to DB or not. + + Some hosts produce thumbnail representation, most of them do not create + them explicitly, but they created during extract phase. + + In some cases it might be useful to override implicit setting for host/task + + This plugin needs to run after extract phase, but before integrate.py as + thumbnail is part of review family and integrated there. + + It should be better to control integration of thumbnail in one place than + configure it in multiple places on host implementations. +""" +import pyblish.api + +from openpype.lib.profiles_filtering import filter_profiles + + +class PreIntegrateThumbnails(pyblish.api.InstancePlugin): + """Marks thumbnail representation for integrate to DB or not.""" + + label = "Should Integrate Thumbnails" + order = pyblish.api.IntegratorOrder + families = ["review"] + + integrate_profiles = {} + + def process(self, instance): + thumbnail_repre = None + for repre in instance.data["representations"]: + if repre["name"] == "thumbnail": + thumbnail_repre = repre + break + + if not thumbnail_repre: + return + + family = instance.data["family"] + subset_name = instance.data["subset"] + host_name = instance.context.data["hostName"] + + anatomy_data = instance.data["anatomyData"] + task = anatomy_data.get("task", {}) + + found_profile = filter_profiles( + self.integrate_profiles, + { + "hosts": host_name, + "tasks": task.get("name"), + "task_types": task.get("type"), + "families": family, + "subsets": subset_name, + }, + logger=self.log + ) + + if not found_profile: + return + + if not found_profile["integrate_thumbnail"]: + if "delete" not in thumbnail_repre["tags"]: + thumbnail_repre["tags"].append("delete") + else: + if "delete" in thumbnail_repre["tags"]: + thumbnail_repre["tags"].pop("delete") + + self.log.debug( + "Thumbnail repre tags {}".format(thumbnail_repre["tags"]))