added function 'path_to_subprocess_arg' which decide if path should be wrapped in quotes

This commit is contained in:
iLLiCiTiT 2021-09-16 15:57:25 +02:00
parent 004b2c5a5e
commit 3d9970aa4f
2 changed files with 13 additions and 0 deletions

View file

@ -28,6 +28,7 @@ from .execute import (
execute,
run_subprocess,
split_command_to_list,
path_to_subprocess_arg,
CREATE_NO_WINDOW
)
from .log import PypeLogger, timeit
@ -173,6 +174,7 @@ __all__ = [
"execute",
"run_subprocess",
"split_command_to_list",
"path_to_subprocess_arg",
"CREATE_NO_WINDOW",
"env_value_to_bool",

View file

@ -139,6 +139,14 @@ def run_subprocess(*args, **kwargs):
return full_output
def path_to_subprocess_arg(path):
"""Prepare path for subprocess arguments.
Returned path can be wrapped with quotes or kept as is.
"""
return subprocess.list2cmdline([path])
def split_command_to_list(string_command):
"""Split string subprocess command to list.
@ -159,6 +167,9 @@ def split_command_to_list(string_command):
Returns:
list: Command separated into individual arguments.
"""
if not string_command:
return []
kwargs = {}
# Use 'posix' argument only on windows
if platform.system().lower() == "windows":