Configure verbosity level through Fabric's output managers.

    Provides a default mapping from verbosity levels to output types.

    :param verbosity: an integral verbosity level
    :param output_levels: an optional mapping from Fabric output types to verbosity
    :param quiet: specifies that all output should be suppressed

    This function is designed to work with command line argument parsing.
    For example:

        # configure argparse
        parser.add_option("-q", dest="quiet", action="store_true", default=False)
        parser.add_option("-v", dest="verbosity", action="count", default=0)

        # configure output
        configure_output(options.verbosity, options.quiet)

def configure_output(verbosity=0, output_levels=None, quiet=False):
    """
    Configure verbosity level through Fabric's output managers.

    Provides a default mapping from verbosity levels to output types.

    :param verbosity: an integral verbosity level
    :param output_levels: an optional mapping from Fabric output types to verbosity
    :param quiet: specifies that all output should be suppressed

    This function is designed to work with command line argument parsing.
    For example:

        # configure argparse
        parser.add_option("-q", dest="quiet", action="store_true", default=False)
        parser.add_option("-v", dest="verbosity", action="count", default=0)

        # configure output
        configure_output(options.verbosity, options.quiet)
    """
    verbosity = verbosity if not quiet else -1

    output_levels = output_levels or {
        "status": 0,
        "aborts": 0,
        "user": 1,
        "warnings": 1,
        "running": 1,
        "stdout": 2,
        "stderr": 2,
        "debug": 2
    }

    # configure output manager levels via verbosity
    for manager, level in output_levels.iteritems():
        output[manager] = level <= verbosity

    # Hook up Python warnings to warning output manager
    warnings.showwarning = warn_via_fabric
    warnings.simplefilter("always", UserWarning)