mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Change: Asset is put under an AssetType folder
This commit is contained in:
parent
c210c93b32
commit
5939588317
1 changed files with 37 additions and 23 deletions
|
|
@ -14,7 +14,7 @@ from openpype.client import (
|
||||||
get_project,
|
get_project,
|
||||||
get_assets,
|
get_assets,
|
||||||
get_asset_by_id,
|
get_asset_by_id,
|
||||||
get_asset_by_name
|
get_asset_by_name,
|
||||||
)
|
)
|
||||||
from openpype.pipeline import AvalonMongoDB
|
from openpype.pipeline import AvalonMongoDB
|
||||||
from openpype.api import get_project_settings
|
from openpype.api import get_project_settings
|
||||||
|
|
@ -154,17 +154,23 @@ def update_op_assets(
|
||||||
parent_zou_id = substitute_parent_item["parent_id"]
|
parent_zou_id = substitute_parent_item["parent_id"]
|
||||||
else:
|
else:
|
||||||
parent_zou_id = (
|
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("episode_id")
|
||||||
or item.get("source_id")
|
or item.get("source_id")
|
||||||
) # TODO check consistency
|
)
|
||||||
|
|
||||||
# Substitute Episode and Sequence by Shot
|
# Substitute item type for general classification (assets or shots)
|
||||||
substitute_item_type = (
|
if item_type in ["Asset", "AssetType"]:
|
||||||
"shots"
|
substitute_item_type = "assets"
|
||||||
if item_type in ["Episode", "Sequence"]
|
elif item_type in ["Episode", "Sequence"]:
|
||||||
else f"{item_type.lower()}s"
|
substitute_item_type = "shots"
|
||||||
)
|
else:
|
||||||
|
substitute_item_type = f"{item_type.lower()}s"
|
||||||
entity_parent_folders = [
|
entity_parent_folders = [
|
||||||
f
|
f
|
||||||
for f in project_module_settings["entities_root"]
|
for f in project_module_settings["entities_root"]
|
||||||
|
|
@ -181,8 +187,8 @@ def update_op_assets(
|
||||||
# Find root folder docs
|
# Find root folder docs
|
||||||
root_folder_docs = get_assets(
|
root_folder_docs = get_assets(
|
||||||
project_name,
|
project_name,
|
||||||
asset_name=[entity_parent_folders[-1]],
|
asset_names=[entity_parent_folders[-1]],
|
||||||
fields=["_id", "data.root_of"]
|
fields=["_id", "data.root_of"],
|
||||||
)
|
)
|
||||||
# NOTE: Not sure why it's checking for entity type?
|
# NOTE: Not sure why it's checking for entity type?
|
||||||
# OP3 does not support multiple assets with same names so type
|
# OP3 does not support multiple assets with same names so type
|
||||||
|
|
@ -219,7 +225,7 @@ def update_op_assets(
|
||||||
|
|
||||||
# Get parent entity
|
# Get parent entity
|
||||||
parent_entity = parent_doc["data"]["zou"]
|
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
|
# Set root folders parents
|
||||||
item_data["parents"] = entity_parent_folders + item_data["parents"]
|
item_data["parents"] = entity_parent_folders + item_data["parents"]
|
||||||
|
|
@ -236,7 +242,7 @@ def update_op_assets(
|
||||||
"$set": {
|
"$set": {
|
||||||
"name": item["name"],
|
"name": item["name"],
|
||||||
"data": item_data,
|
"data": item_data,
|
||||||
"parent": asset_doc_ids[item["project_id"]]["_id"],
|
"parent": project_doc["_id"],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -327,6 +333,10 @@ def sync_all_projects(login: str, password: str):
|
||||||
def sync_project_from_kitsu(dbcon: AvalonMongoDB, project: dict):
|
def sync_project_from_kitsu(dbcon: AvalonMongoDB, project: dict):
|
||||||
"""Update OP project in DB with Zou data.
|
"""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:
|
Args:
|
||||||
dbcon (AvalonMongoDB): MongoDB connection
|
dbcon (AvalonMongoDB): MongoDB connection
|
||||||
project (dict): Project dict got using gazu.
|
project (dict): Project dict got using gazu.
|
||||||
|
|
@ -341,12 +351,17 @@ def sync_project_from_kitsu(dbcon: AvalonMongoDB, project: dict):
|
||||||
|
|
||||||
# Get all assets from zou
|
# Get all assets from zou
|
||||||
all_assets = gazu.asset.all_assets_for_project(project)
|
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_episodes = gazu.shot.all_episodes_for_project(project)
|
||||||
all_seqs = gazu.shot.all_sequences_for_project(project)
|
all_seqs = gazu.shot.all_sequences_for_project(project)
|
||||||
all_shots = gazu.shot.all_shots_for_project(project)
|
all_shots = gazu.shot.all_shots_for_project(project)
|
||||||
all_entities = [
|
all_entities = [
|
||||||
item
|
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"])
|
if naming_pattern.match(item["name"])
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -401,21 +416,20 @@ def sync_project_from_kitsu(dbcon: AvalonMongoDB, project: dict):
|
||||||
"data": {
|
"data": {
|
||||||
"root_of": entity_type,
|
"root_of": entity_type,
|
||||||
"parents": parent_folders[:i],
|
"parents": parent_folders[:i],
|
||||||
"visualParent": direct_parent_doc,
|
"visualParent": direct_parent_doc.inserted_id
|
||||||
|
if direct_parent_doc
|
||||||
|
else None,
|
||||||
"tasks": {},
|
"tasks": {},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create
|
# Create
|
||||||
to_insert = []
|
to_insert = [
|
||||||
to_insert.extend(
|
create_op_asset(item)
|
||||||
[
|
for item in all_entities
|
||||||
create_op_asset(item)
|
if item["id"] not in zou_ids_and_asset_docs.keys()
|
||||||
for item in all_entities
|
]
|
||||||
if item["id"] not in zou_ids_and_asset_docs.keys()
|
|
||||||
]
|
|
||||||
)
|
|
||||||
if to_insert:
|
if to_insert:
|
||||||
# Insert doc in DB
|
# Insert doc in DB
|
||||||
dbcon.insert_many(to_insert)
|
dbcon.insert_many(to_insert)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue