From c590d706555d0c1aa4ba56c952f9a394a66c9449 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 22 May 2015 22:40:24 +0200 Subject: [PATCH 1/5] rename pluginloader -> pluginLoader --- includes/pluginloader.py | 52 ---------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 includes/pluginloader.py diff --git a/includes/pluginloader.py b/includes/pluginloader.py deleted file mode 100644 index ae591cf..0000000 --- a/includes/pluginloader.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/python -# -*- coding: cp1252 -*- - -import logging # Global logger -import imp -import os - -from includes import globals # Global variables - -def loadPlugins(): - try: - logging.debug("loading plugins") - for i in getPlugins(): - plugin = loadPlugin(i) - globals.pluginList[i["name"]] = plugin - except: - logging.exception("cannot load Plugins") - - -def getPlugins(): - 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: - 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): - 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 From 0849672cbef17d6cf06f725a5dfbcbc753d412d5 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 22 May 2015 22:40:44 +0200 Subject: [PATCH 2/5] rename pluginloader -> pluginLoader --- boswatch.py | 4 ++-- includes/alarmHandler.py | 1 - includes/pluginLoader.py | 52 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 includes/pluginLoader.py diff --git a/boswatch.py b/boswatch.py index 2768a5e..90dabc8 100755 --- a/boswatch.py +++ b/boswatch.py @@ -131,8 +131,8 @@ try: else: #load plugins - from includes import pluginloader - pluginloader.loadPlugins() + from includes import pluginLoader + pluginLoader.loadPlugins() try: #start rtl_fm diff --git a/includes/alarmHandler.py b/includes/alarmHandler.py index 88a1834..7a58dbe 100644 --- a/includes/alarmHandler.py +++ b/includes/alarmHandler.py @@ -4,7 +4,6 @@ import logging from includes import globals # Global variables -from includes import pluginloader def processAlarm(typ,freq,data): logging.debug("[ ALARM ]") diff --git a/includes/pluginLoader.py b/includes/pluginLoader.py new file mode 100644 index 0000000..ae591cf --- /dev/null +++ b/includes/pluginLoader.py @@ -0,0 +1,52 @@ +#!/usr/bin/python +# -*- coding: cp1252 -*- + +import logging # Global logger +import imp +import os + +from includes import globals # Global variables + +def loadPlugins(): + try: + logging.debug("loading plugins") + for i in getPlugins(): + plugin = loadPlugin(i) + globals.pluginList[i["name"]] = plugin + except: + logging.exception("cannot load Plugins") + + +def getPlugins(): + 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: + 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): + 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 From 148547b69fe9968d793e907436df74fd7efe41e9 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 22 May 2015 22:58:27 +0200 Subject: [PATCH 3/5] little edit httpreq plugin --- plugins/httpRequest/httpRequest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/httpRequest/httpRequest.py b/plugins/httpRequest/httpRequest.py index 0720db7..689c4bc 100644 --- a/plugins/httpRequest/httpRequest.py +++ b/plugins/httpRequest/httpRequest.py @@ -68,7 +68,7 @@ def run(typ,freq,data): logging.exception("cannot get HTTP response") finally: - logging.debug("close http-Connection") + logging.debug("close HTTP-Connection") httprequest.close() ########## User Plugin CODE ########## From f53bdb30f65cd1926eaf8c402a2a61791eef9e23 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 22 May 2015 22:58:43 +0200 Subject: [PATCH 4/5] debug return from plugin --- includes/alarmHandler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/alarmHandler.py b/includes/alarmHandler.py index 7a58dbe..8890ee4 100644 --- a/includes/alarmHandler.py +++ b/includes/alarmHandler.py @@ -10,4 +10,5 @@ def processAlarm(typ,freq,data): for name, plugin in globals.pluginList.items(): logging.debug("call Plugin: %s", name) plugin.run(typ,freq,data) + logging.debug("return from: %s", name) logging.debug("[END ALARM]") \ No newline at end of file From 989cb95e57aa3917f63dac803209387802b0b2e7 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 22 May 2015 22:59:33 +0200 Subject: [PATCH 5/5] update plugin_test.py to new methods --- plugin_test.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/plugin_test.py b/plugin_test.py index 49c6308..4981052 100644 --- a/plugin_test.py +++ b/plugin_test.py @@ -12,7 +12,8 @@ import os #for log mkdir import time #timestamp for doublealarm from includes import globals # Global variables -from includes import pluginloader +from includes import pluginLoader +from includes import alarmHandler #create new logger logger = logging.getLogger() @@ -49,15 +50,7 @@ except: logging.exception("cannot read config file") -try: - logging.debug("loading plugins") - pluginList = {} - for i in pluginloader.getPlugins(): - plugin = pluginloader.loadPlugin(i) - pluginList[i["name"]] = plugin - logging.debug("loading ready") -except: - logging.exception("cannot load Plugins") +pluginLoader.loadPlugins() # ----- Test Data ----- # @@ -75,11 +68,7 @@ while True: time.sleep(1) print "" - logging.debug("[ ALARM ]") - for name, plugin in pluginList.items(): - logging.debug("call Plugin: %s", name) - plugin.run(typ,"0",data) - logging.debug("[END ALARM]") + alarmHandler.processAlarm(typ,"0",data) except KeyboardInterrupt: logging.warning("Keyboard Interrupt")