Coverage for volexport/util.py: 82%
16 statements
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-20 14:19 +0000
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-20 14:19 +0000
1import subprocess
2import shlex
3from logging import getLogger
4from .config import config
6_log = getLogger(__name__)
9def runcmd(cmd: list[str], root: bool = True):
10 _log.info("run %s, root=%s", cmd, root)
11 if root: 11 ↛ 16line 11 didn't jump to line 16 because the condition on line 11 was always true
12 if config.BECOME_METHOD == "su": 12 ↛ 13line 12 didn't jump to line 13 because the condition on line 12 was never true
13 cmd = ["su", "-c", shlex.join(cmd)]
14 elif config.BECOME_METHOD.lower() not in ("none", "false"): 14 ↛ 16line 14 didn't jump to line 16 because the condition on line 14 was always true
15 cmd[0:0] = shlex.split(config.BECOME_METHOD)
16 res = subprocess.run(
17 cmd,
18 capture_output=True,
19 encoding="utf-8",
20 timeout=config.CMD_TIMEOUT,
21 stdin=subprocess.DEVNULL,
22 start_new_session=True,
23 )
24 _log.info("returncode=%s, stdout=%s, stderr=%s", res.returncode, repr(res.stdout), repr(res.stderr))
25 res.check_returncode()
26 return res