renamed custom attributes contatnts and get_avalon_attrs to get_pype_attrs

This commit is contained in:
iLLiCiTiT 2020-07-10 17:20:53 +02:00
parent fff3c15da0
commit 8edba507b3
8 changed files with 54 additions and 52 deletions

View file

@ -1,7 +1,7 @@
import collections
import ftrack_api
from pype.modules.ftrack.lib import BaseAction, statics_icon
from pype.modules.ftrack.lib.avalon_sync import get_avalon_attr
from pype.modules.ftrack.lib.avalon_sync import get_pype_attr
class CleanHierarchicalAttrsAction(BaseAction):
@ -48,7 +48,7 @@ class CleanHierarchicalAttrsAction(BaseAction):
)
entity_ids_joined = ", ".join(all_entities_ids)
attrs, hier_attrs = get_avalon_attr(session)
attrs, hier_attrs = get_pype_attr(session)
for attr in hier_attrs:
configuration_key = attr["key"]

View file

@ -11,7 +11,7 @@ from avalon.vendor import filelink
from pype.api import Anatomy
from pype.modules.ftrack.lib import BaseAction, statics_icon
from pype.modules.ftrack.lib.avalon_sync import CustAttrIdKey
from pype.modules.ftrack.lib.avalon_sync import CUST_ATTR_ID_KEY
from pype.modules.ftrack.lib.io_nonsingleton import DbConnector
@ -243,7 +243,7 @@ class Delivery(BaseAction):
version = entity["version"]
parent = asset["parent"]
parent_mongo_id = parent["custom_attributes"].get(CustAttrIdKey)
parent_mongo_id = parent["custom_attributes"].get(CUST_ATTR_ID_KEY)
if parent_mongo_id:
parent_mongo_id = ObjectId(parent_mongo_id)
else:

View file

@ -3,7 +3,7 @@ import json
from pype.modules.ftrack.lib import BaseAction, statics_icon
from pype.api import config, Anatomy, project_overrides_dir_path
from pype.modules.ftrack.lib.avalon_sync import get_avalon_attr
from pype.modules.ftrack.lib.avalon_sync import get_pype_attr
class PrepareProject(BaseAction):
@ -221,7 +221,7 @@ class PrepareProject(BaseAction):
def _attributes_to_set(self, project_defaults):
attributes_to_set = {}
cust_attrs, hier_cust_attrs = get_avalon_attr(self.session, True)
cust_attrs, hier_cust_attrs = get_pype_attr(self.session, True)
for attr in hier_cust_attrs:
key = attr["key"]

View file

@ -8,7 +8,7 @@ from pype.modules.ftrack.lib import BaseAction, statics_icon
from pype.api import Anatomy
from pype.modules.ftrack.lib.io_nonsingleton import DbConnector
from pype.modules.ftrack.lib.avalon_sync import CustAttrIdKey
from pype.modules.ftrack.lib.avalon_sync import CUST_ATTR_ID_KEY
class StoreThumbnailsToAvalon(BaseAction):
@ -390,7 +390,7 @@ class StoreThumbnailsToAvalon(BaseAction):
return output
asset_ent = None
asset_mongo_id = parent["custom_attributes"].get(CustAttrIdKey)
asset_mongo_id = parent["custom_attributes"].get(CUST_ATTR_ID_KEY)
if asset_mongo_id:
try:
asset_mongo_id = ObjectId(asset_mongo_id)

View file

@ -1,5 +1,5 @@
from pype.modules.ftrack.lib import BaseEvent
from pype.modules.ftrack.lib.avalon_sync import CustAttrIdKey
from pype.modules.ftrack.lib.avalon_sync import CUST_ATTR_ID_KEY
from pype.modules.ftrack.events.event_sync_to_avalon import SyncToAvalonEvent
@ -29,7 +29,7 @@ class DelAvalonIdFromNew(BaseEvent):
elif (
entity.get('action', None) == 'update' and
CustAttrIdKey in entity['keys'] and
CUST_ATTR_ID_KEY in entity['keys'] and
entity_id in created
):
ftrack_entity = session.get(
@ -38,11 +38,11 @@ class DelAvalonIdFromNew(BaseEvent):
)
cust_attr = ftrack_entity['custom_attributes'][
CustAttrIdKey
CUST_ATTR_ID_KEY
]
if cust_attr != '':
ftrack_entity['custom_attributes'][CustAttrIdKey] = ''
ftrack_entity['custom_attributes'][CUST_ATTR_ID_KEY] = ''
session.commit()
except Exception:

View file

@ -14,7 +14,7 @@ from avalon import schema
from pype.modules.ftrack.lib import avalon_sync
from pype.modules.ftrack.lib.avalon_sync import (
CustAttrIdKey, CustAttrAutoSync, EntitySchemas
CUST_ATTR_ID_KEY, CUST_ATTR_AUTO_SYNC, EntitySchemas
)
import ftrack_api
from pype.modules.ftrack import BaseEvent
@ -103,7 +103,7 @@ class SyncToAvalonEvent(BaseEvent):
@property
def avalon_cust_attrs(self):
if self._avalon_cust_attrs is None:
self._avalon_cust_attrs = avalon_sync.get_avalon_attr(
self._avalon_cust_attrs = avalon_sync.get_pype_attr(
self.process_session
)
return self._avalon_cust_attrs
@ -220,7 +220,7 @@ class SyncToAvalonEvent(BaseEvent):
def avalon_custom_attributes(self):
"""Return info about changeability of entity and it's parents."""
if self._avalon_custom_attributes is None:
self._avalon_custom_attributes = avalon_sync.get_avalon_attr(
self._avalon_custom_attributes = avalon_sync.get_pype_attr(
self.process_session
)
return self._avalon_custom_attributes
@ -557,10 +557,10 @@ class SyncToAvalonEvent(BaseEvent):
continue
changes = ent_info["changes"]
if CustAttrAutoSync not in changes:
if CUST_ATTR_AUTO_SYNC not in changes:
continue
auto_sync = changes[CustAttrAutoSync]["new"]
auto_sync = changes[CUST_ATTR_AUTO_SYNC]["new"]
if auto_sync == "1":
# Trigger sync to avalon action if auto sync was turned on
ft_project = self.cur_project
@ -593,16 +593,16 @@ class SyncToAvalonEvent(BaseEvent):
ft_project = self.cur_project
# Check if auto-sync custom attribute exists
if CustAttrAutoSync not in ft_project["custom_attributes"]:
if CUST_ATTR_AUTO_SYNC not in ft_project["custom_attributes"]:
# TODO should we sent message to someone?
self.log.error((
"Custom attribute \"{}\" is not created or user \"{}\" used"
" for Event server don't have permissions to access it!"
).format(CustAttrAutoSync, self.session.api_user))
).format(CUST_ATTR_AUTO_SYNC, self.session.api_user))
return True
# Skip if auto-sync is not set
auto_sync = ft_project["custom_attributes"][CustAttrAutoSync]
auto_sync = ft_project["custom_attributes"][CUST_ATTR_AUTO_SYNC]
if auto_sync is not True:
return True
@ -844,7 +844,7 @@ class SyncToAvalonEvent(BaseEvent):
new_entity["custom_attributes"][key] = val
new_entity["custom_attributes"][CustAttrIdKey] = (
new_entity["custom_attributes"][CUST_ATTR_ID_KEY] = (
str(avalon_entity["_id"])
)
ent_path = self.get_ent_path(new_entity_id)
@ -1097,7 +1097,7 @@ class SyncToAvalonEvent(BaseEvent):
continue
final_entity["data"][key] = val
_mongo_id_str = cust_attrs.get(CustAttrIdKey)
_mongo_id_str = cust_attrs.get(CUST_ATTR_ID_KEY)
if _mongo_id_str:
try:
_mongo_id = ObjectId(_mongo_id_str)
@ -1158,8 +1158,8 @@ class SyncToAvalonEvent(BaseEvent):
self.log.debug("Entity was synchronized <{}>".format(ent_path))
mongo_id_str = str(mongo_id)
if mongo_id_str != ftrack_ent["custom_attributes"][CustAttrIdKey]:
ftrack_ent["custom_attributes"][CustAttrIdKey] = mongo_id_str
if mongo_id_str != ftrack_ent["custom_attributes"][CUST_ATTR_ID_KEY]:
ftrack_ent["custom_attributes"][CUST_ATTR_ID_KEY] = mongo_id_str
try:
self.process_session.commit()
except Exception:
@ -1247,7 +1247,7 @@ class SyncToAvalonEvent(BaseEvent):
self.process_session, entity, hier_keys, defaults
)
for key, val in hier_values.items():
if key == CustAttrIdKey:
if key == CUST_ATTR_ID_KEY:
continue
output[key] = val
@ -1689,7 +1689,7 @@ class SyncToAvalonEvent(BaseEvent):
if "_hierarchical" not in temp_dict:
hier_mongo_id_configuration_id = None
for attr in hier_attrs:
if attr["key"] == CustAttrIdKey:
if attr["key"] == CUST_ATTR_ID_KEY:
hier_mongo_id_configuration_id = attr["id"]
break
temp_dict["_hierarchical"] = hier_mongo_id_configuration_id
@ -1706,7 +1706,7 @@ class SyncToAvalonEvent(BaseEvent):
for attr in cust_attrs:
key = attr["key"]
if key != CustAttrIdKey:
if key != CUST_ATTR_ID_KEY:
continue
if attr["entity_type"] != ent_info["entityType"]:

View file

@ -3,7 +3,7 @@ import re
import subprocess
from pype.modules.ftrack import BaseEvent
from pype.modules.ftrack.lib.avalon_sync import CustAttrIdKey
from pype.modules.ftrack.lib.avalon_sync import CUST_ATTR_ID_KEY
from pype.modules.ftrack.lib.io_nonsingleton import DbConnector
from bson.objectid import ObjectId
@ -106,7 +106,7 @@ class UserAssigmentEvent(BaseEvent):
self.db_con.Session['AVALON_PROJECT'] = task['project']['full_name']
avalon_entity = None
parent_id = parent['custom_attributes'].get(CustAttrIdKey)
parent_id = parent['custom_attributes'].get(CUST_ATTR_ID_KEY)
if parent_id:
parent_id = ObjectId(parent_id)
avalon_entity = self.db_con.find_one({

View file

@ -32,8 +32,10 @@ EntitySchemas = {
CUST_ATTR_GROUP = "pype"
# name of Custom attribute that stores mongo_id from avalon db
CustAttrIdKey = "avalon_mongo_id"
CustAttrAutoSync = "avalon_auto_sync"
CUST_ATTR_ID_KEY = "avalon_mongo_id"
CUST_ATTR_AUTO_SYNC = "avalon_auto_sync"
def default_custom_attributes_definition():
json_file_path = os.path.join(
os.path.dirname(__file__), "custom_attributes.json"
@ -76,14 +78,14 @@ def check_regex(name, entity_type, in_schema=None, schema_patterns=None):
return False
def get_avalon_attr(session, split_hierarchical=True):
def get_pype_attr(session, split_hierarchical=True):
custom_attributes = []
hier_custom_attributes = []
cust_attrs_query = (
"select id, entity_type, object_type_id, is_hierarchical, default"
" from CustomAttributeConfiguration"
" where group.name = \"avalon\""
)
" where group.name = \"{}\""
).format(CUST_ATTR_GROUP)
all_avalon_attr = session.query(cust_attrs_query).all()
for cust_attr in all_avalon_attr:
if split_hierarchical and cust_attr["is_hierarchical"]:
@ -334,12 +336,12 @@ class SyncEntitiesFactory:
"*** Synchronization initialization started <{}>."
).format(project_full_name))
# Check if `avalon_mongo_id` custom attribute exist or is accessible
if CustAttrIdKey not in ft_project["custom_attributes"]:
if CUST_ATTR_ID_KEY not in ft_project["custom_attributes"]:
items = []
items.append({
"type": "label",
"value": "# Can't access Custom attribute <{}>".format(
CustAttrIdKey
CUST_ATTR_ID_KEY
)
})
items.append({
@ -699,7 +701,7 @@ class SyncEntitiesFactory:
def set_cutom_attributes(self):
self.log.debug("* Preparing custom attributes")
# Get custom attributes and values
custom_attrs, hier_attrs = get_avalon_attr(self.session)
custom_attrs, hier_attrs = get_pype_attr(self.session)
ent_types = self.session.query("select id, name from ObjectType").all()
ent_types_by_name = {
ent_type["name"]: ent_type["id"] for ent_type in ent_types
@ -916,7 +918,7 @@ class SyncEntitiesFactory:
project_values[key] = value
for key in avalon_hier:
if key == CustAttrIdKey:
if key == CUST_ATTR_ID_KEY:
continue
value = self.entities_dict[top_id]["avalon_attrs"][key]
if value is not None:
@ -1070,7 +1072,7 @@ class SyncEntitiesFactory:
same_mongo_id = []
all_mongo_ids = {}
for ftrack_id, entity_dict in self.entities_dict.items():
mongo_id = entity_dict["avalon_attrs"].get(CustAttrIdKey)
mongo_id = entity_dict["avalon_attrs"].get(CUST_ATTR_ID_KEY)
if not mongo_id:
continue
if mongo_id in all_mongo_ids:
@ -1101,7 +1103,7 @@ class SyncEntitiesFactory:
entity_dict = self.entities_dict[ftrack_id]
ent_path = self.get_ent_path(ftrack_id)
mongo_id = entity_dict["avalon_attrs"].get(CustAttrIdKey)
mongo_id = entity_dict["avalon_attrs"].get(CUST_ATTR_ID_KEY)
av_ent_by_mongo_id = self.avalon_ents_by_id.get(mongo_id)
if av_ent_by_mongo_id:
av_ent_ftrack_id = av_ent_by_mongo_id.get("data", {}).get(
@ -1122,7 +1124,7 @@ class SyncEntitiesFactory:
continue
_entity_dict = self.entities_dict[_ftrack_id]
_mongo_id = _entity_dict["avalon_attrs"][CustAttrIdKey]
_mongo_id = _entity_dict["avalon_attrs"][CUST_ATTR_ID_KEY]
_av_ent_by_mongo_id = self.avalon_ents_by_id.get(
_mongo_id
)
@ -1515,11 +1517,11 @@ class SyncEntitiesFactory:
avalon_attrs = self.entities_dict[ftrack_id]["avalon_attrs"]
if (
CustAttrIdKey not in avalon_attrs or
avalon_attrs[CustAttrIdKey] != avalon_id
CUST_ATTR_ID_KEY not in avalon_attrs or
avalon_attrs[CUST_ATTR_ID_KEY] != avalon_id
):
configuration_id = self.entities_dict[ftrack_id][
"avalon_attrs_id"][CustAttrIdKey]
"avalon_attrs_id"][CUST_ATTR_ID_KEY]
_entity_key = collections.OrderedDict({
"configuration_id": configuration_id,
@ -1599,7 +1601,7 @@ class SyncEntitiesFactory:
# avalon_archived_by_id avalon_archived_by_name
current_id = (
entity_dict["avalon_attrs"].get(CustAttrIdKey) or ""
entity_dict["avalon_attrs"].get(CUST_ATTR_ID_KEY) or ""
).strip()
mongo_id = current_id
name = entity_dict["name"]
@ -1635,14 +1637,14 @@ class SyncEntitiesFactory:
if current_id != new_id_str:
# store mongo id to ftrack entity
configuration_id = self.hier_cust_attr_ids_by_key.get(
CustAttrIdKey
CUST_ATTR_ID_KEY
)
if not configuration_id:
# NOTE this is for cases when CustAttrIdKey key is not
# NOTE this is for cases when CUST_ATTR_ID_KEY key is not
# hierarchical custom attribute but per entity type
configuration_id = self.entities_dict[ftrack_id][
"avalon_attrs_id"
][CustAttrIdKey]
][CUST_ATTR_ID_KEY]
_entity_key = collections.OrderedDict({
"configuration_id": configuration_id,
@ -1751,7 +1753,7 @@ class SyncEntitiesFactory:
project_item = self.entities_dict[self.ft_project_id]["final_entity"]
mongo_id = (
self.entities_dict[self.ft_project_id]["avalon_attrs"].get(
CustAttrIdKey
CUST_ATTR_ID_KEY
) or ""
).strip()
@ -1782,7 +1784,7 @@ class SyncEntitiesFactory:
# store mongo id to ftrack entity
entity = self.entities_dict[self.ft_project_id]["entity"]
entity["custom_attributes"][CustAttrIdKey] = str(new_id)
entity["custom_attributes"][CUST_ATTR_ID_KEY] = str(new_id)
def _bubble_changeability(self, unchangeable_ids):
unchangeable_queue = queue.Queue()
@ -2163,7 +2165,7 @@ class SyncEntitiesFactory:
if new_entity_id not in p_chilren:
self.entities_dict[parent_id]["children"].append(new_entity_id)
cust_attr, hier_attrs = get_avalon_attr(self.session)
cust_attr, hier_attrs = get_pype_attr(self.session)
for _attr in cust_attr:
key = _attr["key"]
if key not in av_entity["data"]:
@ -2179,7 +2181,7 @@ class SyncEntitiesFactory:
new_entity["custom_attributes"][key] = value
av_entity_id = str(av_entity["_id"])
new_entity["custom_attributes"][CustAttrIdKey] = av_entity_id
new_entity["custom_attributes"][CUST_ATTR_ID_KEY] = av_entity_id
self.ftrack_avalon_mapper[new_entity_id] = av_entity_id
self.avalon_ftrack_mapper[av_entity_id] = new_entity_id