diff --git a/pype/ftrack/actions/action_create_cust_attrs.py b/pype/ftrack/actions/action_create_cust_attrs.py index 20db205c62..5279a95a20 100644 --- a/pype/ftrack/actions/action_create_cust_attrs.py +++ b/pype/ftrack/actions/action_create_cust_attrs.py @@ -6,7 +6,7 @@ import arrow import logging import ftrack_api from pype.ftrack import BaseAction -from pype.ftrack.lib.avalon_sync import cust_attr_id_key +from pype.ftrack.lib.avalon_sync import CustAttrIdKey from pypeapp import config from ftrack_api.exception import NoResultFoundError @@ -207,7 +207,7 @@ class CustomAttributes(BaseAction): group = self.get_group('avalon') data = {} - data['key'] = cust_attr_id_key + data['key'] = CustAttrIdKey data['label'] = cust_attr_label data['type'] = custom_attribute_type data['default'] = '' diff --git a/pype/ftrack/actions/action_prepare_project.py b/pype/ftrack/actions/action_prepare_project.py index 10d05151ff..4cc6cfd8df 100644 --- a/pype/ftrack/actions/action_prepare_project.py +++ b/pype/ftrack/actions/action_prepare_project.py @@ -2,13 +2,10 @@ import os import json from ruamel import yaml -import ftrack_api from pype.ftrack import BaseAction from pypeapp import config from pype.ftrack.lib.avalon_sync import get_avalon_attr -from ftrack_api import session as fa_session - class PrepareProject(BaseAction): '''Edit meta data action.''' diff --git a/pype/ftrack/events/event_del_avalon_id_from_new.py b/pype/ftrack/events/event_del_avalon_id_from_new.py index 2278c83685..d820e40467 100644 --- a/pype/ftrack/events/event_del_avalon_id_from_new.py +++ b/pype/ftrack/events/event_del_avalon_id_from_new.py @@ -1,4 +1,5 @@ -from pype.ftrack.lib import avalon_sync, BaseEvent +from pype.ftrack.lib import BaseEvent +from pype.ftrack.lib.avalon_sync import CustAttrIdKey from pype.ftrack.events.event_sync_to_avalon import SyncToAvalonEvent @@ -28,7 +29,7 @@ class DelAvalonIdFromNew(BaseEvent): elif ( entity.get('action', None) == 'update' and - avalon_sync.cust_attr_id_key in entity['keys'] and + CustAttrIdKey in entity['keys'] and entity_id in created ): ftrack_entity = session.get( @@ -37,13 +38,11 @@ class DelAvalonIdFromNew(BaseEvent): ) cust_attr = ftrack_entity['custom_attributes'][ - avalon_sync.cust_attr_id_key + CustAttrIdKey ] if cust_attr != '': - ftrack_entity['custom_attributes'][ - avalon_sync.cust_attr_id_key - ] = '' + ftrack_entity['custom_attributes'][CustAttrIdKey] = '' session.commit() except Exception: @@ -53,5 +52,4 @@ class DelAvalonIdFromNew(BaseEvent): def register(session, plugins_presets): '''Register plugin. Called when used as an plugin.''' - DelAvalonIdFromNew(session, plugins_presets).register() diff --git a/pype/ftrack/events/event_sync_all_auto_sync.py b/pype/ftrack/events/event_sync_all_auto_sync.py index ec30ac3292..cb78027483 100644 --- a/pype/ftrack/events/event_sync_all_auto_sync.py +++ b/pype/ftrack/events/event_sync_all_auto_sync.py @@ -3,10 +3,12 @@ from pype.ftrack import BaseEvent class SyncAllAutoSyncProjects(BaseEvent): ignore_me = True + """Trigger sychronization of each project where auto sync is set.""" + def register(self): - '''Registers the event, subscribing the discover and launch topics.''' + """Registers the event, subscribing the discover and launch topics.""" self.session.event_hub.subscribe( - 'topic=pype.storer.started', + "topic=pype.storer.started", self.launch ) diff --git a/pype/ftrack/events/event_sync_to_avalon.py b/pype/ftrack/events/event_sync_to_avalon.py index f0a7a294c5..31387b5934 100644 --- a/pype/ftrack/events/event_sync_to_avalon.py +++ b/pype/ftrack/events/event_sync_to_avalon.py @@ -12,7 +12,7 @@ from avalon import schema from pype.ftrack.lib import avalon_sync from pype.ftrack.lib.avalon_sync import ( - cust_attr_id_key, cust_attr_auto_sync, entity_schemas + CustAttrIdKey, CustAttrAutoSync, EntitySchemas ) import ftrack_api from ftrack_api import session as fa_session @@ -515,10 +515,10 @@ class SyncToAvalonEvent(BaseEvent): continue changes = ent_info["changes"] - if cust_attr_auto_sync not in changes: + if CustAttrAutoSync not in changes: continue - auto_sync = changes[cust_attr_auto_sync]["new"] + auto_sync = changes[CustAttrAutoSync]["new"] if auto_sync == "1": # Trigger sync to avalon action if auto sync was turned on ft_project = self.cur_project @@ -552,17 +552,17 @@ class SyncToAvalonEvent(BaseEvent): ft_project = self.cur_project # Check if auto-sync custom attribute exists - if cust_attr_auto_sync not in ft_project["custom_attributes"]: + if CustAttrAutoSync not in ft_project["custom_attributes"]: # TODO should we sent message to someone? # TODO report self.log.error(( "Custom attribute \"{}\" is not created or user \"{}\" used" " for Event server don't have permissions to access it!" - ).format(cust_attr_auto_sync, self.session.api_user)) + ).format(CustAttrAutoSync, self.session.api_user)) return True # Skip if auto-sync is not set - auto_sync = ft_project["custom_attributes"][cust_attr_auto_sync] + auto_sync = ft_project["custom_attributes"][CustAttrAutoSync] if auto_sync is not True: self.log.debug("Auto sync is not turned on") return True @@ -746,7 +746,7 @@ class SyncToAvalonEvent(BaseEvent): new_entity["custom_attributes"][key] = val - new_entity["custom_attributes"][cust_attr_id_key] = ( + new_entity["custom_attributes"][CustAttrIdKey] = ( str(avalon_entity["_id"]) ) try: @@ -951,7 +951,7 @@ class SyncToAvalonEvent(BaseEvent): "_id": mongo_id, "name": name, "type": "asset", - "schema": entity_schemas["asset"], + "schema": EntitySchemas["asset"], "parent": proj["_id"], "data": { "ftrackId": ftrack_ent["id"], @@ -993,7 +993,7 @@ class SyncToAvalonEvent(BaseEvent): if not replaced: self.dbcon.insert_one(final_entity) - ftrack_ent["custom_attributes"][cust_attr_id_key] = str(mongo_id) + ftrack_ent["custom_attributes"][CustAttrIdKey] = str(mongo_id) try: self.process_session.commit() except Exception: @@ -1259,7 +1259,7 @@ class SyncToAvalonEvent(BaseEvent): configuration_id = None for attr in cust_attrs: key = attr["key"] - if key == cust_attr_id_key: + if key == CustAttrIdKey: configuration_id = attr["id"] break diff --git a/pype/ftrack/events/event_thumbnail_updates.py b/pype/ftrack/events/event_thumbnail_updates.py index 47909da055..d323fa2dbb 100644 --- a/pype/ftrack/events/event_thumbnail_updates.py +++ b/pype/ftrack/events/event_thumbnail_updates.py @@ -1,4 +1,3 @@ -import ftrack_api from pype.ftrack import BaseEvent diff --git a/pype/ftrack/events/event_user_assigment.py b/pype/ftrack/events/event_user_assigment.py index 8654d19261..87994d34b2 100644 --- a/pype/ftrack/events/event_user_assigment.py +++ b/pype/ftrack/events/event_user_assigment.py @@ -1,13 +1,15 @@ -import ftrack_api -from pype.ftrack import BaseEvent -from pype.ftrack.lib import avalon_sync -from pype.ftrack.lib.io_nonsingleton import DbConnector -from bson.objectid import ObjectId -from pypeapp import config -from pypeapp import Anatomy -import subprocess import os import re +import subprocess + +from pype.ftrack import BaseEvent +from pype.ftrack.lib.avalon_sync import CustAttrIdKey +from pype.ftrack.lib.io_nonsingleton import DbConnector + +from bson.objectid import ObjectId + +from pypeapp import config +from pypeapp import Anatomy class UserAssigmentEvent(BaseEvent): @@ -37,7 +39,6 @@ class UserAssigmentEvent(BaseEvent): """ db_con = DbConnector() - ca_mongoid = avalon_sync.cust_attr_id_key def error(self, *err): for e in err: @@ -106,7 +107,7 @@ class UserAssigmentEvent(BaseEvent): self.db_con.Session['AVALON_PROJECT'] = task['project']['full_name'] avalon_entity = None - parent_id = parent['custom_attributes'].get(self.ca_mongoid) + parent_id = parent['custom_attributes'].get(CustAttrIdKey) if parent_id: parent_id = ObjectId(parent_id) avalon_entity = self.db_con.find_one({ diff --git a/pype/ftrack/lib/avalon_sync.py b/pype/ftrack/lib/avalon_sync.py index ae9dfe8648..88013a55b4 100644 --- a/pype/ftrack/lib/avalon_sync.py +++ b/pype/ftrack/lib/avalon_sync.py @@ -20,15 +20,15 @@ log = Logger().get_logger(__name__) # Current schemas for avalon types -entity_schemas = { +EntitySchemas = { "project": "avalon-core:project-2.0", "asset": "avalon-core:asset-3.0", "config": "avalon-core:config-1.0" } # name of Custom attribute that stores mongo_id from avalon db -cust_attr_id_key = "avalon_mongo_id" -cust_attr_auto_sync = "avalon_auto_sync" +CustAttrIdKey = "avalon_mongo_id" +CustAttrAutoSync = "avalon_auto_sync" def check_regex(name, entity_type, in_schema=None, schema_patterns=None):