mirror of
https://github.com/Foltik/dotfiles
synced 2025-01-07 08:42:47 -05:00
Change exec to take sudo as a parameter
This commit is contained in:
parent
e1647db4b8
commit
1d42aab37e
@ -11,5 +11,5 @@ def install_all(packages):
|
||||
|
||||
def pacman(flags, sudo = False):
|
||||
cmd = ['pacman', '--noconfirm'] + flags
|
||||
subproc = proc.sudo(cmd) if sudo else proc.exec(cmd)
|
||||
subproc = proc.exec(cmd, sudo)
|
||||
return proc.communicate(subproc, cmd)
|
||||
|
17
lib/proc.py
17
lib/proc.py
@ -1,23 +1,16 @@
|
||||
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):
|
||||
def exec(cmd, sudo = False):
|
||||
#print(cmd)
|
||||
return subprocess.Popen(cmd,
|
||||
return subprocess.Popen(['sudo'] + cmd if sudo else cmd,
|
||||
stderr = subprocess.PIPE,
|
||||
stdout = subprocess.PIPE,
|
||||
stdin = subprocess.PIPE)
|
||||
|
||||
def communicate(proc, cmd):
|
||||
def communicate(proc, cmd, success_retvals = [0]):
|
||||
data = proc.communicate()
|
||||
|
||||
if proc.returncode != 0:
|
||||
raise Exception('Command failed: ' + data[1].decode())
|
||||
if proc.returncode not in success_retvals:
|
||||
raise Exception('Command failed: "' + ' '.join(cmd) + '"' + data[1].decode())
|
||||
|
||||
return data[0].decode()
|
||||
|
Loading…
Reference in New Issue
Block a user