mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
integrate thumbnail looks for thumbnail to multiple places
This commit is contained in:
parent
7c16c15ecb
commit
63b47efc51
1 changed files with 54 additions and 4 deletions
|
|
@ -102,8 +102,56 @@ class IntegrateThumbnails(pyblish.api.ContextPlugin):
|
|||
thumbnail_root
|
||||
)
|
||||
|
||||
def _get_thumbnail_from_instance(self, instance):
|
||||
# 1. Look for thumbnail path on instance in 'thumbnailPath'
|
||||
thumbnail_path = instance.data.get("thumbnailPath")
|
||||
if thumbnail_path and os.path.exists(thumbnail_path):
|
||||
return thumbnail_path
|
||||
|
||||
# 2. Look for thumbnail in published representations
|
||||
published_repres = instance.data.get("published_representations")
|
||||
path = self._get_thumbnail_path_from_published(published_repres)
|
||||
if path and os.path.exists(path):
|
||||
return path
|
||||
|
||||
if path:
|
||||
self.log.warning(
|
||||
"Could not find published thumbnail path {}".format(path)
|
||||
)
|
||||
|
||||
# 3. Look for thumbnail in "not published" representations
|
||||
repres = instance.data.get("representations")
|
||||
if not repres:
|
||||
return None
|
||||
|
||||
thumbnail_repre = next(
|
||||
(
|
||||
repre
|
||||
for repre in repres
|
||||
if repre["name"] == "thumbnail"
|
||||
),
|
||||
None
|
||||
)
|
||||
if not thumbnail_repre:
|
||||
return None
|
||||
|
||||
staging_dir = thumbnail_repre.get("stagingDir")
|
||||
if not staging_dir:
|
||||
staging_dir = instance.data.get("stagingDir")
|
||||
|
||||
filename = thumbnail_repre.get("files")
|
||||
if not staging_dir or not filename:
|
||||
return None
|
||||
|
||||
if isinstance(filename, (list, tuple, set)):
|
||||
filename = filename[0]
|
||||
thumbnail_path = os.path.join(staging_dir, filename)
|
||||
if os.path.exists(thumbnail_path):
|
||||
return thumbnail_path
|
||||
return None
|
||||
|
||||
def _prepare_instances(self, context):
|
||||
context_thumbnail_path = context.get("thumbnailPath")
|
||||
context_thumbnail_path = context.data.get("thumbnailPath")
|
||||
valid_context_thumbnail = False
|
||||
if context_thumbnail_path and os.path.exists(context_thumbnail_path):
|
||||
valid_context_thumbnail = True
|
||||
|
|
@ -122,8 +170,7 @@ class IntegrateThumbnails(pyblish.api.ContextPlugin):
|
|||
continue
|
||||
|
||||
# Find thumbnail path on instance
|
||||
thumbnail_path = self._get_instance_thumbnail_path(
|
||||
published_repres)
|
||||
thumbnail_path = self._get_thumbnail_from_instance(instance)
|
||||
if thumbnail_path:
|
||||
self.log.debug((
|
||||
"Found thumbnail path for instance \"{}\"."
|
||||
|
|
@ -157,7 +204,10 @@ class IntegrateThumbnails(pyblish.api.ContextPlugin):
|
|||
for repre_info in published_representations.values():
|
||||
return repre_info["representation"]["parent"]
|
||||
|
||||
def _get_instance_thumbnail_path(self, published_representations):
|
||||
def _get_thumbnail_path_from_published(self, published_representations):
|
||||
if not published_representations:
|
||||
return None
|
||||
|
||||
thumb_repre_doc = None
|
||||
for repre_info in published_representations.values():
|
||||
repre_doc = repre_info["representation"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue