From 08bf7e5b7c6e3a244ed1dbfb5aa7e663b5db8933 Mon Sep 17 00:00:00 2001 From: jezscha Date: Tue, 8 Jun 2021 09:59:30 +0000 Subject: [PATCH 1/5] Create draft PR for #1658 From c4fb8fdbe1ea45ce0fcbed33faf25860e4a982c1 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 8 Jun 2021 12:36:50 +0200 Subject: [PATCH 2/5] Global: fix duplicity of plugin --- .../integrate_ftrack_component_overwrite.py | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 openpype/plugins/publish/integrate_ftrack_component_overwrite.py diff --git a/openpype/plugins/publish/integrate_ftrack_component_overwrite.py b/openpype/plugins/publish/integrate_ftrack_component_overwrite.py deleted file mode 100644 index 047fd8462c..0000000000 --- a/openpype/plugins/publish/integrate_ftrack_component_overwrite.py +++ /dev/null @@ -1,21 +0,0 @@ -import pyblish.api - - -class IntegrateFtrackComponentOverwrite(pyblish.api.InstancePlugin): - """ - Set `component_overwrite` to True on all instances `ftrackComponentsList` - """ - - order = pyblish.api.IntegratorOrder + 0.49 - label = 'Overwrite ftrack created versions' - families = ["clip"] - optional = True - active = False - - def process(self, instance): - component_list = instance.data['ftrackComponentsList'] - - for cl in component_list: - cl['component_overwrite'] = True - self.log.debug('Component {} overwriting'.format( - cl['component_data']['name'])) From 0fea8b201c52bc02e5ee4b41d2c6c23e2c06b67b Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 8 Jun 2021 18:06:25 +0200 Subject: [PATCH 3/5] Global: validator plugin editorial asset names --- .../publish/validate_editorial_asset_name.py | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 openpype/plugins/publish/validate_editorial_asset_name.py diff --git a/openpype/plugins/publish/validate_editorial_asset_name.py b/openpype/plugins/publish/validate_editorial_asset_name.py new file mode 100644 index 0000000000..6548b8ea89 --- /dev/null +++ b/openpype/plugins/publish/validate_editorial_asset_name.py @@ -0,0 +1,113 @@ +import pyblish.api +from avalon import io +from pprint import pformat + + +class ValidateEditorialAssetName(pyblish.api.ContextPlugin): + """ Validating if editorial's asset names are not already created in db. + + Checking variations of names with different size of caps or with or without underscores. + """ + + order = pyblish.api.ValidatorOrder + label = "Validate Asset Name" + + def process(self, context): + + asset_and_parents = self.get_parents(context) + + if not io.Session: + io.install() + + db_assets = list(io.find( + {"type": "asset"}, {"name": 1, "data.parents": 1})) + self.log.debug("__ db_assets: {}".format(db_assets)) + + project_entities = { + str(e["name"]): e["data"]["parents"] for e in db_assets} + + self.log.debug("__ project_entities: {}".format( + pformat(project_entities))) + + assets_missing_name = {} + assets_wrong_parent = {} + for asset in asset_and_parents.keys(): + if asset not in project_entities.keys(): + # add to some nonexistent list for next layer of check + assets_missing_name.update({asset: asset_and_parents[asset]}) + continue + + if asset_and_parents[asset] != project_entities[asset]: + # add to some nonexistent list for next layer of check + assets_wrong_parent.update({ + asset: { + "required": asset_and_parents[asset], + "already_in_db": project_entities[asset] + } + }) + continue + + self.log.info("correct asset: {}".format(asset)) + + if assets_missing_name: + wrong_names = {} + self.log.debug( + ">> assets_missing_name: {}".format(assets_missing_name)) + for asset in assets_missing_name.keys(): + _asset = asset.lower().replace("_", "") + if _asset in [a.lower().replace("_", "") + for a in project_entities.keys()]: + wrong_names.update({ + "required_name": asset, + "used_variants_in_db": [ + a for a in project_entities.keys() + if a.lower().replace("_", "") == _asset + ] + }) + + if wrong_names: + self.log.debug( + ">> wrong_names: {}".format(wrong_names)) + raise Exception( + "Some already existing asset name variants `{}`".format( + wrong_names)) + + + + if assets_wrong_parent: + self.log.debug( + ">> assets_wrong_parent: {}".format(assets_wrong_parent)) + raise Exception( + "Wrong parents on assets `{}`".format(assets_wrong_parent)) + + def _get_all_assets(self, input_dict): + """ Returns asset names in list. + + List contains all asset names including parents + """ + for key in input_dict.keys(): + # check if child key is available + if input_dict[key].get("childs"): + # loop deeper + self._get_all_assets( + input_dict[key]["childs"]) + else: + self.all_testing_assets.append(key) + + def get_parents(self, context): + return_dict = {} + for instance in context: + asset = instance.data["asset"] + families = instance.data.get("families", []) + [ + instance.data["family"] + ] + # filter out non-shot families + if "shot" not in families: + continue + + parents = instance.data["parents"] + + return_dict.update({ + asset: [p["entity_name"] for p in parents] + }) + return return_dict From 7e164c8a470b4a1a7a91f153b00549443297b50f Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 8 Jun 2021 18:11:35 +0200 Subject: [PATCH 4/5] hound: suggestions --- openpype/plugins/publish/validate_editorial_asset_name.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openpype/plugins/publish/validate_editorial_asset_name.py b/openpype/plugins/publish/validate_editorial_asset_name.py index 6548b8ea89..60b8f76a07 100644 --- a/openpype/plugins/publish/validate_editorial_asset_name.py +++ b/openpype/plugins/publish/validate_editorial_asset_name.py @@ -6,7 +6,8 @@ from pprint import pformat class ValidateEditorialAssetName(pyblish.api.ContextPlugin): """ Validating if editorial's asset names are not already created in db. - Checking variations of names with different size of caps or with or without underscores. + Checking variations of names with different size of caps or with + or without underscores. """ order = pyblish.api.ValidatorOrder @@ -72,8 +73,6 @@ class ValidateEditorialAssetName(pyblish.api.ContextPlugin): "Some already existing asset name variants `{}`".format( wrong_names)) - - if assets_wrong_parent: self.log.debug( ">> assets_wrong_parent: {}".format(assets_wrong_parent)) From 35192876dc3a4d643a45c7742456ce28de1bf538 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 11 Jun 2021 10:26:18 +0200 Subject: [PATCH 5/5] Global: suggested namespace change --- .../publish/validate_editorial_asset_name.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openpype/plugins/publish/validate_editorial_asset_name.py b/openpype/plugins/publish/validate_editorial_asset_name.py index 60b8f76a07..ccea42dc37 100644 --- a/openpype/plugins/publish/validate_editorial_asset_name.py +++ b/openpype/plugins/publish/validate_editorial_asset_name.py @@ -24,26 +24,26 @@ class ValidateEditorialAssetName(pyblish.api.ContextPlugin): {"type": "asset"}, {"name": 1, "data.parents": 1})) self.log.debug("__ db_assets: {}".format(db_assets)) - project_entities = { + asset_db_docs = { str(e["name"]): e["data"]["parents"] for e in db_assets} self.log.debug("__ project_entities: {}".format( - pformat(project_entities))) + pformat(asset_db_docs))) assets_missing_name = {} assets_wrong_parent = {} for asset in asset_and_parents.keys(): - if asset not in project_entities.keys(): + if asset not in asset_db_docs.keys(): # add to some nonexistent list for next layer of check assets_missing_name.update({asset: asset_and_parents[asset]}) continue - if asset_and_parents[asset] != project_entities[asset]: + if asset_and_parents[asset] != asset_db_docs[asset]: # add to some nonexistent list for next layer of check assets_wrong_parent.update({ asset: { "required": asset_and_parents[asset], - "already_in_db": project_entities[asset] + "already_in_db": asset_db_docs[asset] } }) continue @@ -57,11 +57,11 @@ class ValidateEditorialAssetName(pyblish.api.ContextPlugin): for asset in assets_missing_name.keys(): _asset = asset.lower().replace("_", "") if _asset in [a.lower().replace("_", "") - for a in project_entities.keys()]: + for a in asset_db_docs.keys()]: wrong_names.update({ "required_name": asset, "used_variants_in_db": [ - a for a in project_entities.keys() + a for a in asset_db_docs.keys() if a.lower().replace("_", "") == _asset ] })