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)
评论列表
文章目录