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:
parent
2953c3f16f
commit
1f2c1b3fcd
|
@ -34,6 +34,9 @@ class ConfigHelper:
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
return self.section
|
return self.section
|
||||||
|
|
||||||
|
def get_options(self):
|
||||||
|
return dict(self.config[self.section])
|
||||||
|
|
||||||
def get_prefix_sections(self, prefix):
|
def get_prefix_sections(self, prefix):
|
||||||
return [s for s in self.sections() if s.startswith(prefix)]
|
return [s for s in self.sections() if s.startswith(prefix)]
|
||||||
|
|
||||||
|
@ -70,6 +73,16 @@ class ConfigHelper:
|
||||||
return self._get_item(
|
return self._get_item(
|
||||||
self.config[self.section].getfloat, option, default)
|
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):
|
def get_configuration(server, system_args):
|
||||||
cfg_file_path = os.path.normpath(os.path.expanduser(
|
cfg_file_path = os.path.normpath(os.path.expanduser(
|
||||||
system_args.configfile))
|
system_args.configfile))
|
||||||
|
|
Loading…
Reference in New Issue