config.Config: add constructor parameter default_config_dirpath

This commit is contained in:
Benjamin Renard 2022-01-20 19:11:51 +01:00
parent c851e7aca7
commit b90994037a
1 changed files with 7 additions and 2 deletions

View File

@ -558,7 +558,7 @@ class Config: # pylint: disable=too-many-instance-attributes
""" Configuration helper """
def __init__(self, appname, shortname=None, version=None, encoding=None,
config_file_env_variable=None):
config_file_env_variable=None, default_config_dirpath=None):
self.appname = appname
self.shortname = shortname
self.version = version if version else '0.0'
@ -571,6 +571,7 @@ class Config: # pylint: disable=too-many-instance-attributes
self._loaded_callbacks_executed = []
self._filepath = None
self.config_file_env_variable = config_file_env_variable
self.default_config_dirpath = default_config_dirpath
def add_section(self, name, loaded_callback=None, **kwargs):
"""
@ -934,7 +935,11 @@ class Config: # pylint: disable=too-many-instance-attributes
@property
def config_dir(self):
""" Retrieve configuration directory path """
return os.path.dirname(self._filepath) if self._filepath else DEFAULT_CONFIG_DIRPATH
if self._filepath:
return os.path.dirname(self._filepath)
if self.default_config_dirpath:
return self.default_config_dirpath
return DEFAULT_CONFIG_DIRPATH
@property
def config_filepath(self):