From 5f6c52dff03f2dc85d5b26b7f4469bc85a25ee09 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 13 Dec 2019 14:43:54 +0100 Subject: introduce verbosity aware subprocess.run wrapper and use it in benchmarks --- src/util.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/util.py') diff --git a/src/util.py b/src/util.py index 7992084..3f2ab06 100644 --- a/src/util.py +++ b/src/util.py @@ -24,6 +24,32 @@ import sys import src.globalvars +def run_cmd(cmd, + output_verbosity=3, + capture=False, + check=True, + cwd=None, + input=None): + """subprocess.run wrapper which cares about the set verbosity""" + if capture: + stdout = subprocess.PIPE + stderr = stdout + elif src.globalvars.verbosity < output_verbosity: + stdout = subprocess.DEVNULL + stderr = stdout + else: + stdout = None + stderr = stdout + + return subprocess.run(cmd, + check=check, + universal_newlines=True, + cwd=None, + stdout=stdout, + stderr=stderr, + input=input) + + def is_exe(fpath): """Check if the given path is an exexutable file""" return os.path.isfile(fpath) and os.access(fpath, os.X_OK) -- cgit v1.2.3