Exemplo n.º 1
0
def main(args):
    config = get_config()

    if args.show:
        log.info(yaml.safe_dump(config, default_flow_style=False))
        return

    if args.show_sources:
        config_files = load_file_configs(SEARCH_PATH)
        for path in config_files:
            log.info('==> %s <==', path)
            log.info(
                yaml.safe_dump(config_files[path], default_flow_style=False))
        return

    if args.get:
        if args.get in config:
            log.info(config[args.get])
        else:
            log.info("The value of '%s' is not set." % args.get)
        return

    if args.files:
        log.info('User Config: %s' % USER_CONFIG)
        log.info('System Config: %s' % SYSTEM_CONFIG)
        return

    config_file = USER_CONFIG if args.user else SYSTEM_CONFIG

    config = load_config(config_file)

    for key, value in args.set:
        recursive_set(config, key, value, args.type)

    for key in args.remove:
        try:
            recursive_remove(config, key)
        except KeyError:
            log.error("Key %s does not exist" % key)

    if not (args.set or args.remove):
        raise ShowHelp()

    save_config(config, config_file)
Exemplo n.º 2
0
def main(args):
    config = get_config()

    if args.show:
        logger.info(yaml_dump(config))
        return

    if args.show_sources:
        config_files = load_file_configs(SEARCH_PATH)
        for path in config_files:
            logger.info('==> %s <==', path)
            logger.info(yaml_dump(config_files[path]))
        return

    if args.get:
        if args.get in config:
            logger.info(config[args.get])
        else:
            logger.info("The value of '%s' is not set." % args.get)
        return

    if args.files:
        logger.info('User Config: %s' % USER_CONFIG)
        logger.info('System Config: %s' % SYSTEM_CONFIG)
        return

    config_file = USER_CONFIG if args.user else SYSTEM_CONFIG

    config = load_config(config_file)

    for key, value in args.set:
        recursive_set(config, key, value, args.type)

    for key in args.remove:
        try:
            recursive_remove(config, key)
        except KeyError:
            logger.error("Key %s does not exist" % key)

    if not (args.set or args.remove):
        raise ShowHelp()

    save_config(config, config_file)