confighelper: match core components to their configuration
Most core components have default options that allow them to load without a section specified in moonraker.conf. This resulted in those options showing up in the [server] section in the "/server/config" response. These changes will make sure that those values show up in the correct section. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
58228ec161
commit
d61540cad5
|
@ -79,10 +79,14 @@ class ConfigHelper:
|
||||||
return self.section
|
return self.section
|
||||||
|
|
||||||
def get_options(self) -> Dict[str, str]:
|
def get_options(self) -> Dict[str, str]:
|
||||||
|
if not self.config.has_section(self.section):
|
||||||
|
return {}
|
||||||
return dict(self.config[self.section])
|
return dict(self.config[self.section])
|
||||||
|
|
||||||
def get_hash(self) -> hashlib._Hash:
|
def get_hash(self) -> hashlib._Hash:
|
||||||
hash = hashlib.sha256()
|
hash = hashlib.sha256()
|
||||||
|
if not self.config.has_section(self.section):
|
||||||
|
return hash
|
||||||
for option, val in self.config[self.section].items():
|
for option, val in self.config[self.section].items():
|
||||||
hash.update(option.encode())
|
hash.update(option.encode())
|
||||||
hash.update(val.encode())
|
hash.update(val.encode())
|
||||||
|
@ -92,8 +96,6 @@ class ConfigHelper:
|
||||||
return [s for s in self.sections() if s.startswith(prefix)]
|
return [s for s in self.sections() if s.startswith(prefix)]
|
||||||
|
|
||||||
def getsection(self, section: str) -> 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,
|
return ConfigHelper(self.server, self.config, section,
|
||||||
self.orig_sections, self.parsed)
|
self.orig_sections, self.parsed)
|
||||||
|
|
||||||
|
@ -109,11 +111,9 @@ class ConfigHelper:
|
||||||
) -> _T:
|
) -> _T:
|
||||||
try:
|
try:
|
||||||
val = func(self.section, option)
|
val = func(self.section, option)
|
||||||
except configparser.NoOptionError:
|
except (configparser.NoOptionError, configparser.NoSectionError) as e:
|
||||||
if isinstance(default, SentinelClass):
|
if isinstance(default, SentinelClass):
|
||||||
raise ConfigError(
|
raise ConfigError(str(e)) from None
|
||||||
f"No option found ({option}) in section [{self.section}]"
|
|
||||||
) from None
|
|
||||||
val = default
|
val = default
|
||||||
except Exception:
|
except Exception:
|
||||||
raise ConfigError(
|
raise ConfigError(
|
||||||
|
|
|
@ -228,8 +228,7 @@ class Server:
|
||||||
return self.components[component_name]
|
return self.components[component_name]
|
||||||
try:
|
try:
|
||||||
module = importlib.import_module("components." + component_name)
|
module = importlib.import_module("components." + component_name)
|
||||||
if component_name in config:
|
config = config[component_name]
|
||||||
config = config[component_name]
|
|
||||||
load_func = getattr(module, "load_component")
|
load_func = getattr(module, "load_component")
|
||||||
component = load_func(config)
|
component = load_func(config)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
Loading…
Reference in New Issue