Add helper exec_cmd

main
Felix Stupp 2 years ago
parent 79fca1994c
commit 51982682c6
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -25,10 +25,11 @@
from __future__ import annotations from __future__ import annotations
import argparse import argparse
from functools import cached_property, wraps from functools import cache, cached_property, wraps
import os import os
from pathlib import Path from pathlib import Path
import shlex import shlex
from subprocess import CompletedProcess, PIPE, run
import sys import sys
from typing import ( from typing import (
Dict, Dict,
@ -131,6 +132,18 @@ def combine_cmds(*commands: CommandArgs | List[Optional[str]]) -> CommandArgs:
return CommandArgs([arg for cmd in commands for arg in filter_cmds(cmd)]) return CommandArgs([arg for cmd in commands for arg in filter_cmds(cmd)])
def exec_cmd(
command: CommandArgs, check: bool = True, capture_stdout: bool = True
) -> CompletedProcess:
res = run(
args=command,
check=check,
shell=False,
stdout=PIPE if capture_stdout else None,
)
return res
@wraps(print) @wraps(print)
def error(*args, **kwargs): def error(*args, **kwargs):
ret = print(*args, file=sys.stderr, **kwargs) ret = print(*args, file=sys.stderr, **kwargs)

Loading…
Cancel
Save