Exemplo n.º 1
0
def dumpButlerConfig(root, searchPath=None, subset=None, outfh=sys.stdout):
    """Dump a config or subset to the specified file handle.

    Parameters
    ----------
    root : `str`
        Location of butler configuration.  Can be a path to a YAML
        file or a directory containing the configuration file.
    searchPath : `list` of `str`
        Directory paths for resolving the locations of configuration
        file lookups.
    subset : `str` or `tuple` of `str`
        Key into a subset of the configuration. If a string it should use
        the standard notation of supplying the relevant delimiter in the
        first character.
    outfh
        File descriptor to use to write the configuration content.
    """

    config = ButlerConfig(root, searchPaths=searchPath)

    if subset is not None:
        config = config[subset]

    try:
        config.dump(outfh)
    except AttributeError:
        print(config, file=outfh)
        default=None,
        type=str,
        help="Subset of a configuration to report. This can be any key in the"
        " hierarchy such as '.datastore.root' where the leading '.' specified"
        " the delimiter for the hierarchy.")
    parser.add_argument(
        "--searchpath",
        "-p",
        action="append",
        type=str,
        help="Additional search paths to use for configuration overrides")
    parser.add_argument("--verbose",
                        "-v",
                        action="store_true",
                        help="Turn on debug reporting.")

    args = parser.parse_args()

    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)

    config = ButlerConfig(args.root, searchPaths=args.searchpath)

    if args.subset is not None:
        config = config[args.subset]

    try:
        config.dump(sys.stdout)
    except AttributeError:
        print(config)