diff --git a/lib/exec.py b/lib/exec.py new file mode 100644 index 0000000..b9ba16e --- /dev/null +++ b/lib/exec.py @@ -0,0 +1,17 @@ +import os +import pwd + +def current_user(): + return pwd.getpwuid(os.getuid()).pw_name + +def sudo(cmd): + return subprocess.Popen(['sudo'] + cmd, shell=True, + stderr = subprocess.PIPE, + stdout = subprocess.PIPE, + stdin = subprocess.PIPE) + +def exec(cmd): + return subprocess.Popen(['sudo'] + cmd, shell=True, + stderr = subprocess.PIPE, + stdout = subprocess.PIPE, + stdin = subprocess.PIPE) diff --git a/lib/git.py b/lib/git.py new file mode 100644 index 0000000..0ebbce9 --- /dev/null +++ b/lib/git.py @@ -0,0 +1,9 @@ +import lib.proc as proc + +def clone(url, dest): + output = git(['clone', url, dest]) + +def git(flags): + cmd = ['git'] + flags + subproc = proc.exec(cmd) + return proc.communicate(subproc, cmd) diff --git a/lib/proc.py b/lib/proc.py new file mode 100644 index 0000000..04495be --- /dev/null +++ b/lib/proc.py @@ -0,0 +1,23 @@ +import subprocess + +def sudo(cmd): + #print(['sudo'] + cmd) + return subprocess.Popen(['sudo'] + cmd, + stderr = subprocess.PIPE, + stdout = subprocess.PIPE, + stdin = subprocess.PIPE) + +def exec(cmd): + #print(cmd) + return subprocess.Popen(cmd, + stderr = subprocess.PIPE, + stdout = subprocess.PIPE, + stdin = subprocess.PIPE) + +def communicate(proc, cmd): + data = proc.communicate() + + if proc.returncode != 0: + raise Exception('Command failed: ' + data[1].decode()) + + return data[0].decode() diff --git a/lib/yay.py b/lib/yay.py new file mode 100644 index 0000000..9a790e9 --- /dev/null +++ b/lib/yay.py @@ -0,0 +1,12 @@ +import lib.proc as proc + +def install(package): + output = yay(['-S', package], True) + +def install_all(packages): + output = yay(['-S'] + packages, True) + +def yay(flags, sudo = False): + cmd = ['yay', '--noconfirm'] + flags + subproc = proc.sudo(cmd) if sudo else proc.exec(cmd) + return proc.communicate(subproc, cmd)