From ed9a7619b43d83cedfdee3516bd71fad21eaf064 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Fri, 22 May 2015 09:51:59 +0200 Subject: [PATCH] error handling pluginloader.py --- pluginloader.py | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/pluginloader.py b/pluginloader.py index 2d0e7db..d3383bc 100644 --- a/pluginloader.py +++ b/pluginloader.py @@ -8,27 +8,35 @@ import os def getPlugins(): - PluginFolder = globals.script_path+"/plugins" - plugins = [] - for i in os.listdir(PluginFolder): - location = os.path.join(PluginFolder, i) - # plugins have to be a subdir with MainModule, if not skip - if not os.path.isdir(location) or not i + ".py" in os.listdir(location): - continue + try: + logging.debug("Search in Plugin Folder") + PluginFolder = globals.script_path+"/plugins" + plugins = [] + for i in os.listdir(PluginFolder): + location = os.path.join(PluginFolder, i) + # plugins have to be a subdir with MainModule, if not skip + if not os.path.isdir(location) or not i + ".py" in os.listdir(location): + continue - # is the plugin enabled in the config-file? - try: - if globals.config.getint("Plugins", i): - info = imp.find_module(i, [location]) - plugins.append({"name": i, "info": info}) - logging.debug("Plugin [ENABLED ] %s", i) - else: + # is the plugin enabled in the config-file? + try: logging.debug("Plugin [DISABLED] %s ", i) - except: #no entry for plugin found in config-file, skip - logging.warning("Plugin [NO CONF ] %s", i) - + if globals.config.getint("Plugins", i): + info = imp.find_module(i, [location]) + plugins.append({"name": i, "info": info}) + logging.debug("Plugin [ENABLED ] %s", i) + else: + logging.debug("Plugin [DISABLED] %s ", i) + except: #no entry for plugin found in config-file, skip + logging.warning("Plugin [NO CONF ] %s", i) + except: + logging.exception("Error during Plugin search") + return plugins def loadPlugin(plugin): - logging.debug("load Plugin: %s", plugin["name"]) - return imp.load_module(plugin["name"], *plugin["info"]) \ No newline at end of file + try: + logging.debug("load Plugin: %s", plugin["name"]) + return imp.load_module(plugin["name"], *plugin["info"]) + except: + logging.exception("cannot load Plugin: %s", plugin["name"]) \ No newline at end of file