From dfc982a7e408528875815ec8dc93ef93a660a1d8 Mon Sep 17 00:00:00 2001 From: JHCD Date: Fri, 3 Jul 2015 23:36:50 +0200 Subject: [PATCH] solve bug in exception-handling we don't want to break down BOSWatch, if an plugin doesn't work --- includes/pluginLoader.py | 45 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/includes/pluginLoader.py b/includes/pluginLoader.py index 9d40dc8..7fbb192 100644 --- a/includes/pluginLoader.py +++ b/includes/pluginLoader.py @@ -18,7 +18,7 @@ from includes import globals # Global variables def loadPlugins(): """ - Load all Plugins into globals.pluginList + Load all plugins into globals.pluginList @return: nothing @exception: Exception if insert into globals.pluginList failed @@ -27,10 +27,17 @@ def loadPlugins(): logging.debug("loading plugins") # go to all Plugins from getPlugins() for i in getPlugins(): - # call for each Plugin the loadPlugin() Methode - plugin = loadPlugin(i) - # Try to call the .onLoad() routine for all active plugins try: + # call for each Plugin the loadPlugin() Methode + plugin = loadPlugin(i) + except: + # call next plugin, if one has thrown an exception + logging.error("error loading plugin: %s", i["name"]) + logging.debug("error loading plugin: %s", i["name"], exc_info=True) + pass + + try: + # Try to call the .onLoad() routine for all active plugins logging.debug("call %s.onLoad()", i["name"]) plugin.onLoad() # Add it to globals.pluginList @@ -41,20 +48,20 @@ def loadPlugins(): logging.debug("error calling %s.onLoad()", exc_info=True) pass except: - logging.error("cannot load Plugins") - logging.debug("cannot load Plugins", exc_info=True) + logging.error("cannot load plugins") + logging.debug("cannot load plugins", exc_info=True) raise def getPlugins(): """ - get a Python Dict of all activeated Plugins + get a Python Dict of all activeated plugins - @return: Plugins as Python Dict - @exception: Exception if Plugin search failed + @return: plugins as Python Dict + @exception: Exception if plugin search failed """ try: - logging.debug("Search in Plugin Folder") + logging.debug("Search in plugin folder") PluginFolder = globals.script_path+"/plugins" plugins = [] # Go to all Folders in the Plugin-Dir @@ -78,8 +85,8 @@ def getPlugins(): logging.warning("Plugin [NO CONF ] %s", i) pass except: - logging.error("Error during Plugin search") - logging.debug("cannot load Plugins", exc_info=True) + logging.error("Error during plugin search") + logging.debug("cannot load plugins", exc_info=True) raise return plugins @@ -87,19 +94,19 @@ def getPlugins(): def loadPlugin(plugin): """ - Imports a single Plugin + Imports a single plugin - @type plugin: Plugin Data - @param plugin: Contains the information to import a Plugin + @type plugin: plugin Data + @param plugin: Contains the information to import a plugin @return: nothing - @exception: Exception if Plugin import failed + @exception: Exception if plugin import failed """ try: - logging.debug("load Plugin: %s", plugin["name"]) + logging.debug("load plugin: %s", plugin["name"]) return imp.load_module(plugin["name"], *plugin["info"]) except: - logging.error("cannot load Plugin: %s", plugin["name"]) - logging.debug("cannot load Plugin: %s", plugin["name"], exc_info=True) + logging.error("cannot load plugin: %s", plugin["name"]) + logging.debug("cannot load plugin: %s", plugin["name"], exc_info=True) raise