1
0
mirror of https://github.com/Foltik/dotfiles synced 2024-11-27 21:19:51 -05:00

Refactor pacman for new proc stuff

This commit is contained in:
Jack Foltz 2018-12-08 23:20:35 -05:00
parent 38364ab681
commit 40edbf18fe
Signed by: foltik
GPG Key ID: D1F0331758D1F29A

View File

@ -1,19 +1,15 @@
import subprocess import lib.proc as proc
def get_installed(): 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): 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): def pacman(flags, sudo = False):
cmd = ['sudo', 'pacman'] if sudo else ['pacman'] cmd = ['pacman', '--noconfirm'] + flags
cmd += ['--noconfirm', flags] subproc = proc.sudo(cmd) if sudo else proc.exec(cmd)
proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE) return proc.communicate(subproc, cmd)
data = proc.communicate()
if proc.returncode != 0:
raise Exception('Command ' + ' '.join(cmd) + ' failed: ' + data[1].decode())
return data[0].decode()