Merge pull request #1257 from pypeclub/feature/shell_prelaunch_hook

Shell prelaunch hook fix
This commit is contained in:
Milan Kolar 2021-04-08 12:36:04 +02:00 committed by GitHub
commit 5b7f94c5a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 15 deletions

View file

@ -1,4 +1,5 @@
import os
import subprocess
from openpype.lib import PreLaunchHook
@ -10,15 +11,32 @@ class LaunchWithWindowsShell(PreLaunchHook):
instead.
"""
order = 10
app_groups = ["resolve", "nuke", "nukex", "hiero", "nukestudio"]
# Should be as last hook becuase must change launch arguments to string
order = 1000
app_groups = ["nuke", "nukex", "hiero", "nukestudio"]
platforms = ["windows"]
def execute(self):
# Get comspec which is cmd.exe in most cases.
comspec = os.environ.get("COMSPEC", "cmd.exe")
# Add comspec to arguments list and add "/k"
new_args = [comspec, "/c"]
new_args.extend(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(self.launch_context.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 = new_args
self.launch_context.launch_args = args_string
# Change `creationflags` to CREATE_NEW_CONSOLE
self.launch_context.kwargs["creationflags"] = (
subprocess.CREATE_NEW_CONSOLE
)

View file

@ -836,10 +836,15 @@ class ApplicationLaunchContext:
self.log.debug("All prelaunch hook executed. Starting new process.")
# Prepare subprocess args
args = self.clear_launch_args(self.launch_args)
self.log.debug(
"Launching \"{}\" with args ({}): {}".format(
self.app_name, len(args), args
args_len_str = ""
if isinstance(self.launch_args, str):
args = self.launch_args
else:
args = self.clear_launch_args(self.launch_args)
args_len_str = " ({})".format(len(args))
self.log.info(
"Launching \"{}\" with args{}: {}".format(
self.app_name, args_len_str, args
)
)
# Run process
@ -885,7 +890,10 @@ class ApplicationLaunchContext:
Return:
list: Unpacked arguments.
"""
while True:
if isinstance(args, str):
return args
all_cleared = False
while not all_cleared:
all_cleared = True
new_args = []
for arg in args:
@ -897,8 +905,6 @@ class ApplicationLaunchContext:
new_args.append(arg)
args = new_args
if all_cleared:
break
return args