diff --git a/src/otaclient_common/common.py b/src/otaclient_common/common.py index 10433bc2f..49faf21c8 100644 --- a/src/otaclient_common/common.py +++ b/src/otaclient_common/common.py @@ -22,7 +22,6 @@ import logging import os -import shlex import shutil import subprocess import time @@ -33,6 +32,8 @@ import requests +from otaclient_common.linux import subprocess_run_wrapper + logger = logging.getLogger(__name__) @@ -101,39 +102,6 @@ def write_str_to_file_sync(path: Union[Path, str], input: str): os.fsync(f.fileno()) -def subprocess_run_wrapper( - cmd: str | list[str], - *, - check: bool, - check_output: bool, - timeout: Optional[float] = None, -) -> subprocess.CompletedProcess[bytes]: - """A wrapper for subprocess.run method. - - NOTE: this is for the requirement of customized subprocess call - in the future, like chroot or nsenter before execution. - - Args: - cmd (str | list[str]): command to be executed. - check (bool): if True, raise CalledProcessError on non 0 return code. - check_output (bool): if True, the UTF-8 decoded stdout will be returned. - timeout (Optional[float], optional): timeout for execution. Defaults to None. - - Returns: - subprocess.CompletedProcess[bytes]: the result of the execution. - """ - if isinstance(cmd, str): - cmd = shlex.split(cmd) - - return subprocess.run( - cmd, - check=check, - stderr=subprocess.PIPE, - stdout=subprocess.PIPE if check_output else None, - timeout=timeout, - ) - - def subprocess_check_output( cmd: str | list[str], *, diff --git a/src/otaclient_common/linux.py b/src/otaclient_common/linux.py index 785858ca3..0cc34df61 100644 --- a/src/otaclient_common/linux.py +++ b/src/otaclient_common/linux.py @@ -22,7 +22,7 @@ from subprocess import check_call from typing import Any, Callable, Optional -from otaclient._utils.typing import StrOrPath +from otaclient_common.typing import StrOrPath # # ------ swapfile handling ------ # @@ -158,6 +158,11 @@ def map_gid_by_grpnam(*, src_db: ParsedGroup, dst_db: ParsedGroup, gid: int) -> raise ValueError(f"failed to find mapping for {gid}") +# +# ------ subprocess call ------ # +# + + def subprocess_run_wrapper( cmd: str | list[str], *,