diff --git a/lib/pacman.py b/lib/pacman.py index 3cd0aac..48c7fab 100644 --- a/lib/pacman.py +++ b/lib/pacman.py @@ -11,5 +11,5 @@ def install_all(packages): def pacman(flags, sudo = False): cmd = ['pacman', '--noconfirm'] + flags - subproc = proc.sudo(cmd) if sudo else proc.exec(cmd) + subproc = proc.exec(cmd, sudo) return proc.communicate(subproc, cmd) diff --git a/lib/proc.py b/lib/proc.py index 04495be..274a783 100644 --- a/lib/proc.py +++ b/lib/proc.py @@ -1,23 +1,16 @@ import subprocess -def sudo(cmd): - #print(['sudo'] + cmd) - return subprocess.Popen(['sudo'] + cmd, - stderr = subprocess.PIPE, - stdout = subprocess.PIPE, - stdin = subprocess.PIPE) - -def exec(cmd): +def exec(cmd, sudo = False): #print(cmd) - return subprocess.Popen(cmd, + return subprocess.Popen(['sudo'] + cmd if sudo else cmd, stderr = subprocess.PIPE, stdout = subprocess.PIPE, stdin = subprocess.PIPE) -def communicate(proc, cmd): +def communicate(proc, cmd, success_retvals = [0]): data = proc.communicate() - if proc.returncode != 0: - raise Exception('Command failed: ' + data[1].decode()) + if proc.returncode not in success_retvals: + raise Exception('Command failed: "' + ' '.join(cmd) + '"' + data[1].decode()) return data[0].decode()