From 789de0bd40744df7e4f98ccd62ecfa597482d84b Mon Sep 17 00:00:00 2001 From: KP Date: Tue, 16 Jun 2015 16:04:31 -0500 Subject: [PATCH 1/2] #29975 add app_path, app_args, version params to before_app_launch hook The before_app_launch hook now gets the same parameters as the app_launch hook which means you have access to the path of the application being launched and any arguments passed in. Also added a version parameter which will contain the version being launched *if* it was defined in the "versions" setting in the Launcher instance (otherwise this will be None). --- app.py | 28 +++++++++++++++++++++++----- hooks/app_launch.py | 4 +++- hooks/before_app_launch.py | 10 ++++++++-- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index 139586b..9b1af4e 100644 --- a/app.py +++ b/app.py @@ -190,6 +190,21 @@ def launch_from_entity(self, version=None): self._launch_app(self.context, version=version) + def _get_clean_version_string(self, version): + """ + Returns version string used for current app launch stripped of any ()'s defining + additional version tokens. For example, if the version setting is "(8.4)v6" this will + return "8.4v6" + + :param version: version of the application being launched specified by the value from + 'versions' settings. If no 'versions' were defined in the settings, then + this will be None. + """ + if version is None: + return version + clean_version = re.sub('[()]', '', version) + return clean_version + def _translate_version_tokens(self, raw_string, version): """ Returns string with version tokens replaced by their values. Replaces @@ -205,7 +220,7 @@ def _translate_version_tokens(self, raw_string, version): # split version string into tokens defined by ()s version_tokens = re.findall(r"\(([^\)]+)\)", version) # ensure we have a clean complete version string without ()s - clean_version = re.sub('[()]', '', version) + clean_version = self._get_clean_version_string(version) # do the substitution string = raw_string.replace("{version}", clean_version) for i, token in enumerate(version_tokens): @@ -217,7 +232,7 @@ def _get_app_path(self, version=None): platform_name = {"linux2": "linux", "darwin": "mac", "win32": "windows"}[sys.platform] raw_app_path = self.get_setting("%s_path" % platform_name, "") if version is None: - # there are two reasons version could be none + # there are two reasons version could be None # the first is if versions have not been configured, in which case the raw path is valid # if versions has been configured, then we should expand with the first element in the # list, which will be treated as the default @@ -308,9 +323,11 @@ def _launch_app_internal(self, context, file_to_open=None, version=None): else: (app_path, app_args) = self.prepare_generic_launch(engine_name, context, app_path, app_args) + version_string = self._get_clean_version_string(version) # run before launch hook - self.log_debug("Running before launch hook...") - self.execute_hook("hook_before_app_launch") + self.log_debug("Running before app launch hook...") + self.execute_hook("hook_before_app_launch", app_path=app_path, app_args=app_args, + version=version_string) # Ticket 26741: Avoid having odd DLL loading issues on windows # Desktop PySide sets an explicit DLL path, which is getting inherited by subprocess. @@ -320,7 +337,8 @@ def _launch_app_internal(self, context, file_to_open=None, version=None): try: # Launch the application self.log_debug("Launching executable '%s' with args '%s'" % (app_path, app_args)) - result = self.execute_hook("hook_app_launch", app_path=app_path, app_args=app_args) + result = self.execute_hook("hook_app_launch", app_path=app_path, app_args=app_args, + version=version_string) cmd = result.get("command") return_code = result.get("return_code") diff --git a/hooks/app_launch.py b/hooks/app_launch.py index 24fd230..5c6b81b 100644 --- a/hooks/app_launch.py +++ b/hooks/app_launch.py @@ -23,12 +23,14 @@ class AppLaunch(tank.Hook): Hook to run an application. """ - def execute(self, app_path, app_args, **kwargs): + def execute(self, app_path, app_args, version, **kwargs): """ The execute functon of the hook will be called to start the required application :param app_path: (str) The path of the application executable :param app_args: (str) Any arguments the application may require + :param version: (str) version of the application being run if set in the "versions" settings + of the Launcher instance, otherwise None :returns: (dict) The two valid keys are 'command' (str) and 'return_code' (int). """ diff --git a/hooks/before_app_launch.py b/hooks/before_app_launch.py index 8e15aa3..125227c 100644 --- a/hooks/before_app_launch.py +++ b/hooks/before_app_launch.py @@ -24,9 +24,15 @@ class BeforeAppLaunch(tank.Hook): Hook to set up the system prior to app launch. """ - def execute(self, **kwargs): + def execute(self, app_path, app_args, version, **kwargs): """ - The execute functon of the hook will be called to start the required application + The execute functon of the hook will be called prior to starting the required application + + :param app_path: (str) The path of the application executable + :param app_args: (str) Any arguments the application may require + :param version: (str) version of the application being run if set in the "versions" settings + of the Launcher instance, otherwise None + """ # accessing the current context (current shot, etc) From e17950234533926a0e2cdbcf119bb521d189be18 Mon Sep 17 00:00:00 2001 From: KP Date: Wed, 17 Jun 2015 09:24:57 -0500 Subject: [PATCH 2/2] CR comments --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 9b1af4e..bdfaf63 100644 --- a/app.py +++ b/app.py @@ -201,7 +201,7 @@ def _get_clean_version_string(self, version): this will be None. """ if version is None: - return version + return None clean_version = re.sub('[()]', '', version) return clean_version