confighelper: don't add supplemental configs to the original

Create a new ConfigParser that reads the supplemental and return a new ConfigWrapper.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-07-02 12:16:20 -04:00
parent 627db24c63
commit 78edcab86e
1 changed files with 5 additions and 2 deletions

View File

@ -121,15 +121,18 @@ class ConfigHelper:
return self._get_option( return self._get_option(
self.config[self.section].getfloat, option, default) self.config[self.section].getfloat, option, default)
def read_supplemental_config(self, file_name: str) -> None: def read_supplemental_config(self, file_name: str) -> ConfigHelper:
cfg_file_path = os.path.normpath(os.path.expanduser(file_name)) cfg_file_path = os.path.normpath(os.path.expanduser(file_name))
if not os.path.isfile(cfg_file_path): if not os.path.isfile(cfg_file_path):
raise ConfigError( raise ConfigError(
f"Configuration File Not Found: '{cfg_file_path}''") f"Configuration File Not Found: '{cfg_file_path}''")
try: try:
self.config.read(cfg_file_path) sup_cfg = configparser.ConfigParser(interpolation=None)
sup_cfg.read(cfg_file_path)
except Exception: except Exception:
raise ConfigError(f"Error Reading Config: '{cfg_file_path}'") raise ConfigError(f"Error Reading Config: '{cfg_file_path}'")
sections = sup_cfg.sections()
return ConfigHelper(self.server, sup_cfg, sections[0], sections)
def write_config(self, file_obj: IO[str]) -> None: def write_config(self, file_obj: IO[str]) -> None:
self.config.write(file_obj) self.config.write(file_obj)