From 0849672cbef17d6cf06f725a5dfbcbc753d412d5 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 22 May 2015 22:40:44 +0200 Subject: [PATCH] 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