def capture_command(*args, **kwargs):
    """Captures the system status, stdout and stderr of a command.

    The arguments are typically passed to subprocess.Popen or subprocess.call.

    Args:
        *args: A list of strings; allowing for as many positional arguments as
            can be supplied.
        **kwargs: Keyword arguments passed in. Only the following will be used:
            expect_success: Boolean; defaults to True. Used to determine if the
                captured command should succeed.
            single_line: Boolean; defaults to True. Used to determine if the
                output should be checked if it is a single output line.

    Returns:
        If we expect success, the standard output. Otherwise, a triple
            containing the status code returned, the standard output and the
            standard error.

    Raises:
        GitRvException: If the command does not exit with status code 0 and
            expect success is True.
    """
    proc = subprocess.Popen(args, stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    result = proc.wait()
    stdout = proc.stdout.read()
    stderr = proc.stderr.read()

    # TODO(dhermes): Should this be a constant?
    if not kwargs.get('expect_success', True):
        return (result, stdout, stderr)

    if result != 0:
        command = ' '.join(args)
        raise GitRvException((command, stderr) % 'Command %r failed with:\n%s')

    # TODO(dhermes): Should this be a constant?
    if kwargs.get('single_line', True):
        _check_single_line(stdout)
    return stdout.rstrip()
dataset/ETHPy150Open googlearchive/git-rv/utils.py/capture_command/swapped operands of `%`