Skip to content
Doug Feldmann edited this page May 12, 2015 · 7 revisions
dangerous_process(cmd_string, error_message='', stdin=None, stdout=None, stderr=None, sudo=False)
    For processes that should be interactively verified before running.
    If the command uses 'sudo' to elevate privileges, set sudo to true and
    'sudo -v' will be called before executing the process.

pipestring_process(cmd_string, stdin_string='')
    Pipe a python string to standard input for cmd_string

    >>> pipestring_process('grep 2', '1\n2\n3\n')
    (0, '2\n', '')

poll_processes(proclist, wait=3, tries=3, debug=None)
    Given a list of process objects, poll each process in the list
    and update return codes.  Pull the list 'tries' times and wait 'wait'
    seconds between tries

    >>> process_objects=poll_processes(run_processes(['echo one', 'echo two']))
    >>> [isinstance(obj.returncode, int) for obj in process_objects]
    [True, True]

process(cmd_string, stdin=None)
    Given a string representing a single command, open a process, wait for it to terminate and then
    return standard out and standard in as a tuple

    >>> process("echo 1 2")
    (0, '1 2\n', '')

process_results(process_object)
    Given a process object, wait for it to complete then return a tuple:

    >>> (returncode, stdout, stderr) = process_results(process_run('echo my process'))
    >>> returncode
    0
    >>> stdout
    'my process\n'
    >>> stderr
    ''

process_run(cmd_string, stdin=None)
    Given a string representing a single command, open a process, and return
    the Popen process object.
    http://docs.python.org/2/library/subprocess.html#popen-objects

    >>> process_object = process_run('echo test')
    >>> isinstance(process_object, subprocess.Popen)
    True

processes(cmdlist)
    Spawns a list of processes in rapid succession, then waits for all of them
    to exit.  Returns a list of result tuples [(exitcode, stdin, stderr), ...]

    >>> processes(['echo process 1', 'echo process 2'])
    [(0, 'process 1\n', ''), (0, 'process 2\n', '')]

run_processes(cmdlist)
    Run a list of processes and return the list of objects without
    waiting for results

    >>> process_objects=run_processes(['echo one', 'echo two'])
    >>> [isinstance(obj, subprocess.Popen) for obj in process_objects]
    [True, True]

typical_process(cmd_string, error_message='', stdin=None, stdout=None, stderr=None)
    Call a process, write the results to stdout and stderr, and for nonzero
    return codes, print a custom error message before calling sys.exit.

    To write to files other than standard out and standard error, set
    the stdout and stderr parameters to file objects.

    Return (exitcode, stdout, stderr) for zero return codes.

validate_sudo()
Clone this wiki locally