Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequence and shot folder grouping #129

Open
wants to merge 53 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
9f73b18
Added creation of separate sequence category
kalisp Sep 5, 2024
ac4e85e
Added shot subfolder
kalisp Sep 5, 2024
8907ec6
Refactored similar code
kalisp Sep 6, 2024
2c1682f
Added new folder types
kalisp Sep 6, 2024
c12dc8a
Use new folder types for shot, sequence folders
kalisp Sep 6, 2024
9ee2c8c
Skip non integer id
kalisp Sep 6, 2024
bda159a
Skip non integer id
kalisp Sep 6, 2024
df445bf
Handles special folders when creating entity in SG
kalisp Sep 6, 2024
9483b83
Use only real parents, not grouping folders like shot
kalisp Sep 6, 2024
0523d58
Handles creation of shot/sequence only from events
kalisp Sep 6, 2024
7fc70a7
Removed storing unnecessary sg_id
kalisp Sep 6, 2024
3b97998
Special folders are configured in Settings
kalisp Sep 9, 2024
e02228a
Added configuration for special folder prefixes
kalisp Sep 9, 2024
5ae2744
Revert unwanted changes
kalisp Sep 12, 2024
5037cb7
Merge develop
kalisp Nov 12, 2024
803fabc
Merge branch 'develop' into enhancement/AY-6666_Shotgrid-sequence-and…
jakubjezek001 Nov 14, 2024
16b728f
Add folder types enum and implement default ShotGrid reparenting enti…
jakubjezek001 Nov 14, 2024
a2c56b2
removing settings
jakubjezek001 Nov 14, 2024
eee98f3
Refactor folder path retrieval for asset, sequence, and shot categories
jakubjezek001 Nov 14, 2024
25fabe0
Merge develop
kalisp Nov 14, 2024
39e880e
Do not put shots in sequence to different folder type
kalisp Nov 14, 2024
0edc903
Removed unnecessary code
kalisp Nov 14, 2024
ea292b1
Added docstring
kalisp Nov 14, 2024
a48dddd
Merge
kalisp Nov 14, 2024
dc1196a
Fix import
kalisp Nov 14, 2024
ec7608a
Remove AssetCategory, update folder naming conventions, and add re-pa…
jakubjezek001 Nov 15, 2024
ca031c5
Merge remote-tracking branch 'origin/enhancement/AY-6666_Shotgrid-seq…
kalisp Nov 18, 2024
e97919d
Fix use project setting
kalisp Nov 18, 2024
e697216
Implemented type_grouping use case
kalisp Nov 19, 2024
986e646
Fix access to local variable
kalisp Nov 20, 2024
dbb0f16
Fix non parented entities
kalisp Nov 20, 2024
59feada
Fix cases where no parent found
kalisp Nov 20, 2024
b08ed55
Introduced parenting transfer workflows
kalisp Nov 20, 2024
7f17ded
Renamed placeholder value
kalisp Nov 20, 2024
c1a2e93
Implemented pulling name from AssetCategory as folder name
kalisp Nov 20, 2024
5e263df
Fixes for parent transfer
kalisp Nov 20, 2024
e7865c8
Added parent sequence info to shot sg_ay_dict
kalisp Nov 20, 2024
0c690cc
Fix missing Task entities
kalisp Nov 20, 2024
15eb5a0
Extracted _sync_project_attributes
kalisp Nov 21, 2024
af1ad65
Extracted _update_sg_entity
kalisp Nov 21, 2024
f3ad1c5
Removed parent_entity
kalisp Nov 21, 2024
8b3c017
Added note
kalisp Nov 21, 2024
8120182
Fix wrong parents for Tasks
kalisp Nov 21, 2024
f802f26
Removed unnecessary ShotCategory, SequenceCategory
kalisp Nov 21, 2024
e29611f
Fix missing data on Task entities
kalisp Nov 21, 2024
cbff7e9
Ruff
kalisp Nov 21, 2024
1d77f0e
Fix explicit argument
kalisp Nov 22, 2024
3dd475f
Merge branch 'develop' of https://github.com/ynput/ayon-shotgrid into…
kalisp Nov 25, 2024
c3ad7bb
Removed parent entity from arguments
kalisp Nov 25, 2024
ccc1f1c
Removed parent entity from arguments
kalisp Nov 25, 2024
1814310
Updated logging
kalisp Nov 26, 2024
d89372e
Update data only if exist
kalisp Nov 26, 2024
281a192
Set data directly when create entity
kalisp Nov 26, 2024
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
21 changes: 19 additions & 2 deletions server/settings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ class AttributesMappingModel(BaseSettingsModel):
)


class FolderLocationsModel(BaseSettingsModel):
"""AYON folders to store separate of SG types"""
asset_folder: str = SettingsField(title="Assets", default="assets")
sequence_folder: str = SettingsField(title="Sequences",
default="sequences")
shot_folder: str = SettingsField(title="Shots", default="shots")


class ShotgridCompatibilitySettings(BaseSettingsModel):
""" Settings to define relationships between ShotGrid and AYON.
"""
Expand All @@ -136,6 +144,15 @@ class ShotgridCompatibilitySettings(BaseSettingsModel):
),
)

folder_locations: FolderLocationsModel = SettingsField(
title="Folder locations",
default_factory=FolderLocationsModel,
description=(
"Locations of AYON folders matching to SG types."
"Eg. where SG assets will be stored, where SG shots and sequences."
),
)


class ClientLoginDetailsModel(BaseSettingsModel):
_layout = "expanded"
Expand Down Expand Up @@ -218,13 +235,13 @@ class ShotgridSettings(BaseSettingsModel):
shotgrid_project_code_field: str = SettingsField(
default="code",
title="ShotGrid Project Code field name",
disabled=True,
kalisp marked this conversation as resolved.
Show resolved Hide resolved
description=(
"In order to create AYON projects, we need a Project Code, you "
"can specify here which field in the ShotGrid Project "
"entity represents it."
),
example="sg_code",
scope=["studio"],
example="sg_code"
)
enable_shotgrid_local_storage: bool = SettingsField(
default=True,
Expand Down
4 changes: 3 additions & 1 deletion services/shotgrid_common/ayon_shotgrid_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ def synchronize_projects(self, source="ayon"):
self._sg,
self.sg_enabled_entities,
self.sg_project_code_field,
self.custom_attribs_map
self.custom_attribs_map,
self.settings
)

case _:
Expand Down Expand Up @@ -321,6 +322,7 @@ def react_to_shotgrid_event(self, sg_event_meta):
self.sg_enabled_entities,
self.sg_project_code_field,
self.custom_attribs_map,
self.settings
)

case "attribute_change":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def match_ayon_hierarchy_in_shotgrid(
)
continue
elif sg_entity_id:
# convert sg_entity_id to int if exists
sg_entity_id = int(sg_entity_id)

if sg_entity_type == "AssetCategory":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from utils import (
get_sg_entities,
get_asset_category,
get_sequence_category,
get_shot_category,
update_ay_entity_custom_attributes,
)

Expand All @@ -36,7 +38,8 @@ def match_shotgrid_hierarchy_in_ayon(
sg_session: shotgun_api3.Shotgun,
sg_enabled_entities: List[str],
project_code_field: str,
custom_attribs_map: Dict[str, str]
custom_attribs_map: Dict[str, str],
addon_settings: Dict[str, str]
):
"""Replicate a Shotgrid project into AYON.

Expand Down Expand Up @@ -107,11 +110,31 @@ def match_shotgrid_hierarchy_in_ayon(

# If we couldn't find it we create it.
if ay_entity is None:
if sg_ay_dict["attribs"].get(SHOTGRID_TYPE_ATTRIB) == "AssetCategory": # noqa
parent_is_project = isinstance(ay_parent_entity, ProjectEntity)
kalisp marked this conversation as resolved.
Show resolved Hide resolved

shotgrid_type = sg_ay_dict["attribs"].get(SHOTGRID_TYPE_ATTRIB)
if shotgrid_type == "AssetCategory":
ay_entity = get_asset_category(
entity_hub,
ay_parent_entity,
sg_ay_dict
sg_ay_dict,
addon_settings
)

if shotgrid_type == "Sequence" and parent_is_project:
ay_parent_entity = get_sequence_category(
entity_hub,
ay_parent_entity,
sg_ay_dict,
addon_settings
)

if shotgrid_type == "Shot" and parent_is_project:
ay_parent_entity = get_shot_category(
entity_hub,
ay_parent_entity,
sg_ay_dict,
addon_settings
)

if not ay_entity:
Expand Down
24 changes: 14 additions & 10 deletions services/shotgrid_common/ayon_shotgrid_hub/update_from_ayon.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,19 @@ def _create_sg_entity(
sg_field_name = "code"
sg_step = None

# parent AssetCategory should not be created in Shotgrid
# it is only used for grouping Asset types
special_folder_types =["AssetCategory", "ShotCategory", "SequenceCategory"]
# parent special folder like AssetCategory should not be created in
# Shotgrid it is only used for grouping Asset types
is_parent_project_entity = isinstance(ay_entity.parent, ProjectEntity)
if (
isinstance(ay_entity.parent, ProjectEntity)
and ay_entity.folder_type == "AssetCategory"
is_parent_project_entity
and ay_entity.folder_type in special_folder_types
):
return
elif ay_entity.parent.folder_type == "AssetCategory":
elif (not is_parent_project_entity and
ay_entity.parent.folder_type in special_folder_types):
sg_parent_id = None
sg_parent_type = "AssetCategory"
sg_parent_type = ay_entity.parent.folder_type
else:
sg_parent_id = ay_entity.parent.attribs.get(SHOTGRID_ID_ATTRIB)
sg_parent_type = ay_entity.parent.attribs.get(SHOTGRID_TYPE_ATTRIB)
Expand Down Expand Up @@ -413,13 +416,14 @@ def _create_sg_entity(
else:
data = {
"project": sg_project,
parent_field: {
"type": sg_parent_type,
"id": int(sg_parent_id)
},
sg_field_name: ay_entity.name,
CUST_FIELD_CODE_ID: ay_entity.id,
}
if isinstance(sg_parent_id, int):
data[parent_field] = {
"type": sg_parent_type,
"id": int(sg_parent_id)
}

# Fill up data with any extra attributes from Ayon we want to sync to SG
data.update(get_sg_custom_attributes_data(
Expand Down
52 changes: 41 additions & 11 deletions services/shotgrid_common/ayon_shotgrid_hub/update_from_shotgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

from utils import (
get_asset_category,
get_shot_category,
get_sequence_category,
get_sg_entity_as_ay_dict,
get_sg_entity_parent_field,
update_ay_entity_custom_attributes,
Expand All @@ -54,7 +56,8 @@ def create_ay_entity_from_sg_event(
ayon_entity_hub: ayon_api.entity_hub.EntityHub,
sg_enabled_entities: List[str],
project_code_field: str,
custom_attribs_map: Optional[Dict[str, str]] = None
custom_attribs_map: Optional[Dict[str, str]] = None,
addon_settings: Optional[Dict[str, str]] = None
):
"""Create an AYON entity from a ShotGrid Event.

Expand All @@ -67,6 +70,7 @@ def create_ay_entity_from_sg_event(
project_code_field (str): The Shotgrid project code field.
custom_attribs_map (Optional[dict]): A dictionary that maps ShotGrid
attributes to Ayon attributes.
addon_settings (Optional[dict]): A dictionary of Settings

Returns:
ay_entity (ayon_api.entity_hub.EntityHub.Entity): The newly
Expand All @@ -84,6 +88,9 @@ def create_ay_entity_from_sg_event(
extra_fields.append("sg_asset_type")
sg_parent_field = "sg_asset_type"

if sg_event["entity_type"] == "Shot":
sg_parent_field = "sg_sequence"

sg_ay_dict = get_sg_entity_as_ay_dict(
sg_session,
sg_event["entity_type"],
Expand Down Expand Up @@ -131,29 +138,52 @@ def create_ay_entity_from_sg_event(

return ay_entity

# INFO: Parent entity might not be added in SG so this needs to be handled
# with optional way.
if sg_ay_dict["data"].get(sg_parent_field) is None:
# Parent is the project
log.debug(f"ShotGrid Parent is the Project: {sg_project}")
ay_parent_entity = ayon_entity_hub.project_entity
elif (
sg_ay_dict["attribs"][SHOTGRID_TYPE_ATTRIB] == "Asset"
shotgrid_type = sg_ay_dict["attribs"][SHOTGRID_TYPE_ATTRIB]
sg_parent = sg_ay_dict["data"].get(sg_parent_field)

if (
shotgrid_type == "Asset"
and sg_ay_dict["data"].get("sg_asset_type")
):
log.debug("ShotGrid Parent is an Asset category.")
ay_parent_entity = get_asset_category(
ayon_entity_hub,
ayon_entity_hub.project_entity,
sg_ay_dict,
addon_settings
)

elif(shotgrid_type == "Sequence"):
log.info("ShotGrid Parent is an Sequence category.")
ay_parent_entity = get_sequence_category(
ayon_entity_hub,
ayon_entity_hub.project_entity,
sg_ay_dict,
addon_settings
)

elif(shotgrid_type == "Shot") and not sg_parent:
log.info("ShotGrid Parent is an Shot category.")
ay_parent_entity = get_shot_category(
ayon_entity_hub,
ayon_entity_hub.project_entity,
sg_ay_dict,
addon_settings
)

# INFO: Parent entity might not be added in SG so this needs to be handled
# with optional way.
elif sg_parent is None:
# Parent is the project
log.debug(f"ShotGrid Parent is the Project: {sg_project}")
ay_parent_entity = ayon_entity_hub.project_entity

else:
# Find parent entity ID
sg_parent_entity_dict = get_sg_entity_as_ay_dict(
sg_session,
sg_ay_dict["data"][sg_parent_field]["type"],
sg_ay_dict["data"][sg_parent_field]["id"],
sg_parent["type"],
sg_parent["id"],
project_code_field,
)

Expand Down
Loading