mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
If one App is broken other will load. Print were changed for Logger
This commit is contained in:
parent
a13e86962f
commit
355dcbbae8
7 changed files with 74 additions and 58 deletions
|
|
@ -4,40 +4,64 @@ import toml
|
|||
import ftrack_api
|
||||
from ftrack_action_handler import AppAction
|
||||
from avalon import io, lib
|
||||
from app.api import Logger
|
||||
|
||||
log = Logger.getLogger(__name__)
|
||||
|
||||
def registerApp(app, session):
|
||||
name = app['name'].split("_")[0]
|
||||
variant = ""
|
||||
try:
|
||||
variant = app['name'].split("_")[1]
|
||||
except Exception as e:
|
||||
log.warning("'{0}' - App 'name' and 'variant' is not separated by '_' (variant is set to '')".format(app['name']))
|
||||
return
|
||||
|
||||
abspath = lib.which_app(app['name'])
|
||||
if abspath == None:
|
||||
log.error("'{0}' - App don't have config toml file".format(app['name']))
|
||||
return
|
||||
|
||||
apptoml = toml.load(abspath)
|
||||
executable = apptoml['executable']
|
||||
|
||||
label = app['label']
|
||||
icon = None
|
||||
# TODO get right icons
|
||||
if 'nuke' in app['name']:
|
||||
icon = "https://mbtskoudsalg.com/images/nuke-icon-png-2.png"
|
||||
label = "Nuke"
|
||||
elif 'maya' in app['name']:
|
||||
icon = "http://icons.iconarchive.com/icons/froyoshark/enkel/256/Maya-icon.png"
|
||||
label = "Autodesk Maya"
|
||||
|
||||
# register action
|
||||
AppAction(session, label, name, executable, variant, icon).register()
|
||||
|
||||
|
||||
def register(session):
|
||||
|
||||
# TODO AVALON_PROJECT, AVALON_ASSET, AVALON_SILO need to be set or debug from avalon
|
||||
|
||||
# Get all projects from Avalon DB
|
||||
io.install()
|
||||
projects = sorted(io.projects(), key=lambda x: x['name'])
|
||||
io.uninstall()
|
||||
|
||||
apps=[]
|
||||
actions = []
|
||||
try:
|
||||
io.install()
|
||||
projects = sorted(io.projects(), key=lambda x: x['name'])
|
||||
io.uninstall()
|
||||
except Exception as e:
|
||||
log.error(e)
|
||||
|
||||
apps = []
|
||||
appNames = []
|
||||
# Get all application from all projects
|
||||
for project in projects:
|
||||
os.environ['AVALON_PROJECT'] = project['name']
|
||||
for app in project['config']['apps']:
|
||||
if app not in apps:
|
||||
if app['name'] not in appNames:
|
||||
appNames.append(app['name'])
|
||||
apps.append(app)
|
||||
|
||||
for app in apps:
|
||||
name = app['name'].split("_")[0]
|
||||
variant = app['name'].split("_")[1]
|
||||
label = app['label']
|
||||
executable = toml.load(lib.which_app(app['name']))['executable']
|
||||
icon = None
|
||||
# TODO get right icons
|
||||
if 'nuke' in app['name']:
|
||||
icon = "https://mbtskoudsalg.com/images/nuke-icon-png-2.png"
|
||||
label = "Nuke"
|
||||
elif 'maya' in app['name']:
|
||||
icon = "http://icons.iconarchive.com/icons/froyoshark/enkel/256/Maya-icon.png"
|
||||
label = "Autodesk Maya"
|
||||
|
||||
# register action
|
||||
AppAction(session, label, name, executable, variant, icon).register()
|
||||
try:
|
||||
registerApp(app, session)
|
||||
except Exception as e:
|
||||
log.warning("'{0}' - not proper App ({1})".format(app['name'], e))
|
||||
|
|
|
|||
|
|
@ -127,8 +127,7 @@ class AvalonIdAttribute(BaseAction):
|
|||
|
||||
except Exception as e:
|
||||
job['status'] = 'failed'
|
||||
print("Creating custom attributes failed")
|
||||
print(e)
|
||||
self.log.error("Creating custom attributes failed ({})".format(e))
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ class JobKiller(BaseAction):
|
|||
|
||||
# Update all the queried jobs, setting the status to failed.
|
||||
for job in jobs:
|
||||
print(job['created_at'])
|
||||
print('Changing Job ({}) status: {} -> failed'.format(job['id'], job['status']))
|
||||
self.log.debug(job['created_at'])
|
||||
self.log.debug('Changing Job ({}) status: {} -> failed'.format(job['id'], job['status']))
|
||||
job['status'] = 'failed'
|
||||
|
||||
try:
|
||||
|
|
@ -47,7 +47,7 @@ class JobKiller(BaseAction):
|
|||
except:
|
||||
session.rollback()
|
||||
|
||||
print('All running jobs were killed Successfully!')
|
||||
self.log.info('All running jobs were killed Successfully!')
|
||||
return {
|
||||
'success': True,
|
||||
'message': 'All running jobs were killed Successfully!'
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class SyncToAvalon(BaseAction):
|
|||
})
|
||||
|
||||
try:
|
||||
print("action <" + self.__class__.__name__ + "> is running")
|
||||
self.log.info("action <" + self.__class__.__name__ + "> is running")
|
||||
|
||||
#TODO AVALON_PROJECTS, AVALON_ASSET, AVALON_SILO should be set up otherwise console log shows avalon debug
|
||||
self.setAvalonAttributes(session)
|
||||
|
|
@ -89,13 +89,12 @@ class SyncToAvalon(BaseAction):
|
|||
|
||||
job['status'] = 'done'
|
||||
session.commit()
|
||||
print('Synchronization to Avalon was successfull!')
|
||||
self.log.info('Synchronization to Avalon was successfull!')
|
||||
|
||||
except Exception as e:
|
||||
job['status'] = 'failed'
|
||||
print('During synchronization to Avalon went something wrong!')
|
||||
print(e)
|
||||
message = str(e)
|
||||
self.log.error('During synchronization to Avalon went something wrong! ({})'.format(message))
|
||||
|
||||
if len(message) > 0:
|
||||
return {
|
||||
|
|
@ -129,7 +128,7 @@ class SyncToAvalon(BaseAction):
|
|||
name = input_name
|
||||
else:
|
||||
name = input_name.replace(" ", "-")
|
||||
print("Name of {} was changed to {}".format(input_name, name))
|
||||
self.log.info("Name of {} was changed to {}".format(input_name, name))
|
||||
return name
|
||||
|
||||
def getConfig(self, entity):
|
||||
|
|
@ -139,7 +138,7 @@ class SyncToAvalon(BaseAction):
|
|||
label = toml.load(lib.which_app(app))['label']
|
||||
apps.append({'name':app, 'label':label})
|
||||
except Exception as e:
|
||||
print('Error with application {0} - {1}'.format(app, e))
|
||||
self.log.error('Error with application {0} - {1}'.format(app, e))
|
||||
|
||||
config = {
|
||||
'schema': 'avalon-core:config-1.0',
|
||||
|
|
@ -223,7 +222,7 @@ class SyncToAvalon(BaseAction):
|
|||
if ca_mongoid in entity['custom_attributes']:
|
||||
entity['custom_attributes'][ca_mongoid] = str(projectId)
|
||||
else:
|
||||
print("Custom attribute for <{}> is not created.".format(entity['name']))
|
||||
self.log.error("Custom attribute for <{}> is not created.".format(entity['name']))
|
||||
io.uninstall()
|
||||
return
|
||||
|
||||
|
|
@ -278,7 +277,7 @@ class SyncToAvalon(BaseAction):
|
|||
# Create if don't exists
|
||||
if avalon_asset is None:
|
||||
inventory.create_asset(name, silo, data, projectId)
|
||||
print("Asset {} - created".format(name))
|
||||
self.log.debug("Asset {} - created".format(name))
|
||||
# Raise error if it seems to be different ent. with same name
|
||||
|
||||
elif (avalon_asset['data']['ftrackId'] != data['ftrackId'] or
|
||||
|
|
@ -290,14 +289,14 @@ class SyncToAvalon(BaseAction):
|
|||
io.update_many({'type': 'asset','name': name},
|
||||
{'$set':{'data':data, 'silo': silo}})
|
||||
# TODO check if is asset in same folder!!! ???? FEATURE FOR FUTURE
|
||||
print("Asset {} - updated".format(name))
|
||||
self.log.debug("Asset {} - updated".format(name))
|
||||
|
||||
## FTRACK FEATURE - FTRACK MUST HAVE avalon_mongo_id FOR EACH ENTITY TYPE EXCEPT TASK
|
||||
# Set custom attribute to avalon/mongo id of entity (parentID is last)
|
||||
if ca_mongoid in entity['custom_attributes']:
|
||||
entity['custom_attributes'][ca_mongoid] = str(parentId)
|
||||
else:
|
||||
print("Custom attribute for <{}> is not created.".format(entity['name']))
|
||||
self.log.error("Custom attribute for <{}> is not created.".format(entity['name']))
|
||||
|
||||
io.uninstall()
|
||||
session.commit()
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class ThumbToParent(BaseAction):
|
|||
try:
|
||||
parent = entity['parent']
|
||||
except:
|
||||
print("Durin Action 'Thumb to Parent' went something wrong")
|
||||
self.log.error("Durin Action 'Thumb to Parent' went something wrong")
|
||||
thumbid = entity['thumbnail_id']
|
||||
|
||||
if parent and thumbid:
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import os
|
|||
import re
|
||||
from operator import itemgetter
|
||||
import ftrack_api
|
||||
from app.api import Logger
|
||||
|
||||
|
||||
class DJVViewAction(object):
|
||||
|
|
@ -16,9 +17,7 @@ class DJVViewAction(object):
|
|||
def __init__(self, session):
|
||||
'''Expects a ftrack_api.Session instance'''
|
||||
|
||||
self.logger = logging.getLogger(
|
||||
'{0}.{1}'.format(__name__, self.__class__.__name__)
|
||||
)
|
||||
self.log = Logger.getLogger(self.__class__.__name__)
|
||||
|
||||
if self.identifier is None:
|
||||
raise ValueError(
|
||||
|
|
@ -84,7 +83,7 @@ class DJVViewAction(object):
|
|||
),
|
||||
self.launch
|
||||
)
|
||||
print("----- action - <" + self.__class__.__name__ + "> - Has been registered -----")
|
||||
self.log.info("----- action - <" + self.__class__.__name__ + "> - Has been registered -----")
|
||||
|
||||
def get_applications(self):
|
||||
applications = []
|
||||
|
|
@ -240,7 +239,6 @@ class DJVViewAction(object):
|
|||
range = (padding % start) + '-' + (padding % end)
|
||||
filename = re.sub('%[0-9]*d', range, filename)
|
||||
else:
|
||||
print("")
|
||||
return {
|
||||
'success': False,
|
||||
'message': 'DJV View - Filename has more than one seqence identifier.'
|
||||
|
|
|
|||
|
|
@ -34,9 +34,7 @@ class AppAction(object):
|
|||
def __init__(self, session, label, name, executable, variant=None, icon=None, description=None):
|
||||
'''Expects a ftrack_api.Session instance'''
|
||||
|
||||
self.logger = logging.getLogger(
|
||||
'{0}.{1}'.format(__name__, self.__class__.__name__)
|
||||
)
|
||||
self.log = Logger.getLogger(self.__class__.__name__)
|
||||
|
||||
# self.logger = Logger.getLogger(__name__)
|
||||
|
||||
|
|
@ -86,7 +84,7 @@ class AppAction(object):
|
|||
)
|
||||
|
||||
if accepts:
|
||||
self.logger.info('Selection is valid')
|
||||
self.log.info('Selection is valid')
|
||||
return {
|
||||
'items': [{
|
||||
'label': self.label,
|
||||
|
|
@ -97,7 +95,7 @@ class AppAction(object):
|
|||
}]
|
||||
}
|
||||
else:
|
||||
self.logger.info('Selection is _not_ valid')
|
||||
self.log.info('Selection is _not_ valid')
|
||||
|
||||
def discover(self, session, entities, event):
|
||||
'''Return true if we can handle the selected entities.
|
||||
|
|
@ -226,7 +224,7 @@ class AppAction(object):
|
|||
'''
|
||||
|
||||
# TODO Delete this line
|
||||
print("Action - {0} ({1}) - just started".format(self.label, self.identifier))
|
||||
self.log.info("Action - {0} ({1}) - just started".format(self.label, self.identifier))
|
||||
|
||||
entity, id = entities[0]
|
||||
entity = session.get(entity, id)
|
||||
|
|
@ -318,7 +316,7 @@ class AppAction(object):
|
|||
username = event['source']['user']['username']
|
||||
user = session.query('User where username is "{}"'.format(username)).one()
|
||||
task = session.query('Task where id is {}'.format(entity['id'])).one()
|
||||
print('Starting timer for task: ' + task['name'])
|
||||
self.log.info('Starting timer for task: ' + task['name'])
|
||||
user.start_timer(task, force=True)
|
||||
|
||||
return {
|
||||
|
|
@ -371,7 +369,7 @@ class AppAction(object):
|
|||
)
|
||||
|
||||
else:
|
||||
self.logger.error(
|
||||
self.log.error(
|
||||
'Invalid result type must be bool or dictionary!'
|
||||
)
|
||||
|
||||
|
|
@ -400,9 +398,7 @@ class BaseAction(object):
|
|||
def __init__(self, session):
|
||||
'''Expects a ftrack_api.Session instance'''
|
||||
|
||||
self.logger = logging.getLogger(
|
||||
'{0}.{1}'.format(__name__, self.__class__.__name__)
|
||||
)
|
||||
self.log = Logger.getLogger(self.__class__.__name__)
|
||||
|
||||
if self.label is None:
|
||||
raise ValueError(
|
||||
|
|
@ -439,7 +435,7 @@ class BaseAction(object):
|
|||
),
|
||||
self._launch
|
||||
)
|
||||
print("----- action - <" + self.__class__.__name__ + "> - Has been registered -----")
|
||||
self.log.info("----- action - <" + self.__class__.__name__ + "> - Has been registered -----")
|
||||
|
||||
def _discover(self, event):
|
||||
args = self._translate_event(
|
||||
|
|
@ -451,7 +447,7 @@ class BaseAction(object):
|
|||
)
|
||||
|
||||
if accepts:
|
||||
self.logger.info(u'Discovering action with selection: {0}'.format(
|
||||
self.log.info(u'Discovering action with selection: {0}'.format(
|
||||
args[1]['data'].get('selection', [])))
|
||||
return {
|
||||
'items': [{
|
||||
|
|
@ -610,7 +606,7 @@ class BaseAction(object):
|
|||
)
|
||||
|
||||
else:
|
||||
self.logger.error(
|
||||
self.log.error(
|
||||
'Invalid result type must be bool or dictionary!'
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue