"""Detects whether or not an argument list invokes a Python program."""
return args[0] == "python" or args[0] == "wizard"
-def drop_priviledges(dir, options):
+def drop_priviledges(dir, log_file):
"""
Checks if we are running as root. If we are, attempt to drop
priviledges to the user who owns ``dir``, by re-calling
itself using sudo with exec, such that the new process subsumes our
- current one.
+ current one. If ``log_file`` is passed, the file is chown'ed
+ to the user we are dropping priviledges to, so the subprocess
+ can write to it.
"""
if os.getuid():
return
args.append("%s=%s" % (k,v))
args += sys.argv
logging.debug("Dropping priviledges")
- if options.log_file: os.chown(options.log_file, uid, -1)
+ if log_file: os.chown(log_file, uid, -1)
os.execlp('sudo', 'sudo', '-u', '#' + str(uid), *args)
class Shell(object):
super(ParallelShell, self).__init__(dry=dry)
self.running = {}
self.max = max # maximum of commands to run in parallel
+ @staticmethod
+ def make(no_parallelize, max):
+ """Convenience method oriented towards command modules."""
+ if no_parallelize:
+ return DummyParallelShell()
+ else:
+ return ParallelShell(max=max)
def _async(self, proc, args, python, on_success, on_error, **kwargs):
"""
Gets handed a :class:`subprocess.Proc` object from our deferred