From ac83b43f98499ad3274544e8aa459ea652eed4f9 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 17 Aug 2023 21:59:28 +0200 Subject: [PATCH] Support for custom key-value overrides on `Config.init`. --- platypush/config/__init__.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/platypush/config/__init__.py b/platypush/config/__init__.py index 82c52eac3..9ad77f2f4 100644 --- a/platypush/config/__init__.py +++ b/platypush/config/__init__.py @@ -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