Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CSV ingest to create new shots. #36

Merged
93 changes: 87 additions & 6 deletions client/ayon_traypublisher/plugins/create/create_csv_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ def __init__(
self.variant = variant
self.product_type = product_type
self.repre_items: List[RepreItem] = []
self.has_promised_context = False
self.parents = None
self._unique_name = None
self._pre_product_name = None

Expand Down Expand Up @@ -388,6 +390,54 @@ def _resolve_repre_path(

return filepath

@staticmethod
def _validate_parents(project_name: str, product_item: ProductItem) -> list:
""" Ensure parent exists for provided product_item.folder_path

Args:
project_name (str): The project name.
product_item (ProductItem): The product item to inspect.

Returns:
list. The parent list if any

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:
return []

folder_data = ayon_api.get_folder_by_path(
project_name,
parent_folder_path,
fields=("folderType",)
)
robin-ynput marked this conversation as resolved.
Show resolved Hide resolved

if folder_data is None:
raise ValueError(f"Unknown parent folder {parent_folder_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(
project_name,
f"/{'/'.join(inspected)}",
fields=("folderType",)
)
parent_data.append({
"folder_type": folder_data["folderType"],
"entity_name": key
})

return parent_data
robin-ynput marked this conversation as resolved.
Show resolved Hide resolved


def _get_data_from_csv(
self, csv_dir: str, filename: str
) -> Dict[str, ProductItem]:
Expand Down Expand Up @@ -458,12 +508,6 @@ def _get_data_from_csv(
)
}
missing_paths: Set[str] = folder_paths - set(folder_ids_by_path.keys())
if missing_paths:
ending = "" if len(missing_paths) == 1 else "s"
joined_paths = "\n".join(sorted(missing_paths))
raise CreatorError(
f"Folder{ending} not found.\n{joined_paths}"
)

task_names: Set[str] = {
product_item.task_name
Expand All @@ -482,6 +526,22 @@ def _get_data_from_csv(
missing_tasks: Set[str] = set()
for product_item in product_items_by_name.values():
folder_path = product_item.folder_path

if folder_path in missing_paths:
product_item.has_promised_context = True
product_item.task_type = None
try:
product_item.parents = self._validate_parents(
project_name,
product_item
)
except ValueError:
raise CreatorError(
f"Parent context must exists for new shots: {folder_path}"
robin-ynput marked this conversation as resolved.
Show resolved Hide resolved
)

continue

task_name = product_item.task_name
folder_id = folder_ids_by_path[folder_path]
task_entities = task_entities_by_folder_id[folder_id]
Expand Down Expand Up @@ -835,6 +895,23 @@ def _create_instances_from_csv_data(self, csv_dir: str, filename: str):
"prepared_data_for_repres": []
}

if product_item.has_promised_context:
hierarchy, _ = folder_path.rsplit("/",1)
robin-ynput marked this conversation as resolved.
Show resolved Hide resolved
families.append("csv_ingest_shot")
robin-ynput marked this conversation as resolved.
Show resolved Hide resolved
instance_data.update(
{
"newHierarchyIntegration": True,
"hierarchy": hierarchy,
"parents": product_item.parents
}
)
# TODO create new task from provided task name
# if product_item.task_name:
# instance_data["tasks"] = {
# "name": product_item.task_name,
# "type": "Generic"
# }
robin-ynput marked this conversation as resolved.
Show resolved Hide resolved
robin-ynput marked this conversation as resolved.
Show resolved Hide resolved

# create new instance
new_instance: CreatedInstance = CreatedInstance(
product_item.product_type,
Expand All @@ -843,6 +920,10 @@ def _create_instances_from_csv_data(self, csv_dir: str, filename: str):
self
)
self._prepare_representations(product_item, new_instance)

if product_item.has_promised_context:
new_instance.transient_data["has_promised_context"] = True

instances.append(new_instance)

return instances