From 40edbf18fec1de069150d7b6d47a174757995da3 Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Sat, 8 Dec 2018 23:20:35 -0500 Subject: [PATCH] Refactor pacman for new proc stuff --- lib/pacman.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) 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)