From f27daac4f4eeaaa36c81f4b06722a097211f4354 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Mon, 4 Apr 2022 20:44:50 -0400 Subject: [PATCH] confighelper: remove "orig section" tracking This isn't necessary as we don't add new sections to the original config object when parsing supplemental data. Signed-off-by: Eric Callahan --- moonraker/confighelper.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/moonraker/confighelper.py b/moonraker/confighelper.py index 5531f20..b2f2457 100644 --- a/moonraker/confighelper.py +++ b/moonraker/confighelper.py @@ -47,13 +47,11 @@ class ConfigHelper: server: Server, config: configparser.ConfigParser, section: str, - orig_sects: List[str], parsed: Dict[str, Dict[str, ConfigVal]] = {} ) -> None: self.server = server self.config = config self.section = section - self.orig_sections = orig_sects self.parsed = parsed if self.section not in self.parsed: self.parsed[self.section] = {} @@ -94,8 +92,7 @@ class ConfigHelper: def getsection(self, section: str) -> ConfigHelper: if section not in self.config: raise ConfigError(f"No section [{section}] in config") - return ConfigHelper(self.server, self.config, section, - self.orig_sections, self.parsed) + return ConfigHelper(self.server, self.config, section, self.parsed) def _get_option(self, func: Callable[..., Any], @@ -126,16 +123,15 @@ class ConfigHelper: "deprecated, see the configuration documention " "at https://moonraker.readthedocs.io") self._check_option(option, val, above, below, minval, maxval) - if self.section in self.orig_sections: - # Only track sections included in the original config - if ( - val is None or - isinstance(val, (int, float, bool, str, dict, list)) - ): - self.parsed[self.section][option] = val - else: - # If the item cannot be encoded to json serialize to a string - self.parsed[self.section][option] = str(val) + # Only track sections included in the original config + if ( + val is None or + isinstance(val, (int, float, bool, str, dict, list)) + ): + self.parsed[self.section][option] = val + else: + # If the item cannot be encoded to json serialize to a string + self.parsed[self.section][option] = str(val) return val def _check_option(self, @@ -383,7 +379,7 @@ class ConfigHelper: except Exception: raise ConfigError("Error Reading Object") sections = sup_cfg.sections() - return ConfigHelper(self.server, sup_cfg, sections[0], sections) + return ConfigHelper(self.server, sup_cfg, sections[0]) def read_supplemental_config(self, file_name: str) -> ConfigHelper: cfg_file_path = os.path.normpath(os.path.expanduser(file_name)) @@ -396,7 +392,7 @@ class ConfigHelper: except Exception: raise ConfigError(f"Error Reading Config: '{cfg_file_path}'") sections = sup_cfg.sections() - return ConfigHelper(self.server, sup_cfg, sections[0], sections) + return ConfigHelper(self.server, sup_cfg, sections[0]) def write_config(self, file_obj: IO[str]) -> None: self.config.write(file_obj) @@ -405,7 +401,7 @@ class ConfigHelper: return dict(self.parsed) def validate_config(self) -> None: - for sect in self.orig_sections: + for sect in self.config.sections(): if sect not in self.parsed: self.server.add_warning( f"Unparsed config section [{sect}] detected. This " @@ -442,8 +438,7 @@ def get_configuration(server: Server, raise ConfigError(f"Error Reading Config: '{cfg_file_path}'") from e if not config.has_section('server'): raise ConfigError("No section [server] in config") - orig_sections = config.sections() - return ConfigHelper(server, config, 'server', orig_sections) + return ConfigHelper(server, config, 'server') def backup_config(cfg_path: str) -> None: cfg = pathlib.Path(cfg_path).expanduser().resolve()