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 <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-04-04 15:26:16 -04:00
parent d61540cad5
commit 9c33eb225c
No known key found for this signature in database
GPG Key ID: 7027245FBBDDF59A
1 changed files with 13 additions and 18 deletions

View File

@ -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] = {}
@ -96,8 +94,7 @@ class ConfigHelper:
return [s for s in self.sections() if s.startswith(prefix)]
def getsection(self, section: str) -> ConfigHelper:
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,14 @@ 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)
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 +378,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 +391,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 +400,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 "
@ -443,7 +438,7 @@ def get_configuration(server: Server,
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()