diff --git a/openpype/lib/__init__.py b/openpype/lib/__init__.py index e96f1cc99f..5725e1c0e3 100644 --- a/openpype/lib/__init__.py +++ b/openpype/lib/__init__.py @@ -27,6 +27,7 @@ from .execute import ( get_pype_execute_args, execute, run_subprocess, + split_command_to_list, CREATE_NO_WINDOW ) from .log import PypeLogger, timeit @@ -171,6 +172,8 @@ __all__ = [ "get_pype_execute_args", "execute", "run_subprocess", + "split_command_to_list", + "CREATE_NO_WINDOW", "env_value_to_bool", "get_paths_from_environ", diff --git a/openpype/lib/execute.py b/openpype/lib/execute.py index 12fba23e82..d41db19a78 100644 --- a/openpype/lib/execute.py +++ b/openpype/lib/execute.py @@ -1,11 +1,10 @@ -import logging import os +import shlex import subprocess +import platform from .log import PypeLogger as Logger -log = logging.getLogger(__name__) - # MSDN process creation flag (Windows only) CREATE_NO_WINDOW = 0x08000000 @@ -100,7 +99,9 @@ def run_subprocess(*args, **kwargs): filtered_env = {str(k): str(v) for k, v in env.items()} # Use lib's logger if was not passed with kwargs. - logger = kwargs.pop("logger", log) + logger = kwargs.pop("logger", None) + if logger is None: + logger = Logger.get_logger("run_subprocess") # set overrides kwargs['stdout'] = kwargs.get('stdout', subprocess.PIPE) @@ -138,6 +139,14 @@ def run_subprocess(*args, **kwargs): return full_output +def split_command_to_list(string_command): + """Split string subprocess command to list.""" + posix = True + if platform.system().lower() == "windows": + posix = False + return shlex.split(string_command, posix=posix) + + def get_pype_execute_args(*args): """Arguments to run pype command.