mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 13:52:15 +01:00
Events work but don't show messag eto user
This commit is contained in:
parent
0543d4405a
commit
5aa0edffd4
5 changed files with 96 additions and 72 deletions
|
|
@ -134,31 +134,7 @@ class SyncToAvalon(BaseAction):
|
|||
self.log.info("Name of {} was changed to {}".format(input_name, name))
|
||||
return name
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
def getConfig(self, entity):
|
||||
apps = []
|
||||
for app in entity['custom_attributes']['applications']:
|
||||
try:
|
||||
label = toml.load(lib.which_app(app))['label']
|
||||
apps.append({'name':app, 'label':label})
|
||||
except Exception as e:
|
||||
self.log.error('Error with application {0} - {1}'.format(app, e))
|
||||
|
||||
config = {
|
||||
'schema': 'avalon-core:config-1.0',
|
||||
'tasks': [{'name': ''}],
|
||||
'apps': apps,
|
||||
# TODO redo work!!!
|
||||
'template': {
|
||||
'workfile': '{asset[name]}_{task[name]}_{version:0>3}<_{comment}>',
|
||||
'work': '{root}/{project}/{hierarchy}/{asset}/work/{task}',
|
||||
'publish':'{root}/{project}/{hierarchy}/{asset}/publish/{family}/{subset}/v{version}/{projectcode}_{asset}_{subset}_v{version}.{representation}'}
|
||||
}
|
||||
return config
|
||||
|
||||
|
||||
>>>>>>> develop
|
||||
def importToAvalon(self, session, entity):
|
||||
eLinks = []
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,12 @@ class Sync_to_Avalon(BaseEvent):
|
|||
|
||||
def launch(self, session, entities, event):
|
||||
self.ca_mongoid = 'avalon_mongo_id'
|
||||
for ent in event['data']['entities']:
|
||||
if self.ca_mongoid in ent['keys']:
|
||||
return False
|
||||
self.proj = None
|
||||
self.nameShotAsset = []
|
||||
self.nameChanged = []
|
||||
|
||||
for entity in entities:
|
||||
try:
|
||||
|
|
@ -24,22 +29,28 @@ class Sync_to_Avalon(BaseEvent):
|
|||
break
|
||||
|
||||
if self.proj is None:
|
||||
return
|
||||
return False
|
||||
|
||||
os.environ["AVALON_PROJECT"] = self.proj['full_name']
|
||||
|
||||
proj_id = self.proj['custom_attributes'][self.ca_mongoid]
|
||||
self.projectId = self.proj['custom_attributes'][self.ca_mongoid]
|
||||
|
||||
io.install()
|
||||
self.avalon_project = io.find({"_id": ObjectId(proj_id)})
|
||||
self.projectId = proj_id
|
||||
try:
|
||||
self.avalon_project = io.find_one({"_id": ObjectId(self.projectId)})
|
||||
except:
|
||||
self.avalon_project = None
|
||||
|
||||
importEntities = []
|
||||
|
||||
if self.avalon_project is None:
|
||||
self.avalon_project = io.find_one({"type": "project", "name": self.proj["full_name"]})
|
||||
self.projectId = self.avalon_project['_id']
|
||||
if self.avalon_project is None:
|
||||
importEntities.append(self.proj)
|
||||
else:
|
||||
self.projectId = self.avalon_project['_id']
|
||||
io.uninstall()
|
||||
|
||||
self.importEntities = []
|
||||
|
||||
for entity in entities:
|
||||
if entity.entity_type.lower() in ['task']:
|
||||
entity = entity['parent']
|
||||
|
|
@ -51,21 +62,36 @@ class Sync_to_Avalon(BaseEvent):
|
|||
'message': "Please run 'Create Attributes' action or create custom attribute 'avalon_mongo_id' manually for {}".format(entity.entity_type)
|
||||
}
|
||||
|
||||
if entity not in self.importEntities:
|
||||
self.importEntities.append(entity)
|
||||
if entity not in importEntities:
|
||||
importEntities.append(entity)
|
||||
|
||||
if len(self.importEntities) < 1:
|
||||
return
|
||||
if len(importEntities) < 1:
|
||||
return False
|
||||
|
||||
self.setAvalonAttributes()
|
||||
|
||||
io.install()
|
||||
|
||||
for entity in self.importEntities:
|
||||
for entity in importEntities:
|
||||
self.importToAvalon(entity)
|
||||
|
||||
io.uninstall()
|
||||
|
||||
message = ""
|
||||
if len(self.nameChanged) > 0:
|
||||
names = ", ".join(self.nameChanged)
|
||||
message += "These entities name can't be changed in avalon, please reset DB or use restore action: {} \n".format(names)
|
||||
if len(self.nameShotAsset) > 0:
|
||||
names = ", ".join(self.nameChanged)
|
||||
message += "These entities are already used in avalon, duplicates with new name were created: {}".format(names)
|
||||
|
||||
session.commit()
|
||||
|
||||
if message != "":
|
||||
return {
|
||||
'success': False,
|
||||
'message': message
|
||||
}
|
||||
|
||||
return True
|
||||
|
||||
def importToAvalon(self, entity):
|
||||
|
|
@ -108,28 +134,28 @@ class Sync_to_Avalon(BaseEvent):
|
|||
|
||||
mongo_id = entity['custom_attributes'][self.ca_mongoid]
|
||||
|
||||
|
||||
if entity_type.lower() in ['project']:
|
||||
|
||||
if entity_type in ['Project']:
|
||||
config = ftrack_utils.get_config(entity)
|
||||
template = lib.get_avalon_project_template_schema()
|
||||
|
||||
if self.avalon_project is None:
|
||||
mongo_id = inventory.save(self.proj['full_name'], config, template)
|
||||
inventory.save(name, config, template)
|
||||
self.avalon_project = io.find_one({'type': 'project', 'name': name})
|
||||
|
||||
self.avalon_project = io.find({"_id": ObjectId(mongo_id)})
|
||||
self.projectId = mongo_id
|
||||
if self.avalon_project is None:
|
||||
self.avalon_project = io.find_one({"type": "project", "name": self.proj["full_name"]})
|
||||
self.projectId = self.avalon_project['_id']
|
||||
self.projectId = self.avalon_project['_id']
|
||||
data['code'] = entity['name']
|
||||
|
||||
io.update_many(
|
||||
{"_id": ObjectId(mongo_id)},
|
||||
{"_id": ObjectId(self.projectId)},
|
||||
{'$set':{
|
||||
'name':name,
|
||||
'config':config,
|
||||
'data':data,
|
||||
}})
|
||||
try:
|
||||
entity['custom_attributes'][self.ca_mongoid] = str(self.projectId)
|
||||
except Exception as e:
|
||||
self.log.error(e)
|
||||
return
|
||||
|
||||
|
||||
|
|
@ -148,31 +174,45 @@ class Sync_to_Avalon(BaseEvent):
|
|||
|
||||
folderStruct = []
|
||||
parents = []
|
||||
parentId = None
|
||||
|
||||
for i in range(1, len(eLinks)-1):
|
||||
parents.append(eLinks[i])
|
||||
|
||||
for parent in parents:
|
||||
parname = self.checkName(parent['name'])
|
||||
folderStruct.append(parname)
|
||||
parentId = io.find_one({'type': 'asset', 'name': parname})['_id']
|
||||
if parent['parent'].entity_type != 'project' and parentId is None:
|
||||
avalonAarent = io.find_one({'type': 'asset', 'name': parname})
|
||||
if parent['parent'].entity_type != 'project' and avalonAarent is None:
|
||||
self.importToAvalon(parent)
|
||||
parentId = io.find_one({'type': 'asset', 'name': parname})['_id']
|
||||
parentId = io.find_one({'type': 'asset', 'name': parname})['_id']
|
||||
|
||||
hierarchy = os.path.sep.join(folderStruct)
|
||||
|
||||
data['tasks'] = tasks
|
||||
data['parents'] = folderStruct
|
||||
data['visualParent'] = parentId
|
||||
data['hierarchy'] = hierarchy
|
||||
if parentId is not None:
|
||||
data['parents'] = folderStruct
|
||||
data['visualParent'] = parentId
|
||||
data['hierarchy'] = hierarchy
|
||||
|
||||
avalon_asset = None
|
||||
|
||||
if mongo_id is not "":
|
||||
avalon_asset = io.find_one({'_id': ObjectId(mongo_id)})
|
||||
|
||||
avalon_asset = io.find_one({'_id': ObjectId(mongo_id)})
|
||||
if avalon_asset is None:
|
||||
avalon_asset = io.find_one({'type': type, 'name': name})
|
||||
avalon_asset = io.find_one({'type': 'asset', 'name': name})
|
||||
if avalon_asset is None:
|
||||
mongo_id = inventory.create_asset(name, silo, data, self.projectId)
|
||||
elif avalon_asset['name'] != name:
|
||||
mongo_id = inventory.create_asset(name, silo, data, self.projectId)
|
||||
mongo_id = inventory.create_asset(name, silo, data, ObjectId(self.projectId))
|
||||
else:
|
||||
if name != avalon_asset['name']:
|
||||
string = "'{}->{}'".format(name, avalon_asset['name'])
|
||||
if entity_type in ['Shot','AssetBuild']:
|
||||
self.nameShotAsset.append(string)
|
||||
mongo_id = inventory.create_asset(name, silo, data, ObjectId(self.projectId))
|
||||
else:
|
||||
self.nameChanged.append(string)
|
||||
return
|
||||
|
||||
io.update_many(
|
||||
{"_id": ObjectId(mongo_id)},
|
||||
|
|
@ -182,6 +222,11 @@ class Sync_to_Avalon(BaseEvent):
|
|||
'data':data,
|
||||
'parent': self.projectId}})
|
||||
|
||||
try:
|
||||
entity['custom_attributes'][self.ca_mongoid] = str(mongo_id)
|
||||
except Exception as e:
|
||||
self.log.error(e)
|
||||
|
||||
|
||||
def checkName(self, input_name):
|
||||
if input_name.find(" ") == -1:
|
||||
|
|
|
|||
|
|
@ -33,9 +33,7 @@ class BaseEvent(object):
|
|||
def __init__(self, session):
|
||||
'''Expects a ftrack_api.Session instance'''
|
||||
|
||||
self.logger = Logger.getLogger(
|
||||
'{0}.{1}'.format(__name__, self.__class__.__name__)
|
||||
)
|
||||
self.log = Logger.getLogger(self.__class__.__name__)
|
||||
|
||||
self._session = session
|
||||
|
||||
|
|
@ -61,10 +59,7 @@ class BaseEvent(object):
|
|||
session.get(self._get_entity_type(entity), entity.get('entityId'))
|
||||
)
|
||||
)
|
||||
try:
|
||||
if _entities[0]['project'].entity_type in ['project']:
|
||||
_entities = None
|
||||
_entities = list()
|
||||
|
||||
return [
|
||||
_entities,
|
||||
event
|
||||
|
|
@ -98,6 +93,14 @@ class BaseEvent(object):
|
|||
self.session, event
|
||||
)
|
||||
|
||||
# TODO REMOVE THIS - ONLY FOR TEST PROJECT
|
||||
for a in args[0]:
|
||||
try:
|
||||
if (a['project']['name'] != 'eventproj'):
|
||||
return True
|
||||
except:
|
||||
continue
|
||||
|
||||
response = self.launch(
|
||||
self.session, *args
|
||||
)
|
||||
|
|
@ -150,7 +153,7 @@ class BaseEvent(object):
|
|||
)
|
||||
|
||||
else:
|
||||
self.logger.error(
|
||||
self.log.error(
|
||||
'Invalid result type must be bool or dictionary!'
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import sys
|
||||
import re
|
||||
import ftrack_api
|
||||
from ftrack_event_handler import BaseEvent
|
||||
from app import api
|
||||
|
|
@ -7,13 +8,12 @@ from app import api
|
|||
class Test_Event(BaseEvent):
|
||||
|
||||
def launch(self, session, entities, event):
|
||||
|
||||
'''just a testing event'''
|
||||
exceptions = ['assetversion', 'job', 'user', 'reviewsessionobject', 'timer', 'socialfeed', 'timelog']
|
||||
selection = event['data'].get('entities',[])
|
||||
for entity in selection:
|
||||
if entity['entityType'] in exceptions:
|
||||
print(100*"*")
|
||||
print(entity)
|
||||
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def register(session, **kw):
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ def get_apps(entity):
|
|||
print('Error with application {0} - {1}'.format(app, e))
|
||||
return apps
|
||||
|
||||
def get_config(self, entity):
|
||||
def get_config(entity):
|
||||
config = {}
|
||||
config['schema'] = lib.get_avalon_project_config_schema()
|
||||
config['tasks'] = [{'name': ''}]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue