Wrappers around subprocess functionality that simulate an actual shell.
An advanced shell that performs logging. If dry is True, no commands are actually run.
Performs a system call. The actual executable and options should be passed as arguments to this function. It will magically ensure that ‘wizard’ as a command works. Several keyword arguments are also supported:
Parameters: |
|
---|---|
Returns: | a tuple of strings (stdout, stderr), or a string stdout if strip is specified. |
>>> sh = Shell()
>>> sh.call("echo", "Foobar")
('Foobar\n', '')
>>> sh.call("cat", input='Foobar')
('Foobar', '')
Performs a system call as a different user. This is only possible if you are running as root. Keyword arguments are the same as call() with the following additions:
Parameters: |
|
---|
Note
The resulting system call internally uses sudo, and as such environment variables will get scrubbed. We manually preserve SSH_GSSAPI_NAME.
Evaluates a command and returns its output, with trailing newlines stripped (like backticks in Bash). This is a convenience method for calling call() with strip.
>>> sh = Shell()
>>> sh.eval("echo", "Foobar")
'Foobar'
Checks if the owner of the current working directory is the same as the current user, and if it isn’t, attempts to sudo to be that user. The intended use case is for calling Git commands when running as root, but this method should be used when interfacing with any moderately complex program that depends on working directory context. Keyword arguments are the same as call().
Sets the directory processes are executed in. This sets a value to be passed as the cwd argument to subprocess.Popen.
Modifies the semantics of Shell so that commands are queued here, and executed in parallel using waitpid with max subprocesses, and result in callback execution when they finish.
Enqueues a system call for parallel processing. If there are no openings in the queue, this will block. Keyword arguments are the same as Shell.call() with the following additions:
Parameters: |
|
---|---|
Returns: | The subprocess.Proc object that was opened. |
Enqueues a system call under a different user for parallel processing. Keyword arguments are the same as Shell.callAsUser() with the additions of keyword arguments from call().
Enqueues a “safe” call for parallel processing. Keyword arguments are the same as Shell.safeCall() with the additions of keyword arguments from call().
No difference from call(). Consider having a non-parallel shell if the program you are shelling out to is fast.
Waits for all of our subprocesses to terminate.
Convenience method oriented towards command modules.
Reaps a process.
Bases: wizard.shell.ParallelShell
Same API as ParallelShell, but doesn’t actually parallelize (i.e. all calls to wait() block.)
Performs a system call. The actual executable and options should be passed as arguments to this function. It will magically ensure that ‘wizard’ as a command works. Several keyword arguments are also supported:
Parameters: |
|
---|---|
Returns: | a tuple of strings (stdout, stderr), or a string stdout if strip is specified. |
>>> sh = Shell()
>>> sh.call("echo", "Foobar")
('Foobar\n', '')
>>> sh.call("cat", input='Foobar')
('Foobar', '')
Performs a system call as a different user. This is only possible if you are running as root. Keyword arguments are the same as call() with the following additions:
Parameters: |
|
---|
Note
The resulting system call internally uses sudo, and as such environment variables will get scrubbed. We manually preserve SSH_GSSAPI_NAME.
Evaluates a command and returns its output, with trailing newlines stripped (like backticks in Bash). This is a convenience method for calling call() with strip.
>>> sh = Shell()
>>> sh.eval("echo", "Foobar")
'Foobar'
Waits for all of our subprocesses to terminate.
Convenience method oriented towards command modules.
Reaps a process.
Checks if the owner of the current working directory is the same as the current user, and if it isn’t, attempts to sudo to be that user. The intended use case is for calling Git commands when running as root, but this method should be used when interfacing with any moderately complex program that depends on working directory context. Keyword arguments are the same as call().
Sets the directory processes are executed in. This sets a value to be passed as the cwd argument to subprocess.Popen.
Detects whether or not an argument list invokes a Python program.
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. 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.
This is the path to the wizard executable as specified by the caller; it lets us recursively invoke wizard.
Base exception for this module
Indicates that a subprocess call returned a nonzero exit status.
List of the program and arguments that failed.
The exit code of the failed subprocess.
The stderr of the program.
The stdout of the program.
Bases: wizard.shell.CallError
Indicates that a Python subprocess call had an uncaught exception. This exception also contains the attributes of CallError.
Name of the uncaught exception.