Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Change: Asset is put under an AssetType folder #3543

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 38 additions & 23 deletions openpype/modules/kitsu/utils/update_op_with_zou.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
get_project,
get_assets,
get_asset_by_id,
get_asset_by_name
get_asset_by_name,
)
from openpype.pipeline import AvalonMongoDB
from openpype.api import get_project_settings
Expand Down Expand Up @@ -154,17 +154,23 @@ def update_op_assets(
parent_zou_id = substitute_parent_item["parent_id"]
else:
parent_zou_id = (
item.get("parent_id")
# For Asset, put under asset type directory
item.get("entity_type_id")
if item_type == "Asset"
else None
# Else, fallback on usual hierarchy
or item.get("parent_id")
or item.get("episode_id")
or item.get("source_id")
) # TODO check consistency
)

# Substitute Episode and Sequence by Shot
substitute_item_type = (
"shots"
if item_type in ["Episode", "Sequence"]
else f"{item_type.lower()}s"
)
# Substitute item type for general classification (assets or shots)
if item_type in ["Asset", "AssetType"]:
substitute_item_type = "assets"
elif item_type in ["Episode", "Sequence"]:
substitute_item_type = "shots"
else:
substitute_item_type = f"{item_type.lower()}s"
entity_parent_folders = [
f
for f in project_module_settings["entities_root"]
Expand All @@ -181,8 +187,8 @@ def update_op_assets(
# Find root folder docs
root_folder_docs = get_assets(
project_name,
asset_name=[entity_parent_folders[-1]],
fields=["_id", "data.root_of"]
asset_names=[entity_parent_folders[-1]],
fields=["_id", "data.root_of"],
)
# NOTE: Not sure why it's checking for entity type?
# OP3 does not support multiple assets with same names so type
Expand Down Expand Up @@ -219,7 +225,7 @@ def update_op_assets(

# Get parent entity
parent_entity = parent_doc["data"]["zou"]
parent_zou_id = parent_entity["parent_id"]
parent_zou_id = parent_entity.get("parent_id")

# Set root folders parents
item_data["parents"] = entity_parent_folders + item_data["parents"]
Expand All @@ -236,7 +242,7 @@ def update_op_assets(
"$set": {
"name": item["name"],
"data": item_data,
"parent": asset_doc_ids[item["project_id"]]["_id"],
"parent": project_doc["_id"],
}
},
)
Expand Down Expand Up @@ -327,6 +333,11 @@ def sync_all_projects(login: str, password: str):
def sync_project_from_kitsu(dbcon: AvalonMongoDB, project: dict):
"""Update OP project in DB with Zou data.

`root_of` is meant to sort entities by type for a better readability in
the data tree. It puts all shot like (Shot and Episode and Sequence) and
asset entities under two different root folders or hierarchy, defined in
settings.

Args:
dbcon (AvalonMongoDB): MongoDB connection
project (dict): Project dict got using gazu.
Expand All @@ -341,12 +352,17 @@ def sync_project_from_kitsu(dbcon: AvalonMongoDB, project: dict):

# Get all assets from zou
all_assets = gazu.asset.all_assets_for_project(project)
all_asset_types = gazu.asset.all_asset_types_for_project(project)
all_episodes = gazu.shot.all_episodes_for_project(project)
all_seqs = gazu.shot.all_sequences_for_project(project)
all_shots = gazu.shot.all_shots_for_project(project)
all_entities = [
item
for item in all_assets + all_episodes + all_seqs + all_shots
for item in all_assets
+ all_asset_types
+ all_episodes
+ all_seqs
+ all_shots
if naming_pattern.match(item["name"])
]

Expand Down Expand Up @@ -401,21 +417,20 @@ def sync_project_from_kitsu(dbcon: AvalonMongoDB, project: dict):
"data": {
"root_of": entity_type,
"parents": parent_folders[:i],
"visualParent": direct_parent_doc,
"visualParent": direct_parent_doc.inserted_id
if direct_parent_doc
else None,
"tasks": {},
},
}
)

# Create
to_insert = []
to_insert.extend(
[
create_op_asset(item)
for item in all_entities
if item["id"] not in zou_ids_and_asset_docs.keys()
]
)
to_insert = [
create_op_asset(item)
for item in all_entities
if item["id"] not in zou_ids_and_asset_docs.keys()
]
if to_insert:
# Insert doc in DB
dbcon.insert_many(to_insert)
Expand Down