mirror of
https://github.com/Foltik/dotfiles
synced 2025-01-09 09:16:49 -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):
|
def pacman(flags, sudo = False):
|
||||||
cmd = ['pacman', '--noconfirm'] + flags
|
cmd = ['pacman', '--noconfirm'] + flags
|
||||||
subproc = proc.sudo(cmd) if sudo else proc.exec(cmd)
|
subproc = proc.exec(cmd, sudo)
|
||||||
return proc.communicate(subproc, cmd)
|
return proc.communicate(subproc, cmd)
|
||||||
|
17
lib/proc.py
17
lib/proc.py
@ -1,23 +1,16 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
def sudo(cmd):
|
def exec(cmd, sudo = False):
|
||||||
#print(['sudo'] + cmd)
|
|
||||||
return subprocess.Popen(['sudo'] + cmd,
|
|
||||||
stderr = subprocess.PIPE,
|
|
||||||
stdout = subprocess.PIPE,
|
|
||||||
stdin = subprocess.PIPE)
|
|
||||||
|
|
||||||
def exec(cmd):
|
|
||||||
#print(cmd)
|
#print(cmd)
|
||||||
return subprocess.Popen(cmd,
|
return subprocess.Popen(['sudo'] + cmd if sudo else cmd,
|
||||||
stderr = subprocess.PIPE,
|
stderr = subprocess.PIPE,
|
||||||
stdout = subprocess.PIPE,
|
stdout = subprocess.PIPE,
|
||||||
stdin = subprocess.PIPE)
|
stdin = subprocess.PIPE)
|
||||||
|
|
||||||
def communicate(proc, cmd):
|
def communicate(proc, cmd, success_retvals = [0]):
|
||||||
data = proc.communicate()
|
data = proc.communicate()
|
||||||
|
|
||||||
if proc.returncode != 0:
|
if proc.returncode not in success_retvals:
|
||||||
raise Exception('Command failed: ' + data[1].decode())
|
raise Exception('Command failed: "' + ' '.join(cmd) + '"' + data[1].decode())
|
||||||
|
|
||||||
return data[0].decode()
|
return data[0].decode()
|
||||||
|
Loading…
Reference in New Issue
Block a user