mirror of
https://github.com/Foltik/dotfiles
synced 2024-11-30 14:32:08 -05:00
20 lines
569 B
Python
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()
|
|
|