예제 #1
0
def get_config(config_path):
    """Retrieve the config from the specified path, returning a config dict."""
    if not os.path.exists(config_path):
        raise ConfigDoesNotExistException(
            'Config file {} does not exist.'.format(config_path))

    logger.debug('config_path is %s', config_path)
    with open(config_path, encoding='utf-8') as file_handle:
        try:
            yaml_dict = yaml.safe_load(file_handle)
        except yaml.YAMLError as e:
            raise InvalidConfiguration(
                'Unable to parse YAML file {}.'.format(config_path)) from e

    config_dict = merge_configs(DEFAULT_CONFIG, yaml_dict)

    raw_replay_dir = config_dict['replay_dir']
    config_dict['replay_dir'] = _expand_path(raw_replay_dir)

    raw_cookies_dir = config_dict['cookiecutters_dir']
    config_dict['cookiecutters_dir'] = _expand_path(raw_cookies_dir)

    return config_dict
예제 #2
0
def get_config(config_path):
    """Retrieve the config from the specified path, returning a config dict."""
    if not os.path.exists(config_path):
        raise ConfigDoesNotExistException

    logger.debug("config_path is {0}".format(config_path))
    with io.open(config_path, encoding="utf-8") as file_handle:
        try:
            yaml_dict = poyo.parse_string(file_handle.read())
        except poyo.exceptions.PoyoException as e:
            raise InvalidConfiguration(
                "Unable to parse YAML file {}. Error: {}"
                "".format(config_path, e))

    config_dict = merge_configs(DEFAULT_CONFIG, yaml_dict)

    raw_replay_dir = config_dict["replay_dir"]
    config_dict["replay_dir"] = _expand_path(raw_replay_dir)

    raw_cookies_dir = config_dict["cookiecutters_dir"]
    config_dict["cookiecutters_dir"] = _expand_path(raw_cookies_dir)

    return config_dict