From 9ff545352a2560478c72ab801a0966a6f06317a2 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 11 Jun 2021 10:11:34 +0200 Subject: [PATCH] Revert "with windows shell prelaunch hook to found app hook and simplyfied it" This reverts commit 913f4819596056643d0ba86f3c303bb0f2d724f3. # Conflicts: # openpype/hooks/pre_foundry_apps.py --- openpype/hooks/pre_foundry_apps.py | 28 --------------- openpype/hooks/pre_with_windows_shell.py | 44 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 28 deletions(-) delete mode 100644 openpype/hooks/pre_foundry_apps.py create mode 100644 openpype/hooks/pre_with_windows_shell.py diff --git a/openpype/hooks/pre_foundry_apps.py b/openpype/hooks/pre_foundry_apps.py deleted file mode 100644 index 85f68c6b60..0000000000 --- a/openpype/hooks/pre_foundry_apps.py +++ /dev/null @@ -1,28 +0,0 @@ -import subprocess -from openpype.lib import PreLaunchHook - - -class LaunchFoundryAppsWindows(PreLaunchHook): - """Foundry applications have specific way how to launch them. - - Nuke is executed "like" python process so it is required to pass - `CREATE_NEW_CONSOLE` flag on windows to trigger creation of new console. - At the same time the newly created console won't create it's own stdout - and stderr handlers so they should not be redirected to DEVNULL. - """ - - # Should be as last hook because must change launch arguments to string - order = 1000 - app_groups = ["nuke", "nukex", "hiero", "nukestudio"] - platforms = ["windows"] - - def execute(self): - # Change `creationflags` to CREATE_NEW_CONSOLE - # - on Windows will nuke create new window using it's console - # Set `stdout` and `stderr` to None so new created console does not - # have redirected output to DEVNULL in build - self.launch_context.kwargs.update({ - "creationflags": subprocess.CREATE_NEW_CONSOLE, - "stdout": None, - "stderr": None - }) diff --git a/openpype/hooks/pre_with_windows_shell.py b/openpype/hooks/pre_with_windows_shell.py new file mode 100644 index 0000000000..441ab1a675 --- /dev/null +++ b/openpype/hooks/pre_with_windows_shell.py @@ -0,0 +1,44 @@ +import os +import subprocess +from openpype.lib import PreLaunchHook + + +class LaunchWithWindowsShell(PreLaunchHook): + """Add shell command before executable. + + Some hosts have issues when are launched directly from python in that case + it is possible to prepend shell executable which will trigger process + instead. + """ + + # Should be as last hook because must change launch arguments to string + order = 1000 + app_groups = ["nuke", "nukex", "hiero", "nukestudio"] + platforms = ["windows"] + + def execute(self): + launch_args = self.launch_context.clear_launch_args( + self.launch_context.launch_args) + new_args = [ + # Get comspec which is cmd.exe in most cases. + os.environ.get("COMSPEC", "cmd.exe"), + # NOTE change to "/k" if want to keep console opened + "/c", + # Convert arguments to command line arguments (as string) + "\"{}\"".format( + subprocess.list2cmdline(launch_args) + ) + ] + # Convert list to string + # WARNING this only works if is used as string + args_string = " ".join(new_args) + self.log.info(( + "Modified launch arguments to be launched with shell \"{}\"." + ).format(args_string)) + + # Replace launch args with new one + self.launch_context.launch_args = args_string + # Change `creationflags` to CREATE_NEW_CONSOLE + self.launch_context.kwargs["creationflags"] = ( + subprocess.CREATE_NEW_CONSOLE + )