config: add default_config_filename parameter
This commit is contained in:
parent
07ab4490d2
commit
73795d27b8
1 changed files with 7 additions and 3 deletions
|
@ -666,6 +666,7 @@ class Config: # pylint: disable=too-many-instance-attributes
|
|||
encoding=None,
|
||||
config_file_env_variable=None,
|
||||
default_config_dirpath=None,
|
||||
default_config_filename=None,
|
||||
):
|
||||
self.appname = appname
|
||||
self.shortname = shortname
|
||||
|
@ -680,6 +681,7 @@ class Config: # pylint: disable=too-many-instance-attributes
|
|||
self._filepath = None
|
||||
self.config_file_env_variable = config_file_env_variable
|
||||
self.default_config_dirpath = default_config_dirpath
|
||||
self.default_config_filename = default_config_filename
|
||||
self._init_config_parser()
|
||||
|
||||
def add_section(self, name, loaded_callback=None, **kwargs):
|
||||
|
@ -1204,9 +1206,11 @@ class Config: # pylint: disable=too-many-instance-attributes
|
|||
return self._filepath
|
||||
if self.config_file_env_variable and os.environ.get(self.config_file_env_variable):
|
||||
return os.environ.get(self.config_file_env_variable)
|
||||
return os.path.join(
|
||||
self.config_dir, f"{self.shortname}.ini" if self.shortname else "config.ini"
|
||||
)
|
||||
if self.default_config_filename:
|
||||
filename = self.default_config_filename
|
||||
else:
|
||||
filename = f"{self.shortname}.ini" if self.shortname else "config.ini"
|
||||
return os.path.join(self.config_dir, filename)
|
||||
|
||||
|
||||
class ConfigurableObject:
|
||||
|
|
Loading…
Reference in a new issue