Skip to content

Commit

Permalink
Enforce backward compatibility with OpenPype projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-ynput committed Oct 30, 2024
1 parent da70ce3 commit 2f4d402
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
45 changes: 38 additions & 7 deletions client/ayon_hiero/plugins/create/create_shot_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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()
Expand All @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion client/ayon_hiero/plugins/publish/extract_clip_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("\\", "/")

Expand Down

0 comments on commit 2f4d402

Please sign in to comment.