1
0
mirror of https://github.com/Foltik/dotfiles synced 2025-01-22 06:50:57 -05:00

Add standard interfaces for called programs

This commit is contained in:
Jack Foltz 2018-12-08 23:18:25 -05:00
parent f17a88e46c
commit 90a2adcbd3
Signed by: foltik
GPG Key ID: D1F0331758D1F29A
4 changed files with 61 additions and 0 deletions

17
lib/exec.py Normal file
View File

@ -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)

9
lib/git.py Normal file
View File

@ -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)

23
lib/proc.py Normal file
View File

@ -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()

12
lib/yay.py Normal file
View File

@ -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)