1
0
mirror of https://github.com/Foltik/dotfiles synced 2024-11-24 12:26:05 -05:00
dotfiles/lib/pacman.py

20 lines
569 B
Python

import subprocess
def get_installed():
return [line.split(' ')[0] for line in pacman('-Q').split('\n')[:-1]]
def install(package):
pacman('-S ' + package)
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()