Skip to content

Commit

Permalink
Add plugin settings for traypublishr CSV ingest
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-ynput committed Nov 13, 2024
1 parent 63413da commit 303efed
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 16 deletions.
48 changes: 33 additions & 15 deletions client/ayon_traypublisher/plugins/create/create_csv_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class IngestCSV(TrayPublishCreator):
# settings for this creator
columns_config = {}
representations_config = {}
folder_creation_config = {}

def get_instance_attr_defs(self):
return [
Expand Down Expand Up @@ -390,8 +391,7 @@ def _resolve_repre_path(

return filepath

@staticmethod
def _validate_parents(project_name: str, product_item: ProductItem) -> list:
def _validate_parents(self, project_name: str, product_item: ProductItem) -> list:
""" Ensure parent exists for provided product_item.folder_path
Args:
Expand Down Expand Up @@ -428,15 +428,26 @@ def _validate_parents(project_name: str, product_item: ProductItem) -> list:
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]

# Folder exists, retrieve data from existing.
if folder_entity:
folder_type = folder_entity["folderType"]

# Define folder type from settings.
else:
for folder_setting in self.folder_creation_config["folder_type_regexes"]:
if re.match(folder_setting["regex"], name):
folder_type = folder_setting["folder_type"]
break
else:
folder_type = "Folder" # default

parent_data.append({
"folder_type": folder_entity["folderType"],
"folder_type": folder_type,
"entity_name": name
})

return parent_data


Expand Down Expand Up @@ -526,6 +537,13 @@ def _get_data_from_csv(
task_entities_by_folder_id[folder_id].append(task_entity)

missing_tasks: Set[str] = set()
if missing_paths and not self.folder_creation_config["enabled"]:
error_msg = (
"Folder creation is disabled but found missing folder(s): %r" %
",".join(missing_paths)
)
raise CreatorError(error_msg)

for product_item in product_items_by_name.values():
folder_path = product_item.folder_path

Expand Down Expand Up @@ -908,14 +926,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:
tasks = instance_data.setdefault("tasks", [])
tasks.append(
{
"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
38 changes: 37 additions & 1 deletion server/settings/creator_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ def validate_unique_outputs(cls, value):
return value


class FolderTypeRegexItem(BaseSettingsModel):
_layout = "expanded"
regex: str = SettingsField("", title="Folder Regex")
folder_type: str = SettingsField("", title="Folder Type")


class FolderCreationConfigModel(BaseSettingsModel):
"""Allow to create folder hierarchy when non-existing."""

enabled: bool = SettingsField(
title="Enabled folder creation",
default=False,
)

folder_type_regexes: list[FolderTypeRegexItem] = SettingsField(
default_factory=FolderTypeRegexItem,
description=(
"Using Regex expressions to create missing folders. \nThose can be used"
" to define which folder types are used for new folder creation"
" depending on their names."
)
)


class IngestCSVPluginModel(BaseSettingsModel):
"""Allows to publish multiple video files in one go. <br />Name of matching
asset is parsed from file names ('asset.mov', 'asset_v001.mov',
Expand All @@ -148,6 +172,11 @@ class IngestCSVPluginModel(BaseSettingsModel):
default_factory=RepresentationConfigModel
)

folder_creation_config: FolderCreationConfigModel = SettingsField(
title="Folder creation config",
default_factory=FolderCreationConfigModel
)


class TrayPublisherCreatePluginsModel(BaseSettingsModel):
BatchMovieCreator: BatchMovieCreatorPlugin = SettingsField(
Expand Down Expand Up @@ -336,6 +365,13 @@ class TrayPublisherCreatePluginsModel(BaseSettingsModel):
]
}
]
}
},
"folder_creation_config": {
"enabled": False,
"folder_type_regexes": [
{"regex": "(sh.*)", "folder_type": "Shot"},
{"regex": "(seq.*)", "folder_type": "Sequence"}
],
}
}
}

0 comments on commit 303efed

Please sign in to comment.