diff --git a/lib/configure.py b/lib/configure.py index d83190c..524fcb3 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -1,27 +1,33 @@ import os -from subprocess import call from pathlib import Path +import lib.pacman as pacman +from lib.package import Package -from lib.parse import Package +installed_packages = pacman.get_installed() def install(package): - if not package.source: + if not package.install or not package.source: return + if package.source == 'core' and package.name not in installed_packages: + res = pacman.install(package.name) + def copy_config(package): - if not package.config: + if not package.copy_config or not package.config: return def run_script(package): - if not package.script: + if not package.run_script or not package.script: return def enable_units(package): - if not package.userunits: + if not package.enable_units or not package.userunits: return def configure(package): - print(vars(package)) + if not package.enabled: + return + #print(vars(package)) install(package) copy_config(package) run_script(package) diff --git a/lib/pacman.py b/lib/pacman.py new file mode 100644 index 0000000..8e1fe82 --- /dev/null +++ b/lib/pacman.py @@ -0,0 +1,19 @@ +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() +