check_xbps.py: run commands with sudo only when necessary

This commit is contained in:
Sven Velt 2016-12-26 22:58:47 +01:00
parent 7d476d9109
commit 2ad98cb81d

View file

@ -79,9 +79,9 @@ lxc-2.0.4_1 update x86_64 https://repo.voidlinux.eu/current 1837102 468024'''.sp
##############################################################################
def run_command(cmdline):
def run_command(cmdline, needs_sudo=False):
tstart = time.time()
if plugin.options.sudo:
if needs_sudo and plugin.options.sudo:
new = ['sudo', '-n', '--']
new.extend(cmdline)
cmdline = new
@ -112,7 +112,7 @@ def run_command(cmdline):
if plugin.options.sync_repo_index:
plugin.verbose(1, '-S/--sync_repo_index given')
cmdline = [plugin.options.xbps_install, '-S',]
(sout, serr, rc) = run_command(cmdline)
(sout, serr, rc) = run_command(cmdline, needs_sudo=True)
sout and plugin.verbose(3, sout, prefix='stdout: ')
serr and plugin.verbose(3, serr, prefix='stderr: ')
plugin.verbose(2, 'Return code: %d' % rc)