[core] Minor refactoring

Use a small helper function from util, tidy up some parts of the
output.
This commit is contained in:
Tobi-wan Kenobi 2016-12-02 17:52:05 +01:00
parent a93fa4aa5c
commit f306366629
4 changed files with 18 additions and 23 deletions

View file

@ -21,12 +21,13 @@ def durationfmt(duration):
return res
def execute(cmd):
def execute(cmd, wait=True):
args = shlex.split(cmd)
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, err = p.communicate()
if p.returncode != 0:
raise RuntimeError("{} exited with {}".format(cmd, p.returncode))
return out.decode("utf-8")
if wait:
out, err = p.communicate()
if p.returncode != 0:
raise RuntimeError("{} exited with {}".format(cmd, p.returncode))
return out.decode("utf-8")
return None