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:
parent
f17a88e46c
commit
90a2adcbd3
17
lib/exec.py
Normal file
17
lib/exec.py
Normal 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
9
lib/git.py
Normal 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
23
lib/proc.py
Normal 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
12
lib/yay.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user