Support for custom key-value overrides on `Config.init`.

This commit is contained in:
Fabio Manganiello 2023-08-17 21:59:28 +02:00
parent 657b2cc87d
commit ac83b43f98
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
1 changed files with 22 additions and 4 deletions

View File

@ -463,13 +463,31 @@ class Config:
return None
@classmethod
def init(cls, cfgfile: Optional[str] = None):
def init(
cls,
cfgfile: Optional[str] = None,
device_id: Optional[str] = None,
workdir: Optional[str] = None,
ctrl_sock: Optional[str] = None,
**_,
):
"""
Initializes the config object singleton
Params:
cfgfile -- path to the config file - default: _cfgfile_locations
:param cfgfile: Path to the config file (default: _cfgfile_locations)
:param device_id: Override the configured device_id.
:param workdir: Override the configured working directory.
:param ctrl_sock: Override the configured control socket.
"""
return cls._get_instance(cfgfile, force_reload=True)
cfg = cls._get_instance(cfgfile, force_reload=True)
if device_id:
cfg.set('device_id', device_id)
if workdir:
cfg.set('workdir', workdir)
if ctrl_sock:
cfg.set('ctrl_sock', ctrl_sock)
return cfg
@classmethod
@property