def _get_config_object(config_path, use_cashed_config=True):
'''
Returns a ConfigParser for the config file at the given path. If no file exists, an empty config file is created.
:param config_path:
:param use_cashed_config: If set to True, will return the previously created ConfigParser file (if previously created).
If set to False, will re-read the config file from disk. If a ConfigParser was previously created, it will not be replaced!
:return:
'''
if config_path not in _CONFIG_OBJECTS or not use_cashed_config:
config = ConfigParser()
if not os.path.exists(config_path):
with open(config_path,'w') as f:
config.write(f)
else:
config.read(config_path)
if use_cashed_config:
_CONFIG_OBJECTS[config_path] = config
else:
config = _CONFIG_OBJECTS[config_path]
return config
评论列表
文章目录