Skip to content

Commit

Permalink
move comments import to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
iLLiCiTiT committed Jan 21, 2025
1 parent 34e7dec commit 87a9392
Showing 1 changed file with 43 additions and 37 deletions.
80 changes: 43 additions & 37 deletions server/ftrack_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 87a9392

Please sign in to comment.