From 90c1044bcf973199209acdfc74627074beeb8555 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Wed, 31 Oct 2018 10:08:06 +0100 Subject: [PATCH 1/3] Runs apps with avalon --- pype/ftrack/actions/action_Apps.py | 8 ++- pype/ftrack/actions/action_syncToAvalon.py | 3 +- pype/ftrack/actions/ftrack_action_handler.py | 56 ++++++++++++++------ 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/pype/ftrack/actions/action_Apps.py b/pype/ftrack/actions/action_Apps.py index 6b0a5e4cc7..c0158e1ed9 100644 --- a/pype/ftrack/actions/action_Apps.py +++ b/pype/ftrack/actions/action_Apps.py @@ -8,7 +8,13 @@ from avalon import io, lib def register(session): - os.environ['AVALON_PROJECTS'] = 'tmp' + try: os.environ['AVALON_PROJECT'] + except: os.environ['AVALON_PROJECT'] = 'tmp' + try: os.environ['AVALON_ASSET'] + except: os.environ['AVALON_ASSET'] = 'tmp' + try: os.environ['AVALON_SILO'] + except: os.environ['AVALON_SILO'] = 'tmp' + io.install() projects = sorted(io.projects(), key=lambda x: x['name']) io.uninstall() diff --git a/pype/ftrack/actions/action_syncToAvalon.py b/pype/ftrack/actions/action_syncToAvalon.py index f7e389a16b..4e4ce8d55d 100644 --- a/pype/ftrack/actions/action_syncToAvalon.py +++ b/pype/ftrack/actions/action_syncToAvalon.py @@ -81,7 +81,8 @@ class SyncToAvalon(BaseAction): 'schema': 'avalon-core:config-1.0', 'tasks': [{'name': ''}], 'apps': apps, - 'template': {'work': '','publish':''} + # TODO redo work!!! + 'template': {'work': '{root}/{project}/{hierarchy}/{asset}/work/{task}/{app}','publish':''} } # Set project template diff --git a/pype/ftrack/actions/ftrack_action_handler.py b/pype/ftrack/actions/ftrack_action_handler.py index 1cd18c184c..57fe0f22d7 100644 --- a/pype/ftrack/actions/ftrack_action_handler.py +++ b/pype/ftrack/actions/ftrack_action_handler.py @@ -5,7 +5,9 @@ import logging import getpass import platform import ftrack_api -from avalon import io +import toml +from avalon import io, lib, pipeline +from avalon import session as sess class AppAction(object): '''Custom Action base class @@ -55,8 +57,9 @@ class AppAction(object): ) self.session.event_hub.subscribe( - 'topic=ftrack.action.launch and data.actionIdentifier={0}'.format( - self.identifier + 'topic=ftrack.action.launch and data.actionIdentifier={0} and source.user.username={1}'.format( + self.identifier, + self.session.api_user ), self._launch ) @@ -101,13 +104,12 @@ class AppAction(object): entity = session.get(entity_type, entity_id) # TODO Should return False if not TASK ?!!! - # if entity.entity_type != 'Task': - # return False + if entity.entity_type != 'Task': + return False # TODO Should return False if more than one entity is selected ?!!! - # if len(entities) > 1: - # return False - + if len(entities) > 1: + return False ft_project = entity['project'] if (entity.entity_type != 'Project') else entity @@ -183,7 +185,7 @@ class AppAction(object): response = self.launch( self.session, *args - ) + ) return self._handle_result( self.session, response, *args @@ -211,10 +213,30 @@ class AppAction(object): # TODO Delete this line print("Action - {0} ({1}) - just started".format(self.label, self.identifier)) - # lib.launch(executable=self.executable, - # args=["-u", "-m", "avalon.tools.projectmanager", - # session['AVALON_PROJECT']]) + entity, id = entities[0] + entity = session.get(entity, id) + silo = "Film" + if entity.entity_type=="AssetBuild": + silo= "Asset" + + # set environments for Avalon + os.environ["AVALON_PROJECT"] = entity['project']['full_name'] + os.environ["AVALON_SILO"] = silo + os.environ["AVALON_ASSET"] = entity['parent']['name'] + os.environ["AVALON_TASK"] = entity['name'] + os.environ["AVALON_APP"] = self.identifier + os.environ["AVALON_APP_NAME"] = self.executable + + # TODO Add paths to avalon setup from tomls + if self.identifier == 'maya': + os.environ['PYTHONPATH'] += os.pathsep + os.path.join(os.getenv("AVALON_CORE"), 'setup', 'maya') + elif self.identifier == 'nuke': + os.environ['NUKE_PATH'] = os.pathsep + os.path.join(os.getenv("AVALON_CORE"), 'setup', 'nuke') + # config = toml.load(lib.which_app(self.identifier + "_" + self.variant)) + + + env = os.environ # Get path to execute st_temp_path = os.environ['PYPE_STUDIO_TEMPLATES'] os_plat = platform.system().lower() @@ -230,10 +252,9 @@ class AppAction(object): execfile = fpath break - - + # Run SW if was found executable if execfile is not None: - os.startfile(execfile) + lib.launch(executable=execfile, args=[], environment=env) else: return { 'success': False, @@ -349,8 +370,9 @@ class BaseAction(object): ) self.session.event_hub.subscribe( - 'topic=ftrack.action.launch and data.actionIdentifier={0}'.format( - self.identifier + 'topic=ftrack.action.launch and data.actionIdentifier={0} and source.user.username={1}'.format( + self.identifier, + self.session.api_user ), self._launch ) From 2c21c28417e2234410340ba4e1738e8b8ad8322a Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Wed, 31 Oct 2018 10:39:17 +0100 Subject: [PATCH 2/3] Removed details --- pype/ftrack/actions/action_Apps.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pype/ftrack/actions/action_Apps.py b/pype/ftrack/actions/action_Apps.py index c0158e1ed9..a7d3d933df 100644 --- a/pype/ftrack/actions/action_Apps.py +++ b/pype/ftrack/actions/action_Apps.py @@ -8,13 +8,9 @@ from avalon import io, lib def register(session): - try: os.environ['AVALON_PROJECT'] - except: os.environ['AVALON_PROJECT'] = 'tmp' - try: os.environ['AVALON_ASSET'] - except: os.environ['AVALON_ASSET'] = 'tmp' - try: os.environ['AVALON_SILO'] - except: os.environ['AVALON_SILO'] = 'tmp' + # 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() @@ -22,20 +18,20 @@ def register(session): apps=[] actions = [] + # 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: apps.append(app) - # TODO get right icons 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" @@ -43,4 +39,5 @@ def register(session): 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() From de5716a193e2ee6d34e8e348b229ec9c1b6fe23b Mon Sep 17 00:00:00 2001 From: Milan Kolar Date: Wed, 31 Oct 2018 11:55:51 +0100 Subject: [PATCH 3/3] fix workdir setup and hierarchy preparation --- pype/ftrack/actions/action_syncToAvalon.py | 2 +- pype/ftrack/actions/ftrack_action_handler.py | 30 +++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pype/ftrack/actions/action_syncToAvalon.py b/pype/ftrack/actions/action_syncToAvalon.py index 4e4ce8d55d..a2787e7a38 100644 --- a/pype/ftrack/actions/action_syncToAvalon.py +++ b/pype/ftrack/actions/action_syncToAvalon.py @@ -82,7 +82,7 @@ class SyncToAvalon(BaseAction): 'tasks': [{'name': ''}], 'apps': apps, # TODO redo work!!! - 'template': {'work': '{root}/{project}/{hierarchy}/{asset}/work/{task}/{app}','publish':''} + 'template': {'work': '','publish':''} } # Set project template diff --git a/pype/ftrack/actions/ftrack_action_handler.py b/pype/ftrack/actions/ftrack_action_handler.py index 57fe0f22d7..dd40854d42 100644 --- a/pype/ftrack/actions/ftrack_action_handler.py +++ b/pype/ftrack/actions/ftrack_action_handler.py @@ -9,6 +9,14 @@ import toml from avalon import io, lib, pipeline from avalon import session as sess +from app.api import ( + Templates +) + +t = Templates() + + + class AppAction(object): '''Custom Action base class @@ -226,7 +234,27 @@ class AppAction(object): os.environ["AVALON_ASSET"] = entity['parent']['name'] os.environ["AVALON_TASK"] = entity['name'] os.environ["AVALON_APP"] = self.identifier - os.environ["AVALON_APP_NAME"] = self.executable + os.environ["AVALON_APP_NAME"] = self.identifier + "_" + self.variant + + + anatomy = t.anatomy + io.install() + hierarchy = io.find_one({"type":'asset', "name":entity['parent']['name']})['data']['parents'] + io.uninstall() + if hierarchy: + # hierarchy = os.path.sep.join(hierarchy) + hierarchy = os.path.join(*hierarchy) + + data = { "project": {"name": entity['project']['full_name'], + "code": entity['project']['name']}, + "task": entity['name'], + "asset": entity['parent']['name'], + "hierarchy": hierarchy} + + anatomy = anatomy.format(data) + + + os.environ["AVALON_WORKDIR"] = os.path.join(anatomy.work.root, anatomy.work.folder) # TODO Add paths to avalon setup from tomls if self.identifier == 'maya':