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.
This commit is contained in:
Petr Kalis 2022-10-07 12:30:21 +02:00
parent 08d79e1a78
commit 8b0e641016

View file

@ -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"]))