OP-2414 - refactor non python kwargs

This commit is contained in:
Petr Kalis 2022-02-09 13:09:45 +01:00
parent 755d7a1d95
commit d732363d1a
3 changed files with 40 additions and 30 deletions

View file

@ -1,11 +1,10 @@
import os
import subprocess
import platform
from openpype.lib import (
PreLaunchHook,
get_openpype_execute_args
)
from openpype.lib.execute import get_non_python_host_kwargs
from openpype import PACKAGE_DIR as OPENPYPE_DIR
@ -53,16 +52,6 @@ class NonPythonHostHook(PreLaunchHook):
if remainders:
self.launch_context.launch_args.extend(remainders)
if platform.system().lower() == "windows":
# expected behavior - openpype_console opens window with logs
# openpype_gui has stdout/stderr available for capturing
if "openpype_gui" in os.environ.get("OPENPYPE_EXECUTABLE"):
self.launch_context.kwargs.update({
"creationflags": subprocess.CREATE_NO_WINDOW,
"stdout": subprocess.DEVNULL,
"stderr": subprocess.DEVNULL
})
else:
self.launch_context.kwargs.update({
"creationflags": subprocess.CREATE_NEW_CONSOLE
})
self.launch_context.kwargs = \
get_non_python_host_kwargs(self.launch_context.kwargs)

View file

@ -23,7 +23,7 @@ from .server import Server
from openpype.tools.stdout_broker.app import StdOutBroker
from openpype.tools.utils import host_tools
from openpype import style
from openpype.lib.execute import get_non_python_host_kwargs
# Setup logging.
log = logging.getLogger(__name__)
@ -315,7 +315,7 @@ def launch_zip_file(filepath):
return
print("Launching {}".format(scene_path))
kwargs = _get_kwargs()
kwargs = get_non_python_host_kwargs({}, False)
process = subprocess.Popen(
[ProcessContext.application_path, scene_path],
**kwargs
@ -622,16 +622,3 @@ def find_node_by_name(name, node_type):
return None
def _get_kwargs():
"""Explicitly handle openpype_gui no not show console."""
kwargs = {}
if platform.system().lower() == "windows":
if "openpype_gui" in os.environ.get("OPENPYPE_EXECUTABLE"):
kwargs.update({
"creationflags": subprocess.CREATE_NO_WINDOW,
"stdout": subprocess.DEVNULL,
"stderr": subprocess.DEVNULL
})
print("kwargs:: {}".format(kwargs))
return kwargs

View file

@ -1,6 +1,7 @@
import os
import subprocess
import distutils.spawn
import platform
from .log import PypeLogger as Logger
@ -272,3 +273,36 @@ def get_linux_launcher_args(*args):
launch_args.extend(args)
return launch_args
def get_non_python_host_kwargs(kwargs, allow_console=True):
"""Explicit setting of kwargs for Popen for AE/PS/Harmony.
Expected behavior
- openpype_console opens window with logs
- openpype_gui has stdout/stderr available for capturing
Args:
kwargs (dict) or None
allow_console (bool): use False for inner Popen opening app itself or
it will open additional console (at least for Harmony)
"""
if kwargs is None:
kwargs = {}
if platform.system().lower() == "windows":
executable_path = os.environ.get("OPENPYPE_EXECUTABLE")
executable_filename = ""
if executable_path:
executable_filename = os.path.dirname(executable_path)
if "openpype_gui" in executable_filename:
kwargs.update({
"creationflags": subprocess.CREATE_NO_WINDOW,
"stdout": subprocess.DEVNULL,
"stderr": subprocess.DEVNULL
})
else:
kwargs.update({
"creationflags": subprocess.CREATE_NEW_CONSOLE
})
return kwargs