From 87a939221b293efb8c81f6942fc89cc1dc23fa8e Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 21 Jan 2025 13:49:17 +0100 Subject: [PATCH] move comments import to separate function --- server/ftrack_import.py | 80 ++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/server/ftrack_import.py b/server/ftrack_import.py index acfe13f..7d88785 100644 --- a/server/ftrack_import.py +++ b/server/ftrack_import.py @@ -1183,44 +1183,11 @@ async def _collect_project_data( } -async def import_project( +async def _import_comments( project_name: str, session: FtrackSession, - studio_settings: dict[str, Any], + activities: ActivitiesWrap, ): - """Sync ftrack project data to AYON. - - Args: - project_name (str): Name of the project. - session (FtrackSession): ftrack session. - studio_settings (dict[str, Any]): Studio settings. - - """ - data = await _collect_project_data( - session, project_name, studio_settings, - ) - project_code = data["project_code"] - - await create_project_from_anatomy( - project_name, - project_code, - Anatomy(**data["project"]), - ) - operations = ProjectLevelOperations(project_name) - for folder_entity in data["folders"]: - operations.create("folder", **folder_entity) - - for task_entity in data["tasks"]: - operations.create("task", **task_entity) - - for product_entity in data["products"]: - operations.create("product", **product_entity) - - for version_entity in data["versions"]: - operations.create("version", **version_entity) - - await operations.process() - entity_by_id = {} async def _get_entity_obj(e_id, e_type): obj = entity_by_id.get(e_id) @@ -1231,8 +1198,6 @@ async def _get_entity_obj(e_id, e_type): return obj ftrack_batch_operations = [] - activities: ActivitiesWrap = data["activities"] - for activity, ftrack_id, metadata_item in activities.iter(): entity_id = activity.pop("parent_id") entity_type = activity.pop("parent_type") @@ -1270,6 +1235,47 @@ async def _get_entity_obj(e_id, e_type): for operations_chunk in create_chunks(ftrack_batch_operations, 50): await session.call(operations_chunk) + +async def import_project( + project_name: str, + session: FtrackSession, + studio_settings: dict[str, Any], +): + """Sync ftrack project data to AYON. + + Args: + project_name (str): Name of the project. + session (FtrackSession): ftrack session. + studio_settings (dict[str, Any]): Studio settings. + + """ + data = await _collect_project_data( + session, project_name, studio_settings, + ) + project_code = data["project_code"] + + await create_project_from_anatomy( + project_name, + project_code, + Anatomy(**data["project"]), + ) + operations = ProjectLevelOperations(project_name) + for folder_entity in data["folders"]: + operations.create("folder", **folder_entity) + + for task_entity in data["tasks"]: + operations.create("task", **task_entity) + + for product_entity in data["products"]: + operations.create("product", **product_entity) + + for version_entity in data["versions"]: + operations.create("version", **version_entity) + + await operations.process() + + await _import_comments(project_name, session, data["activities"]) + # components: dict[str, dict[str, Any]] = data["components"] # for resource_id, component in components.items(): # THIS IS EXAMPLE CONTENT