From b1687b86ed440cea599a53dfa90c6fe907c625bd Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Wed, 14 Oct 2020 13:53:24 +0200 Subject: [PATCH 01/13] disable auto ensure_scene_settings --- pype/hosts/harmony/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pype/hosts/harmony/__init__.py b/pype/hosts/harmony/__init__.py index fbf5ca6f12..92434abc77 100644 --- a/pype/hosts/harmony/__init__.py +++ b/pype/hosts/harmony/__init__.py @@ -155,8 +155,11 @@ def check_inventory(): def application_launch(): - ensure_scene_settings() - check_inventory() + # FIXME: This is breaking server <-> client communication. + # It is now moved so it it manually called. + # ensure_scene_settings() + # check_inventory() + pass def export_template(backdrops, nodes, filepath): From 1aeaa4bba175e0354371cdc8275bb2d4afd0a1b6 Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Thu, 15 Oct 2020 09:55:46 +0100 Subject: [PATCH 02/13] Missing audio on farm submission. --- pype/plugins/global/publish/submit_publish_job.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pype/plugins/global/publish/submit_publish_job.py b/pype/plugins/global/publish/submit_publish_job.py index fd109cf881..30f64f7ab9 100644 --- a/pype/plugins/global/publish/submit_publish_job.py +++ b/pype/plugins/global/publish/submit_publish_job.py @@ -732,7 +732,8 @@ class ProcessSubmittedJobOnFarm(pyblish.api.InstancePlugin): "resolutionHeight": data.get("resolutionHeight", 1080), "multipartExr": data.get("multipartExr", False), "jobBatchName": data.get("jobBatchName", ""), - "review": data.get("review", True) + "review": data.get("review", True), + "audio": data.get("audio", []) } if "prerender" in instance.data["families"]: From 6e0a2542074bca51456f4d50d748281f401b0761 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 15 Oct 2020 18:13:24 +0200 Subject: [PATCH 03/13] gave ability to enter different mongo db object than avalon.io --- pype/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pype/lib.py b/pype/lib.py index 6fa204b379..6349ef4cd8 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -1408,7 +1408,7 @@ def source_hash(filepath, *args): return "|".join([file_name, time, size] + list(args)).replace(".", ",") -def get_latest_version(asset_name, subset_name): +def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): """Retrieve latest version from `asset_name`, and `subset_name`. Args: From 2852ad1d8e9e90e7bbe2d4522afccc0ab30dda3b Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 15 Oct 2020 18:14:47 +0200 Subject: [PATCH 04/13] if dbcon keyword argument was not passed than use avalon.io --- pype/lib.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pype/lib.py b/pype/lib.py index 6349ef4cd8..153cde806d 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -1415,15 +1415,10 @@ def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): asset_name (str): Name of asset. subset_name (str): Name of subset. """ - # Get asset - asset_name = io.find_one( - {"type": "asset", "name": asset_name}, projection={"name": True} - ) - subset = io.find_one( - {"type": "subset", "name": subset_name, "parent": asset_name["_id"]}, - projection={"_id": True, "name": True}, - ) + if not dbcon: + log.debug("Using `avalon.io` for query.") + dbcon = io # Check if subsets actually exists. assert subset, "No subsets found." From b8c4dbed56221f88fc349663c5937b4c34aa3025 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 15 Oct 2020 18:17:05 +0200 Subject: [PATCH 05/13] do different stuff if project name is specified --- pype/lib.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pype/lib.py b/pype/lib.py index 153cde806d..41ee730e2a 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -1422,6 +1422,14 @@ def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): # Check if subsets actually exists. assert subset, "No subsets found." + if project_name and project_name != dbcon.Session.get("AVALON_PROJECT"): + # `avalon.io` has only `_database` attribute + # but `AvalonMongoDB` has `database` + database = getattr(dbcon, "database", dbcon._database) + collection = database[project_name] + else: + project_name = dbcon.Session.get("AVALON_PROJECT") + collection = dbcon # Get version version_projection = { From d937fde322facb27edb1e2ae90ce099ee43f78ec Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 15 Oct 2020 18:17:31 +0200 Subject: [PATCH 06/13] do not raise exceptions --- pype/lib.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/pype/lib.py b/pype/lib.py index 41ee730e2a..8f5c4527a0 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -1420,8 +1420,6 @@ def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): log.debug("Using `avalon.io` for query.") dbcon = io - # Check if subsets actually exists. - assert subset, "No subsets found." if project_name and project_name != dbcon.Session.get("AVALON_PROJECT"): # `avalon.io` has only `_database` attribute # but `AvalonMongoDB` has `database` @@ -1431,21 +1429,9 @@ def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): project_name = dbcon.Session.get("AVALON_PROJECT") collection = dbcon - # Get version - version_projection = { - "name": True, - "parent": True, - } - - version = io.find_one( - {"type": "version", "parent": subset["_id"]}, - projection=version_projection, - sort=[("name", -1)], ) - assert version, "No version found, this is a bug" - return version class ApplicationLaunchFailed(Exception): From 730be772a41538afce4f8e1a567ccb1c79efb5f2 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 15 Oct 2020 18:18:17 +0200 Subject: [PATCH 07/13] implemented finding of latest version --- pype/lib.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pype/lib.py b/pype/lib.py index 8f5c4527a0..527db4a38a 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -1429,9 +1429,28 @@ def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): project_name = dbcon.Session.get("AVALON_PROJECT") collection = dbcon + # Query asset document id by asset name + asset_doc = collection.find_one( + {"type": "asset", "name": asset_name}, + {"_id": True} ) + if not asset_doc: + return None + subset_doc = collection.find_one( + {"type": "subset", "name": subset_name, "parent": asset_doc["_id"]}, + {"_id": True} + ) + if not subset_doc: + return None + version_doc = collection.find_one( + {"type": "version", "parent": subset_doc["_id"]}, + sort=[("name", -1)], + ) + if not version_doc: + return None + return version_doc class ApplicationLaunchFailed(Exception): From 120865eb7fe917adb1041505c0ce75390d84927d Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 15 Oct 2020 18:18:30 +0200 Subject: [PATCH 08/13] added few loggings --- pype/lib.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pype/lib.py b/pype/lib.py index 527db4a38a..260281f6bd 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -1429,12 +1429,20 @@ def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): project_name = dbcon.Session.get("AVALON_PROJECT") collection = dbcon + log.debug(( + "Getting latest version for Project: \"{}\" Asset: \"{}\"" + " and Subset: \"{}\"" + ).format(project_name, asset_name, subset_name)) + # Query asset document id by asset name asset_doc = collection.find_one( {"type": "asset", "name": asset_name}, {"_id": True} ) if not asset_doc: + log.info( + "Asset \"{}\" was not found in Database.".format(asset_name) + ) return None subset_doc = collection.find_one( @@ -1442,6 +1450,9 @@ def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): {"_id": True} ) if not subset_doc: + log.info( + "Subset \"{}\" was not found in Database.".format(subset_name) + ) return None version_doc = collection.find_one( @@ -1449,6 +1460,9 @@ def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): sort=[("name", -1)], ) if not version_doc: + log.info( + "Subset \"{}\" does not have any version yet.".format(subset_name) + ) return None return version_doc From 27dfb159436ed32d9cb0e210c335433b6788c80c Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 15 Oct 2020 18:18:37 +0200 Subject: [PATCH 09/13] filled docstring --- pype/lib.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pype/lib.py b/pype/lib.py index 260281f6bd..02ea46c0ff 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -1414,6 +1414,13 @@ def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): Args: asset_name (str): Name of asset. subset_name (str): Name of subset. + dbcon (avalon.mongodb.AvalonMongoDB, optional): Avalon Mongo connection + with Session. + project_name (str, optional): Find latest version in specific project. + + Returns: + None: If asset, subset or version were not found. + dict: Last version document for entered . """ if not dbcon: From 96048ce6d7c4474df8704c016746c640b08ef24f Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 15 Oct 2020 18:18:59 +0200 Subject: [PATCH 10/13] changed way how get_latest_version is used in nuke's collect_review --- pype/plugins/nuke/publish/collect_review.py | 25 ++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pype/plugins/nuke/publish/collect_review.py b/pype/plugins/nuke/publish/collect_review.py index e7e8da19a1..3b3786ed09 100644 --- a/pype/plugins/nuke/publish/collect_review.py +++ b/pype/plugins/nuke/publish/collect_review.py @@ -1,3 +1,4 @@ +import os import pyblish.api import pype.api from avalon import io, api @@ -26,20 +27,24 @@ class CollectReview(pyblish.api.InstancePlugin): if not node["review"].value(): return - # Add audio to instance if it exists. - try: - version = pype.api.get_latest_version( - instance.context.data["assetEntity"]["name"], "audioMain" - ) - representation = io.find_one( - {"type": "representation", "parent": version["_id"]} + # * Add audio to instance if exists. + # Find latest versions document + version_doc = pype.api.get_latest_version( + instance.context.data["assetEntity"]["name"], "audioMain" + ) + repre_doc = None + if version_doc: + # Try to find it's representation (Expected there is only one) + repre_doc = io.find_one( + {"type": "representation", "parent": version_doc["_id"]} ) + + # Add audio to instance if representation was found + if repre_doc: instance.data["audio"] = [{ "offset": 0, - "filename": api.get_representation_path(representation) + "filename": api.get_representation_path(repre_doc) }] - except AssertionError: - pass instance.data["families"].append("review") instance.data['families'].append('ftrack') From 4813365aeda92c15b89ead3c5ae578006104e26d Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 15 Oct 2020 18:22:08 +0200 Subject: [PATCH 11/13] added note to doctring --- pype/lib.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pype/lib.py b/pype/lib.py index 02ea46c0ff..c4321e0605 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -1411,6 +1411,10 @@ def source_hash(filepath, *args): def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): """Retrieve latest version from `asset_name`, and `subset_name`. + Do not use if you want to query more than 5 latest versions as this method + query 3 times to mongo for each call. For those cases is better to use + more efficient way, e.g. with help of aggregations. + Args: asset_name (str): Name of asset. subset_name (str): Name of subset. From c63df5277efb97f715796858d69956442704568a Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 15 Oct 2020 18:25:13 +0200 Subject: [PATCH 12/13] make sure `avalon.io` is installed when using --- pype/lib.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pype/lib.py b/pype/lib.py index c4321e0605..7370f10756 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -1430,6 +1430,8 @@ def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): if not dbcon: log.debug("Using `avalon.io` for query.") dbcon = io + # Make sure is installed + io.install() if project_name and project_name != dbcon.Session.get("AVALON_PROJECT"): # `avalon.io` has only `_database` attribute From a80f1618e63dc25e3dcb7c66f5e56eceb57bede8 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 15 Oct 2020 18:34:44 +0200 Subject: [PATCH 13/13] removed unused import --- pype/plugins/nuke/publish/collect_review.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pype/plugins/nuke/publish/collect_review.py b/pype/plugins/nuke/publish/collect_review.py index 3b3786ed09..42aa910917 100644 --- a/pype/plugins/nuke/publish/collect_review.py +++ b/pype/plugins/nuke/publish/collect_review.py @@ -1,4 +1,3 @@ -import os import pyblish.api import pype.api from avalon import io, api