moonraker: fix load_plugin()

Respect the default parameter if a plugin's path is not found.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-08-02 20:48:34 -04:00
parent d768a30d47
commit 6c69dbdca9
1 changed files with 7 additions and 3 deletions

View File

@ -100,14 +100,18 @@ class Server:
mod_path = os.path.join( mod_path = os.path.join(
os.path.dirname(__file__), 'plugins', plugin_name + '.py') os.path.dirname(__file__), 'plugins', plugin_name + '.py')
if not os.path.exists(mod_path): if not os.path.exists(mod_path):
logging.info("Plugin (%s) does not exist" % (plugin_name)) msg = "Plugin (%s) does not exist" % (plugin_name)
return None logging.info(msg)
if default == Sentinel:
raise ServerError(msg)
return default
module = importlib.import_module("plugins." + plugin_name) module = importlib.import_module("plugins." + plugin_name)
try: try:
load_func = getattr(module, "load_plugin") load_func = getattr(module, "load_plugin")
plugin = load_func(self) plugin = load_func(self)
except Exception: except Exception:
msg = "Unable to load plugin (%s)" % (plugin_name) msg = "Unable to load plugin (%s)" % (plugin_name)
logging.info(msg)
if default == Sentinel: if default == Sentinel:
raise ServerError(msg) raise ServerError(msg)
return default return default
@ -285,7 +289,7 @@ class Server:
for name, cfg in plugin_cfgs.items(): for name, cfg in plugin_cfgs.items():
plugin = self.plugins.get(name) plugin = self.plugins.get(name)
if plugin is None: if plugin is None:
plugin = self.load_plugin(name) plugin = self.load_plugin(name, None)
if hasattr(plugin, "load_config"): if hasattr(plugin, "load_config"):
plugin.load_config(cfg) plugin.load_config(cfg)
# Remove plugins that are loaded but no longer configured # Remove plugins that are loaded but no longer configured