From 1f2c1b3fcdc91b4fcc3b8657d29a2ba888c30f01 Mon Sep 17 00:00:00 2001 From: Arksine Date: Wed, 30 Dec 2020 17:35:14 -0500 Subject: [PATCH] confighelper: implement read_supplemental_config This allows the config object to read additional config files as requred. Also implement a "get_options" method that can be used to retrive a dictionary of all options in the current section. Signed-off-by: Eric Callahan --- moonraker/confighelper.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/moonraker/confighelper.py b/moonraker/confighelper.py index aa9880f..79dc521 100644 --- a/moonraker/confighelper.py +++ b/moonraker/confighelper.py @@ -34,6 +34,9 @@ class ConfigHelper: def get_name(self): return self.section + def get_options(self): + return dict(self.config[self.section]) + def get_prefix_sections(self, prefix): return [s for s in self.sections() if s.startswith(prefix)] @@ -70,6 +73,16 @@ class ConfigHelper: return self._get_item( self.config[self.section].getfloat, option, default) + def read_supplemental_config(self, file_name): + cfg_file_path = os.path.normpath(os.path.expanduser(file_name)) + if not os.path.isfile(cfg_file_path): + raise ConfigError( + f"Configuration File Not Found: '{cfg_file_path}''") + try: + self.config.read(cfg_file_path) + except Exception: + raise ConfigError(f"Error Reading Config: '{cfg_file_path}'") + def get_configuration(server, system_args): cfg_file_path = os.path.normpath(os.path.expanduser( system_args.configfile))