Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jakub Trllo <[email protected]>
Co-authored-by: Kayla Man <[email protected]>
Co-authored-by: Jakub Ježek <[email protected]>
  • Loading branch information
4 people authored Nov 13, 2024
1 parent 4b3d6bd commit 63413da
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions client/ayon_traypublisher/plugins/create/create_csv_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,37 +404,39 @@ def _validate_parents(project_name: str, product_item: ProductItem) -> list:
Raise:
ValueError: When provided folder_path parent do not exist.
"""
parent_folder_path, folder_name = product_item.folder_path.rsplit("/", 1)
if not parent_folder_path:
parent_folder_names = product_item.folder_path.lstrip("/").split("/")
# Rename name of folder itself
parent_folder_names.pop(-1)
if not parent_folder_names:
return []

folder_data = ayon_api.get_folder_by_path(
project_name,
parent_folder_path,
fields=("folderType",)
)

if folder_data is None:
raise ValueError(f"Unknown parent folder {parent_folder_path}")
parent_paths = []
parent_path = ""
for name in parent_folder_names:
path = f"{parent_path}/{name}"
parent_paths.append(path)
parent_path = path

parent_data = []
inspected = []

for key in parent_folder_path.split("/"):
if not key:
continue

inspected.append(key)
folder_data = ayon_api.get_folder_by_path(
folders_by_path = {
folder["path"]: folder
for folder in ayon_api.get_folders(
project_name,
f"/{'/'.join(inspected)}",
fields=("folderType",)
folder_paths=parent_paths,
fields={"folderType", "path"}
)
}
parent_data = []
for path in parent_paths:
folder_entity = folders_by_path.get(path)
if not folder_entity:
# TODO This should be some artist friendy error
# raising 'CreatorError'
raise ValueError(f"Unknown parent folder {path}")
name = path.rsplit("/", 1)[-1]
parent_data.append({
"folder_type": folder_data["folderType"],
"entity_name": key
"folder_type": folder_entity["folderType"],
"entity_name": name
})

return parent_data


Expand Down Expand Up @@ -896,7 +898,7 @@ def _create_instances_from_csv_data(self, csv_dir: str, filename: str):
}

if product_item.has_promised_context:
hierarchy, _ = folder_path.rsplit("/",1)
hierarchy, _ = folder_path.rsplit("/", 1)
families.append("csv_ingest_shot")
instance_data.update(
{
Expand All @@ -906,11 +908,14 @@ def _create_instances_from_csv_data(self, csv_dir: str, filename: str):
}
)
# TODO create new task from provided task name
# if product_item.task_name:
# instance_data["tasks"] = {
# "name": product_item.task_name,
# "type": "Generic"
# }
if product_item.task_name:
tasks = instance_data.setdefault("tasks", [])
tasks.append(
{
"name": product_item.task_name,
"type": "Generic"
}
)

# create new instance
new_instance: CreatedInstance = CreatedInstance(
Expand Down

0 comments on commit 63413da

Please sign in to comment.