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 <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-12-30 17:35:14 -05:00
parent 2953c3f16f
commit 1f2c1b3fcd
1 changed files with 13 additions and 0 deletions

View File

@ -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))