added function 'split_command_to_list'

This commit is contained in:
iLLiCiTiT 2021-09-16 14:32:02 +02:00
parent 70872c240f
commit 1f5f7ac25d
2 changed files with 16 additions and 4 deletions

View file

@ -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.