From 2f4d40287435a46747189f9d0ef199e71afbc64f Mon Sep 17 00:00:00 2001 From: "robin@ynput.io" Date: Wed, 30 Oct 2024 16:06:03 -0400 Subject: [PATCH] Enforce backward compatibility with OpenPype projects. --- .../plugins/create/create_shot_clip.py | 45 ++++++++++++++++--- .../plugins/publish/extract_clip_effects.py | 2 +- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/client/ayon_hiero/plugins/create/create_shot_clip.py b/client/ayon_hiero/plugins/create/create_shot_clip.py index 60ad717..0acdff9 100644 --- a/client/ayon_hiero/plugins/create/create_shot_clip.py +++ b/client/ayon_hiero/plugins/create/create_shot_clip.py @@ -629,7 +629,13 @@ def _collect_legacy_instance(self, track_item): instance_data = { "clip_index": track_item.guid(), "task": None, + "variant": track_item.parentTrack().name(), + "extract_audio": False, } + for create_attr in self.get_pre_create_attr_defs(): + if isinstance(create_attr.key, str): + instance_data[create_attr.key] = create_attr.default + required_key_mapping = { "tag.audio": ("extract_audio", bool), "tag.heroTrack": ("heroTrack", bool), @@ -643,27 +649,51 @@ def _collect_legacy_instance(self, track_item): "tag.hierarchy": ("hierarchy", str), "tag.hierarchyData": ("hierarchyData", json), "tag.asset_name": ("folderName", str), + "tag.asset": ("productName", str), "tag.active": ("active", bool), "tag.productName": ("productName", str), "tag.parents": ("parents", json), } - try: - for key, value in required_key_mapping.items(): + for key, value in required_key_mapping.items(): + if key not in data: + continue + + try: instance_key, type_cast = value if type_cast is bool: instance_data[instance_key] = data[key] == "True" elif type_cast is json: conformed_data = data[key].replace("'", "\"") + conformed_data = conformed_data.replace('u"', '"') instance_data[instance_key] = json.loads(conformed_data) else: instance_data[instance_key] = type_cast(data[key]) - except RuntimeError as error: - self.log.warning( - "Cannot retrieve instance from legacy " - f"tag data: {error}." - ) + except Exception as error: + self.log.warning( + "Cannot retrieve instance from legacy " + f"tag data: {error}." + ) + + if not "folderPath" in instance_data: + try: + instance_data["folderPath"] = ( + "/" + instance_data["hierarchy"] + "/" + + instance_data["productName"] + ) + except KeyError: + instance_data["folderPath"] = "unknown" + instance_data["active"] = False + + if "tag.subset" in data: + instance_data["variant"] = data["tag.subset"].replace("plate", "") + + for folder in instance_data.get("parents", []): + if "entity_name" in folder: + folder["folder_name"] = folder["entity_name"] + if "entity_type" in folder: + folder["folder_type"] = folder["entity_type"] # Create parent shot instance. sub_instance_data = instance_data.copy() @@ -672,6 +702,7 @@ def _collect_legacy_instance(self, track_item): sub_instance_data["workfileFrameStart"] sub_instance_data.update({ "label": f"{sub_instance_data['folderPath']} shot", + "variant": "main", "creator_attributes": { "workfileFrameStart": workfileFrameStart, "handleStart": sub_instance_data["handleStart"], diff --git a/client/ayon_hiero/plugins/publish/extract_clip_effects.py b/client/ayon_hiero/plugins/publish/extract_clip_effects.py index 7ee979c..e034809 100644 --- a/client/ayon_hiero/plugins/publish/extract_clip_effects.py +++ b/client/ayon_hiero/plugins/publish/extract_clip_effects.py @@ -94,7 +94,7 @@ def process(self, instance): def copy_linked_files(self, effect, dst_dir): for k, v in effect["node"].items(): - if k in "file" and v != '': + if k in "file" and isinstance(v, str) and v != '': base_name = os.path.basename(v) dst = os.path.join(dst_dir, base_name).replace("\\", "/")