diff --git a/lib/pacman.py b/lib/pacman.py index 8e1fe82..3cd0aac 100644 --- a/lib/pacman.py +++ b/lib/pacman.py @@ -1,19 +1,15 @@ -import subprocess +import lib.proc as proc def get_installed(): - return [line.split(' ')[0] for line in pacman('-Q').split('\n')[:-1]] + return [line.split(' ')[0] for line in pacman(['-Q']).split('\n')[:-1]] def install(package): - pacman('-S ' + package) + output = pacman(['-S', package], True) + +def install_all(packages): + output = pacman(['-S'] + packages, True) def pacman(flags, sudo = False): - cmd = ['sudo', 'pacman'] if sudo else ['pacman'] - cmd += ['--noconfirm', flags] - proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE) - data = proc.communicate() - - if proc.returncode != 0: - raise Exception('Command ' + ' '.join(cmd) + ' failed: ' + data[1].decode()) - - return data[0].decode() - + cmd = ['pacman', '--noconfirm'] + flags + subproc = proc.sudo(cmd) if sudo else proc.exec(cmd) + return proc.communicate(subproc, cmd)