moonraker: load_plugin() fix

Make sure that the correct config section is loaded when "load_plugin" is called.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-09-26 06:09:08 -04:00
parent d1c0cdf65b
commit 3d1faebf15
1 changed files with 4 additions and 2 deletions

View File

@ -99,7 +99,7 @@ class Server:
opt_sections = set(config.sections()) - \ opt_sections = set(config.sections()) - \
set(['server', 'authorization', 'cmd_args']) set(['server', 'authorization', 'cmd_args'])
for section in opt_sections: for section in opt_sections:
self.load_plugin(config[section], section, None) self.load_plugin(config, section, None)
def load_plugin(self, config, plugin_name, default=Sentinel): def load_plugin(self, config, plugin_name, default=Sentinel):
if plugin_name in self.plugins: if plugin_name in self.plugins:
@ -115,11 +115,13 @@ class Server:
return default return default
module = importlib.import_module("plugins." + plugin_name) module = importlib.import_module("plugins." + plugin_name)
try: try:
if plugin_name not in CORE_PLUGINS:
config = config[plugin_name]
load_func = getattr(module, "load_plugin") load_func = getattr(module, "load_plugin")
plugin = load_func(config) plugin = load_func(config)
except Exception: except Exception:
msg = f"Unable to load plugin ({plugin_name})" msg = f"Unable to load plugin ({plugin_name})"
logging.info(msg) logging.exception(msg)
if default == Sentinel: if default == Sentinel:
raise ServerError(msg) raise ServerError(msg)
return default return default