config.py 文件源码

python
阅读 42 收藏 0 点赞 0 评论 0

项目:stellarmagnate 作者: abadger 项目源码 文件源码
def _read_config(paths, testing=False):
    """
    Read the config files listed in path and merge them into a dictionary.

    :arg paths: filenames to read and merge configuration data from.  The last
        files should override the first ones.
    :arg testing: If set to True, then use paths to data files that are
        appropriate for testing a source checkout.
    :rtype: ConfigObj, a dict-like object with helper methods for use as a config store
    :returns: Return the configuration dict
    """
    cfg = yaml.safe_load(DEFAULT_CONFIG)
    CONFIG_SCHEMA(cfg)

    for cfg_file in paths:
        try:
            with open(cfg_file, 'rb') as f:
                new_cfg = yaml.safe_load(f)
        except yaml.MarkedYAMLError as e:
            raise MagnateConfigError('Config error parsing {}:\n{}'.format(cfg_file, e))

        _merge_mapping(cfg, new_cfg, inplace=True)

        try:
            CONFIG_SCHEMA(cfg)
        except MultipleInvalid as e:
            raise MagnateConfigError('Config error in {}:\n{}'.format(cfg_file, e))

    if testing:
        testing_cfg = yaml.safe_load(TESTING_CONFIG)
        _merge_mapping(cfg, testing_cfg, inplace=True)
        CONFIG_SCHEMA(cfg)

    return cfg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号