Coverage for volexport/util.py: 82%
16 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-09-28 12:48 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-09-28 12:48 +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 """Run a command"""
11 _log.info("run %s, root=%s", cmd, root)
12 if root: 12 ↛ 17line 12 didn't jump to line 17 because the condition on line 12 was always true
13 if config.BECOME_METHOD == "su": 13 ↛ 14line 13 didn't jump to line 14 because the condition on line 13 was never true
14 cmd = ["su", "-c", shlex.join(cmd)]
15 elif config.BECOME_METHOD.lower() not in ("none", "false"): 15 ↛ 17line 15 didn't jump to line 17 because the condition on line 15 was always true
16 cmd[0:0] = shlex.split(config.BECOME_METHOD)
17 res = subprocess.run(
18 cmd,
19 capture_output=True,
20 encoding="utf-8",
21 timeout=config.CMD_TIMEOUT,
22 stdin=subprocess.DEVNULL,
23 start_new_session=True,
24 )
25 _log.info("returncode=%s, stdout=%s, stderr=%s", res.returncode, repr(res.stdout), repr(res.stderr))
26 res.check_returncode()
27 return res