mirror of
https://github.com/Foltik/dotfiles
synced 2024-11-27 21:19:51 -05:00
Add base for package installing code
This commit is contained in:
parent
55479080e5
commit
aeb4276f51
@ -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)
|
||||
|
19
lib/pacman.py
Normal file
19
lib/pacman.py
Normal file
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user