From 43a66826bc45573c3f904fc553ab0608d2ecc5e1 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 20 Nov 2019 18:23:29 +0100 Subject: [PATCH 1/9] integrate remove components is deactivated by default to not remove thumbnails and movs --- pype/plugins/ftrack/publish/integrate_remove_components.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pype/plugins/ftrack/publish/integrate_remove_components.py b/pype/plugins/ftrack/publish/integrate_remove_components.py index bad50f7200..26cac0f1ae 100644 --- a/pype/plugins/ftrack/publish/integrate_remove_components.py +++ b/pype/plugins/ftrack/publish/integrate_remove_components.py @@ -11,13 +11,13 @@ class IntegrateCleanComponentData(pyblish.api.InstancePlugin): label = 'Clean component data' families = ["ftrack"] optional = True - active = True + active = False def process(self, instance): for comp in instance.data['representations']: self.log.debug('component {}'.format(comp)) - + if "%" in comp['published_path'] or "#" in comp['published_path']: continue From 7f63d864fd56afa13285653b56d9d7b3f8fb4e11 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 20 Nov 2019 18:31:40 +0100 Subject: [PATCH 2/9] created extract scaled thumbnails plugin which creates 3 types of thumbnails small, middle and large --- .../publish/extract_scaled_thumbnails.py | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 pype/plugins/global/publish/extract_scaled_thumbnails.py diff --git a/pype/plugins/global/publish/extract_scaled_thumbnails.py b/pype/plugins/global/publish/extract_scaled_thumbnails.py new file mode 100644 index 0000000000..6d6aa6a73c --- /dev/null +++ b/pype/plugins/global/publish/extract_scaled_thumbnails.py @@ -0,0 +1,137 @@ +import os +import pyblish.api +import pype.api + + +class ExtractScaledThumbnails(pyblish.api.InstancePlugin): + """Create scaled thumbnails for GUIs like loader etc. + + Scaled thumbnails creation is based on data in `output_data` attribute. + The dictionary `output_data` store additional filename ending and + filters for ffmpeg. + + Example: + "small": { + "file_end": "S", + "filters": ["scale=160:-1"] + } + + "small" - key is used to store result under represetation + "file_end" - is distinguishing part for files. + - "S" means that source thumbnail "myasset_thumbnail.jpg" + will be converted to "myasset_thumbnail_S.jpg" + "filters" - should contain filters for ffmpeg, key is `scale` filter + which is used to render thumbnails with different + resolution. + - "160:-1" will render thumbnail with 160px width and keep + aspect ratio of source image + """ + + order = pyblish.api.ExtractorOrder + 0.499 + label = "Extract scaled thumbnails" + + optional = True + active = True + hosts = ["nuke", "maya", "shell"] + # Default setting for output data + output_data = { + "small": { + "file_end": "S", + "filters": ["scale=160:-1"] + }, + "middle": { + "file_end": "M", + "filters": ["scale=320:-1"] + }, + "large": { + "file_end": "L", + "filters": ["scale=1024:-1"] + } + } + + def process(self, instance): + for repre in instance.data["representations"]: + name = repre.get("name", "") + if name: + name = " <{}>".format(name) + self.log.debug("Checking repre{}: {}".format(name, repre)) + # Skip if thumbnail not in tags + tags = repre.get("tags") or [] + if ( + "thumbnail" not in tags and + not repre.get("thumbnail") # backwards compatibility + ): + continue + + # skip if files are not set or empty + files = repre.get("files") + if not files: + continue + + orig_filename = None + if isinstance(files, (str, unicode)): + orig_filename = files + elif isinstance(files, list): + orig_filename = files[0] + else: + self.log.debug(( + "Original `files`{} have invalid type \"{}\" on repre {}" + ).format(name, str(type(files)), str(repre))) + continue + + staging_dir = repre["stagingDir"] + full_input_path = os.path.join(staging_dir, orig_filename) + + orig_basename, orig_ext = os.path.splitext(orig_filename) + thumbnail_data = {} + + _input_args = [] + # Overrides output file + _input_args.append("-y") + # Set input path + _input_args.append("-i \"{}\"".format(full_input_path)) + + ffmpeg_path = os.path.join( + os.environ.get("FFMPEG_PATH", ""), "ffmpeg" + ) + + for output_type, single_data in self.output_data.items(): + # DEBUG remove after testing! + self.log.debug(output_type) + file_end = single_data["file_end"] + in_filters = single_data["filters"] + + ffmpeg_filters = [] + if in_filters: + ffmpeg_filters.append("-vf") + ffmpeg_filters.extend([fil for fil in in_filters]) + + # copy _input_args + input_args = [arg for arg in _input_args] + input_args.extend(ffmpeg_filters) + + output_args = [] + filename = "{}_{}{}".format( + orig_basename, file_end, orig_ext + ) + full_output_path = os.path.join(staging_dir, filename) + output_args.append("\"{}\"".format(full_output_path)) + + mov_args = [ + ffmpeg_path, + " ".join(input_args), + " ".join(output_args) + ] + subprcs_cmd = " ".join(mov_args) + + self.log.debug("Executing: {}".format(subprcs_cmd)) + output = pype.api.subprocess(subprcs_cmd) + self.log.debug("Output: {}".format(output)) + + # Store data for integrator + thumbnail_data[output_type] = { + "path": full_output_path, + "filename_append": file_end + } + + repre["thumbnail_data"] = thumbnail_data From c2e5f792f4a62a93fa59a160370ead4500c094fa Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 20 Nov 2019 18:32:20 +0100 Subject: [PATCH 3/9] added processing of thumbnails to integrate new so they can be accesible for guis --- pype/plugins/global/publish/integrate_new.py | 62 ++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/pype/plugins/global/publish/integrate_new.py b/pype/plugins/global/publish/integrate_new.py index 64f6dd5015..a8e6999e8d 100644 --- a/pype/plugins/global/publish/integrate_new.py +++ b/pype/plugins/global/publish/integrate_new.py @@ -384,6 +384,65 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): repre['published_path'] = dst self.log.debug("__ dst: {}".format(dst)) + thumbnail_data = {} + if 'thumbnail' in repre.get('tags', []): + self.log.debug(( + "Looking for scaled thumbnails in <{}>" + ).format(repre["name"])) + # prepare template for thumbnails + # - same as anatomy but keys in basename are replaced with + # one single key `thumb_file_name` + # - template is same for all thumbnails + template_base_name = os.path.basename(template) + thumb_template = template.replace( + template_base_name, "{thumb_file_name}" + ) + self.log.debug( + "Thumbnail template: {}".format(thumb_template) + ) + # get orig thumbnail filename + repre_basename = os.path.basename(dst) + repre_file, repre_ext = os.path.splitext(repre_basename) + # get thumbnail data from reresentation (if there are any) + _thumbnail_data = repre.pop("thumbnail_data", {}) + if _thumbnail_data: + thumbnail_data["template"] = thumb_template + + for thumb_type, thumb_info in _thumbnail_data.items(): + _src = thumb_info["path"] + + # get filename appending "like `S` for small thumb" + filename_append = thumb_info["filename_append"] + thumb_file_name = "{}_{}{}".format( + repre_file, filename_append, repre_ext + ) + _template_data = template_data.copy() + _template_data["thumb_file_name"] = thumb_file_name + # fill thumbnail template with prepared data + self.log.debug( + "Thumbnail <{}> template data: {}".format( + thumb_type, _template_data + ) + ) + template_filled = thumb_template.format( + **_template_data + ) + _dst = os.path.normpath( + template_filled + ).replace("..", ".") + self.log.debug( + "Thumbnail <{}> src: {} || dst: {}".format( + thumb_type, _src, _dst + ) + ) + # add to transfers + instance.data["transfers"].append([_src, _dst]) + # store full path and additional context data + thumbnail_data[thumb_type] = { + "path": _dst, + "context": {"thumb_file_name": thumb_file_name} + } + representation = { "schema": "pype:representation-2.0", "type": "representation", @@ -409,6 +468,9 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): } } + if thumbnail_data: + representation["data"]["thumbnail_data"] = thumbnail_data + if sequence_repre and repre.get("frameStart"): representation['context']['frame'] = repre.get("frameStart") From a03bbc924a4d3f25d36b17a9527ca137f5f5438c Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 20 Nov 2019 18:33:00 +0100 Subject: [PATCH 4/9] renamed extract review repre name to thumbnail --- pype/plugins/global/publish/extract_jpeg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pype/plugins/global/publish/extract_jpeg.py b/pype/plugins/global/publish/extract_jpeg.py index 10c339e0c6..18d9286b86 100644 --- a/pype/plugins/global/publish/extract_jpeg.py +++ b/pype/plugins/global/publish/extract_jpeg.py @@ -69,7 +69,7 @@ class ExtractJpegEXR(pyblish.api.InstancePlugin): instance.data["representations"] = [] representation = { - 'name': 'jpg', + 'name': 'thumbnail', 'ext': 'jpg', 'files': jpegFile, "stagingDir": stagingdir, From 6bc2042cea12869717b318b134ed652cc209ee42 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 4 Dec 2019 18:29:50 +0100 Subject: [PATCH 5/9] removed added integraion and thumbnail extractor --- .../publish/extract_scaled_thumbnails.py | 137 ------------------ pype/plugins/global/publish/integrate_new.py | 65 +-------- 2 files changed, 2 insertions(+), 200 deletions(-) delete mode 100644 pype/plugins/global/publish/extract_scaled_thumbnails.py diff --git a/pype/plugins/global/publish/extract_scaled_thumbnails.py b/pype/plugins/global/publish/extract_scaled_thumbnails.py deleted file mode 100644 index 6d6aa6a73c..0000000000 --- a/pype/plugins/global/publish/extract_scaled_thumbnails.py +++ /dev/null @@ -1,137 +0,0 @@ -import os -import pyblish.api -import pype.api - - -class ExtractScaledThumbnails(pyblish.api.InstancePlugin): - """Create scaled thumbnails for GUIs like loader etc. - - Scaled thumbnails creation is based on data in `output_data` attribute. - The dictionary `output_data` store additional filename ending and - filters for ffmpeg. - - Example: - "small": { - "file_end": "S", - "filters": ["scale=160:-1"] - } - - "small" - key is used to store result under represetation - "file_end" - is distinguishing part for files. - - "S" means that source thumbnail "myasset_thumbnail.jpg" - will be converted to "myasset_thumbnail_S.jpg" - "filters" - should contain filters for ffmpeg, key is `scale` filter - which is used to render thumbnails with different - resolution. - - "160:-1" will render thumbnail with 160px width and keep - aspect ratio of source image - """ - - order = pyblish.api.ExtractorOrder + 0.499 - label = "Extract scaled thumbnails" - - optional = True - active = True - hosts = ["nuke", "maya", "shell"] - # Default setting for output data - output_data = { - "small": { - "file_end": "S", - "filters": ["scale=160:-1"] - }, - "middle": { - "file_end": "M", - "filters": ["scale=320:-1"] - }, - "large": { - "file_end": "L", - "filters": ["scale=1024:-1"] - } - } - - def process(self, instance): - for repre in instance.data["representations"]: - name = repre.get("name", "") - if name: - name = " <{}>".format(name) - self.log.debug("Checking repre{}: {}".format(name, repre)) - # Skip if thumbnail not in tags - tags = repre.get("tags") or [] - if ( - "thumbnail" not in tags and - not repre.get("thumbnail") # backwards compatibility - ): - continue - - # skip if files are not set or empty - files = repre.get("files") - if not files: - continue - - orig_filename = None - if isinstance(files, (str, unicode)): - orig_filename = files - elif isinstance(files, list): - orig_filename = files[0] - else: - self.log.debug(( - "Original `files`{} have invalid type \"{}\" on repre {}" - ).format(name, str(type(files)), str(repre))) - continue - - staging_dir = repre["stagingDir"] - full_input_path = os.path.join(staging_dir, orig_filename) - - orig_basename, orig_ext = os.path.splitext(orig_filename) - thumbnail_data = {} - - _input_args = [] - # Overrides output file - _input_args.append("-y") - # Set input path - _input_args.append("-i \"{}\"".format(full_input_path)) - - ffmpeg_path = os.path.join( - os.environ.get("FFMPEG_PATH", ""), "ffmpeg" - ) - - for output_type, single_data in self.output_data.items(): - # DEBUG remove after testing! - self.log.debug(output_type) - file_end = single_data["file_end"] - in_filters = single_data["filters"] - - ffmpeg_filters = [] - if in_filters: - ffmpeg_filters.append("-vf") - ffmpeg_filters.extend([fil for fil in in_filters]) - - # copy _input_args - input_args = [arg for arg in _input_args] - input_args.extend(ffmpeg_filters) - - output_args = [] - filename = "{}_{}{}".format( - orig_basename, file_end, orig_ext - ) - full_output_path = os.path.join(staging_dir, filename) - output_args.append("\"{}\"".format(full_output_path)) - - mov_args = [ - ffmpeg_path, - " ".join(input_args), - " ".join(output_args) - ] - subprcs_cmd = " ".join(mov_args) - - self.log.debug("Executing: {}".format(subprcs_cmd)) - output = pype.api.subprocess(subprcs_cmd) - self.log.debug("Output: {}".format(output)) - - # Store data for integrator - thumbnail_data[output_type] = { - "path": full_output_path, - "filename_append": file_end - } - - repre["thumbnail_data"] = thumbnail_data diff --git a/pype/plugins/global/publish/integrate_new.py b/pype/plugins/global/publish/integrate_new.py index a8e6999e8d..cc71fce49e 100644 --- a/pype/plugins/global/publish/integrate_new.py +++ b/pype/plugins/global/publish/integrate_new.py @@ -384,65 +384,6 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): repre['published_path'] = dst self.log.debug("__ dst: {}".format(dst)) - thumbnail_data = {} - if 'thumbnail' in repre.get('tags', []): - self.log.debug(( - "Looking for scaled thumbnails in <{}>" - ).format(repre["name"])) - # prepare template for thumbnails - # - same as anatomy but keys in basename are replaced with - # one single key `thumb_file_name` - # - template is same for all thumbnails - template_base_name = os.path.basename(template) - thumb_template = template.replace( - template_base_name, "{thumb_file_name}" - ) - self.log.debug( - "Thumbnail template: {}".format(thumb_template) - ) - # get orig thumbnail filename - repre_basename = os.path.basename(dst) - repre_file, repre_ext = os.path.splitext(repre_basename) - # get thumbnail data from reresentation (if there are any) - _thumbnail_data = repre.pop("thumbnail_data", {}) - if _thumbnail_data: - thumbnail_data["template"] = thumb_template - - for thumb_type, thumb_info in _thumbnail_data.items(): - _src = thumb_info["path"] - - # get filename appending "like `S` for small thumb" - filename_append = thumb_info["filename_append"] - thumb_file_name = "{}_{}{}".format( - repre_file, filename_append, repre_ext - ) - _template_data = template_data.copy() - _template_data["thumb_file_name"] = thumb_file_name - # fill thumbnail template with prepared data - self.log.debug( - "Thumbnail <{}> template data: {}".format( - thumb_type, _template_data - ) - ) - template_filled = thumb_template.format( - **_template_data - ) - _dst = os.path.normpath( - template_filled - ).replace("..", ".") - self.log.debug( - "Thumbnail <{}> src: {} || dst: {}".format( - thumb_type, _src, _dst - ) - ) - # add to transfers - instance.data["transfers"].append([_src, _dst]) - # store full path and additional context data - thumbnail_data[thumb_type] = { - "path": _dst, - "context": {"thumb_file_name": thumb_file_name} - } - representation = { "schema": "pype:representation-2.0", "type": "representation", @@ -468,9 +409,6 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): } } - if thumbnail_data: - representation["data"]["thumbnail_data"] = thumbnail_data - if sequence_repre and repre.get("frameStart"): representation['context']['frame'] = repre.get("frameStart") @@ -485,7 +423,8 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): for rep in instance.data["representations"]: self.log.debug("__ represNAME: {}".format(rep['name'])) self.log.debug("__ represPATH: {}".format(rep['published_path'])) - io.insert_many(representations) + result = io.insert_many(representations) + instance.data["published_representation_ids"] = result.inserted_ids # self.log.debug("Representation: {}".format(representations)) self.log.info("Registered {} items".format(len(representations))) From 9228536f52c52492ad9c074a5b97869b2031c63b Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 4 Dec 2019 18:30:32 +0100 Subject: [PATCH 6/9] added integrate thumbnails plugin --- .../global/publish/integrate_thumbnail.py | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 pype/plugins/global/publish/integrate_thumbnail.py diff --git a/pype/plugins/global/publish/integrate_thumbnail.py b/pype/plugins/global/publish/integrate_thumbnail.py new file mode 100644 index 0000000000..9a7418eebe --- /dev/null +++ b/pype/plugins/global/publish/integrate_thumbnail.py @@ -0,0 +1,141 @@ +import os +import sys +import errno +import shutil +import copy + +import six +import pyblish.api +from bson.objectid import ObjectId + +from avalon import api, dbio + + +class IntegrateThumbnails(pyblish.api.InstancePlugin): + """Integrate Thumbnails.""" + + label = "Integrate Thumbnails" + order = pyblish.api.IntegratorOrder + 0.01 + families = ["review"] + + def process(self, instance): + repre_ids = instance.get("published_representation_ids") + if not repre_ids: + self.log.debug( + "There are not published representation ids on the instance." + ) + return + + project_name = api.Session["AVALON_PROJECT"] + + anatomy = instance.context.data["anatomy"] + if "publish" not in anatomy.templates: + self.log.error("Anatomy does not have set publish key!") + return + + if "thumbnail" not in anatomy.templates["publish"]: + self.log.warning(( + "There is not set \"thumbnail\" template for project {}" + ).format(project_name)) + return + + thumbnail_template = anatomy.templates["publish"]["thumbnail"] + + dbio.install() + repres = dbio.find({ + "_id": {"$in": repre_ids}, + "type": "representation" + }) + if not repres: + self.log.debug(( + "There are not representations in database with ids {}" + ).format(str(repre_ids))) + return + + thumb_repre = None + for repre in repres: + if repre["name"].lower() == "thumbnail": + thumb_repre = repre + break + + if not thumb_repre: + self.log.debug( + "There is not representation with name \"thumbnail\"" + ) + return + + version = dbio.find_one({"_id": thumb_repre["parent"]}) + if not version: + self.log.warning("There does not exist version with id {}".format( + str(thumb_repre["parent"]) + )) + return + + # Get full path to thumbnail file from representation + src_full_path = os.path.normpath(thumb_repre["data"]["path"]) + if not os.path.exists(src_full_path): + self.log.warning("Thumbnail file was not found. Path: {}".format( + src_full_path + )) + return + + # Create id for mongo entity now to fill anatomy template + thumbnail_id = ObjectId() + + # Prepare anatomy template fill data + template_data = copy.deepcopy(thumb_repre["context"]) + template_data["_id"] = str(thumbnail_id) + template_data["thumbnail_root"] = os.environ.get( + "AVALON_THUMBNAIL_ROOT" + ) + + anatomy_filled = anatomy.format(template_data) + final_path = anatomy_filled.get("publish", {}).get("thumbnail") + if not final_path: + self.log.warning(( + "Anatomy template was not filled with entered data" + "\nTemplate: {} " + "\nData: {}" + ).format(thumbnail_template, str(template_data))) + return + + dst_full_path = os.path.normpath(final_path) + self.log.debug( + "Copying file .. {} -> {}".format(src_full_path, dst_full_path) + ) + dirname = os.path.dirname(dst_full_path) + try: + os.makedirs(dirname) + except OSError as e: + if e.errno != errno.EEXIST: + tp, value, tb = sys.exc_info() + six.reraise(tp, value, tb) + + shutil.copy(src_full_path, dst_full_path) + + # Clean template data from keys that are dynamic + template_data.pop("_id") + template_data.pop("thumbnail_root") + + thumbnail_entity = { + "_id": thumbnail_id, + "type": "thumbnail", + "schema": "pype:thumbnail-1.0", + "data": { + "template": thumbnail_template, + "template_data": template_data + } + } + # Create thumbnail entity + dbio.insert_one(thumbnail_entity) + self.log.debug( + "Creating entity in database {}".format(str(thumbnail_entity)) + ) + # Set thumbnail id for version + dbio.update_one( + {"_id": version["_id"]}, + {"$set": {"data.thumbnail_id": thumbnail_id}} + ) + self.log.debug("Setting thumbnail for version \"{}\" <{}>".format( + version["name"], str(version["_id"]) + )) From 7b2e5f1b9e5bbc90ad1fdf947e21b323e83f44a9 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 5 Dec 2019 19:31:58 +0100 Subject: [PATCH 7/9] integrate thumbnails now works --- .../global/publish/integrate_thumbnail.py | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/pype/plugins/global/publish/integrate_thumbnail.py b/pype/plugins/global/publish/integrate_thumbnail.py index 9a7418eebe..08157187df 100644 --- a/pype/plugins/global/publish/integrate_thumbnail.py +++ b/pype/plugins/global/publish/integrate_thumbnail.py @@ -8,7 +8,7 @@ import six import pyblish.api from bson.objectid import ObjectId -from avalon import api, dbio +from avalon import api, io class IntegrateThumbnails(pyblish.api.InstancePlugin): @@ -19,7 +19,7 @@ class IntegrateThumbnails(pyblish.api.InstancePlugin): families = ["review"] def process(self, instance): - repre_ids = instance.get("published_representation_ids") + repre_ids = instance.data.get("published_representation_ids") if not repre_ids: self.log.debug( "There are not published representation ids on the instance." @@ -30,27 +30,24 @@ class IntegrateThumbnails(pyblish.api.InstancePlugin): anatomy = instance.context.data["anatomy"] if "publish" not in anatomy.templates: - self.log.error("Anatomy does not have set publish key!") - return + raise AssertionError("Anatomy does not have set publish key!") if "thumbnail" not in anatomy.templates["publish"]: - self.log.warning(( - "There is not set \"thumbnail\" template for project {}" + raise AssertionError(( + "There is not set \"thumbnail\" template for project \"{}\"" ).format(project_name)) - return thumbnail_template = anatomy.templates["publish"]["thumbnail"] - dbio.install() - repres = dbio.find({ + io.install() + repres = io.find({ "_id": {"$in": repre_ids}, "type": "representation" }) if not repres: - self.log.debug(( + raise AssertionError(( "There are not representations in database with ids {}" ).format(str(repre_ids))) - return thumb_repre = None for repre in repres: @@ -64,12 +61,13 @@ class IntegrateThumbnails(pyblish.api.InstancePlugin): ) return - version = dbio.find_one({"_id": thumb_repre["parent"]}) + version = io.find_one({"_id": thumb_repre["parent"]}) if not version: - self.log.warning("There does not exist version with id {}".format( - str(thumb_repre["parent"]) - )) - return + raise AssertionError( + "There does not exist version with id {}".format( + str(thumb_repre["parent"]) + ) + ) # Get full path to thumbnail file from representation src_full_path = os.path.normpath(thumb_repre["data"]["path"]) @@ -79,25 +77,27 @@ class IntegrateThumbnails(pyblish.api.InstancePlugin): )) return + filename, file_extension = os.path.splitext(src_full_path) # Create id for mongo entity now to fill anatomy template thumbnail_id = ObjectId() # Prepare anatomy template fill data template_data = copy.deepcopy(thumb_repre["context"]) - template_data["_id"] = str(thumbnail_id) - template_data["thumbnail_root"] = os.environ.get( - "AVALON_THUMBNAIL_ROOT" - ) + template_data.update({ + "_id": str(thumbnail_id), + "thumbnail_root": os.environ.get("AVALON_THUMBNAIL_ROOT"), + "ext": file_extension, + "thumbnail_type": "thumbnail" + }) anatomy_filled = anatomy.format(template_data) final_path = anatomy_filled.get("publish", {}).get("thumbnail") if not final_path: - self.log.warning(( + raise AssertionError(( "Anatomy template was not filled with entered data" "\nTemplate: {} " "\nData: {}" ).format(thumbnail_template, str(template_data))) - return dst_full_path = os.path.normpath(final_path) self.log.debug( @@ -127,12 +127,12 @@ class IntegrateThumbnails(pyblish.api.InstancePlugin): } } # Create thumbnail entity - dbio.insert_one(thumbnail_entity) + io.insert_one(thumbnail_entity) self.log.debug( "Creating entity in database {}".format(str(thumbnail_entity)) ) # Set thumbnail id for version - dbio.update_one( + io.update_many( {"_id": version["_id"]}, {"$set": {"data.thumbnail_id": thumbnail_id}} ) From 8b33b22d3081d7bd876d1930509f759d9e460caa Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Sat, 7 Dec 2019 13:03:44 +0100 Subject: [PATCH 8/9] create _id in representation before insert to DB to not require query them after --- pype/plugins/global/publish/integrate_new.py | 5 +++-- pype/plugins/global/publish/integrate_thumbnail.py | 14 +++----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/pype/plugins/global/publish/integrate_new.py b/pype/plugins/global/publish/integrate_new.py index cc71fce49e..3422c95d73 100644 --- a/pype/plugins/global/publish/integrate_new.py +++ b/pype/plugins/global/publish/integrate_new.py @@ -385,6 +385,7 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): self.log.debug("__ dst: {}".format(dst)) representation = { + "_id": io.ObjectId(), "schema": "pype:representation-2.0", "type": "representation", "parent": version_id, @@ -423,8 +424,8 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): for rep in instance.data["representations"]: self.log.debug("__ represNAME: {}".format(rep['name'])) self.log.debug("__ represPATH: {}".format(rep['published_path'])) - result = io.insert_many(representations) - instance.data["published_representation_ids"] = result.inserted_ids + io.insert_many(representations) + instance.data["published_representations"] = representations # self.log.debug("Representation: {}".format(representations)) self.log.info("Registered {} items".format(len(representations))) diff --git a/pype/plugins/global/publish/integrate_thumbnail.py b/pype/plugins/global/publish/integrate_thumbnail.py index 08157187df..bf6c62155f 100644 --- a/pype/plugins/global/publish/integrate_thumbnail.py +++ b/pype/plugins/global/publish/integrate_thumbnail.py @@ -19,8 +19,8 @@ class IntegrateThumbnails(pyblish.api.InstancePlugin): families = ["review"] def process(self, instance): - repre_ids = instance.data.get("published_representation_ids") - if not repre_ids: + published_repres = instance.data.get("published_representations") + if not published_repres: self.log.debug( "There are not published representation ids on the instance." ) @@ -40,17 +40,9 @@ class IntegrateThumbnails(pyblish.api.InstancePlugin): thumbnail_template = anatomy.templates["publish"]["thumbnail"] io.install() - repres = io.find({ - "_id": {"$in": repre_ids}, - "type": "representation" - }) - if not repres: - raise AssertionError(( - "There are not representations in database with ids {}" - ).format(str(repre_ids))) thumb_repre = None - for repre in repres: + for repre in published_repres: if repre["name"].lower() == "thumbnail": thumb_repre = repre break From e05356bb904e2cef66acbb9726461d714a4fc420 Mon Sep 17 00:00:00 2001 From: Milan Kolar Date: Fri, 31 Jan 2020 15:05:49 +0100 Subject: [PATCH 9/9] gracefully skip missing thumbnail path --- pype/plugins/global/publish/extract_jpeg.py | 10 +++++----- pype/plugins/global/publish/integrate_thumbnail.py | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pype/plugins/global/publish/extract_jpeg.py b/pype/plugins/global/publish/extract_jpeg.py index 00e8a6fedf..4978649ba2 100644 --- a/pype/plugins/global/publish/extract_jpeg.py +++ b/pype/plugins/global/publish/extract_jpeg.py @@ -6,7 +6,7 @@ import pype.api class ExtractJpegEXR(pyblish.api.InstancePlugin): - """Resolve any dependency issies + """Resolve any dependency issues This plug-in resolves any paths which, if not updated might break the published file. @@ -55,8 +55,8 @@ class ExtractJpegEXR(pyblish.api.InstancePlugin): filename = os.path.splitext(input_file)[0] if not filename.endswith('.'): filename += "." - jpegFile = filename + "jpg" - full_output_path = os.path.join(stagingdir, jpegFile) + jpeg_file = filename + "jpg" + full_output_path = os.path.join(stagingdir, jpeg_file) self.log.info("output {}".format(full_output_path)) @@ -87,9 +87,9 @@ class ExtractJpegEXR(pyblish.api.InstancePlugin): instance.data["representations"] = [] representation = { - 'name': 'jpg', + 'name': 'thumbnail', 'ext': 'jpg', - 'files': jpegFile, + 'files': jpeg_file, "stagingDir": stagingdir, "thumbnail": True, "tags": ['thumbnail'] diff --git a/pype/plugins/global/publish/integrate_thumbnail.py b/pype/plugins/global/publish/integrate_thumbnail.py index bf6c62155f..1c4399b386 100644 --- a/pype/plugins/global/publish/integrate_thumbnail.py +++ b/pype/plugins/global/publish/integrate_thumbnail.py @@ -19,6 +19,12 @@ class IntegrateThumbnails(pyblish.api.InstancePlugin): families = ["review"] def process(self, instance): + + if not os.environ.get("AVALON_THUMBNAIL_ROOT"): + self.log.info("AVALON_THUMBNAIL_ROOT is not set." + " Skipping thumbnail integration.") + return + published_repres = instance.data.get("published_representations") if not published_repres: self.log.debug(