utils.py 文件源码

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

项目:aws-vapor 作者: ohtomi 项目源码 文件源码
def save_to_config_file(props, save_on_global=False):
    """Save properties to a config file.

    Args:
        props (:class:`dict`): A :class:`dict` of properties.

        save_on_global (bool): A flag whether or not a new configuration will be saved globaly.
    """
    config = configparser.RawConfigParser()

    for section, entries in list(props.items()):
        config.add_section(section)
        for key, value in list(entries.items()):
            config.set(section, key, value)

    if save_on_global:
        if not os.path.exists(GLOBAL_CONFIG_DIRECTORY):
            os.mkdir(GLOBAL_CONFIG_DIRECTORY)

        with open(os.path.join(GLOBAL_CONFIG_DIRECTORY, CONFIG_FILE_NAME), mode=FILE_WRITE_MODE) as configfile:
            config.write(configfile)

    else:
        with open(os.path.join(LOCAL_CONFIG_DIRECTORY, CONFIG_FILE_NAME), mode=FILE_WRITE_MODE) as configfile:
            config.write(configfile)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号