From 90c1044bcf973199209acdfc74627074beeb8555 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Wed, 31 Oct 2018 10:08:06 +0100 Subject: [PATCH] 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 )