mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-01-20 15:20:16 +01:00
insert debug msg, edit pluginloader.py
This commit is contained in:
parent
367e68e5fe
commit
0bef06c2ad
|
|
@ -6,7 +6,7 @@ import time
|
|||
import pluginloader
|
||||
|
||||
import os #for absolute path: os.path.dirname(os.path.abspath(__file__))
|
||||
import ConfigParser #for parse the config file
|
||||
import configparser #for parse the config file
|
||||
|
||||
import logging
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ logger = logging.getLogger()
|
|||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
#set log string format
|
||||
formatter = logging.Formatter('%(asctime)s - %(levelname)s: %(message)s', '%d.%m.%Y %I:%M:%S')
|
||||
formatter = logging.Formatter('%(asctime)s - %(module)s - %(levelname)s: %(message)s', '%d.%m.%Y %I:%M:%S')
|
||||
|
||||
#create a file loger
|
||||
fh = logging.FileHandler('boswatch.log', 'w')
|
||||
|
|
@ -39,11 +39,11 @@ logger.addHandler(ch)
|
|||
#exception - error with exception message in log
|
||||
#critical - critical error, program exit
|
||||
|
||||
#ConfigParser
|
||||
#configparser
|
||||
try:
|
||||
logging.debug("reading config file")
|
||||
script_path = os.path.dirname(os.path.abspath(__file__))
|
||||
globals.config = ConfigParser.ConfigParser()
|
||||
globals.config = configparser.ConfigParser()
|
||||
globals.config.read(script_path+"/config/config.ini")
|
||||
except:
|
||||
logging.exception("cannot read config file")
|
||||
|
|
@ -52,9 +52,13 @@ except:
|
|||
data = {"ric":"1234567", "function":"1", "msg":"Hello World!"}
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
logging.info("Alarm!")
|
||||
try:
|
||||
time.sleep(1)
|
||||
logging.info("Alarm!")
|
||||
for i in pluginloader.getPlugins():
|
||||
plugin = pluginloader.loadPlugin(i)
|
||||
logging.debug(i["name"] + " Plugin called")
|
||||
plugin.run("POC","80000000",data)
|
||||
plugin = pluginloader.loadPlugin(i)
|
||||
logging.debug(i["name"] + " Plugin called")
|
||||
plugin.run("POC","80000000",data)
|
||||
except:
|
||||
logging.exception("Cannot Throw Modules")
|
||||
exit()
|
||||
|
|
@ -10,26 +10,27 @@ PluginFolder = "./plugins"
|
|||
MainModule = "__init__"
|
||||
|
||||
def getPlugins():
|
||||
plugins = []
|
||||
possibleplugins = os.listdir(PluginFolder)
|
||||
for i in possibleplugins:
|
||||
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 MainModule + ".py" in os.listdir(location):
|
||||
continue
|
||||
logging.debug("found plugin: "+i)
|
||||
plugins = []
|
||||
possibleplugins = os.listdir(PluginFolder)
|
||||
for i in possibleplugins:
|
||||
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 MainModule + ".py" in os.listdir(location):
|
||||
continue
|
||||
logging.debug("found plugin: "+i)
|
||||
|
||||
# is the plugin enabled in the config-file?
|
||||
try:
|
||||
usePlugin = int(globals.config.get("Module", i))
|
||||
except: #no entry for plugin found in config-file, skip
|
||||
continue
|
||||
logging.debug("use Plugin: "+str(usePlugin))
|
||||
if usePlugin:
|
||||
info = imp.find_module(MainModule, [location])
|
||||
plugins.append({"name": i, "info": info})
|
||||
logging.debug("append Plugin: "+i)
|
||||
return plugins
|
||||
# is the plugin enabled in the config-file?
|
||||
try:
|
||||
usePlugin = int(globals.config.get("Module", i))
|
||||
except: #no entry for plugin found in config-file, skip
|
||||
logging.warning("Plugin not in config: "+i)
|
||||
|
||||
logging.debug("use Plugin: "+str(usePlugin))
|
||||
if usePlugin:
|
||||
info = imp.find_module(MainModule, [location])
|
||||
plugins.append({"name": i, "info": info})
|
||||
logging.debug("append Plugin: "+i)
|
||||
return plugins
|
||||
|
||||
def loadPlugin(plugin):
|
||||
return imp.load_module(MainModule, *plugin["info"])
|
||||
return imp.load_module(MainModule, *plugin["info"])
|
||||
9
plugin_test/plugins/none/__init__.py
Normal file
9
plugin_test/plugins/none/__init__.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: cp1252 -*-
|
||||
|
||||
import logging # Global logger
|
||||
import globals # Global variables
|
||||
|
||||
def run(typ,freq,data):
|
||||
logging.info("Nothing to do")
|
||||
|
||||
|
|
@ -8,5 +8,7 @@ def run(typ,freq,data):
|
|||
try:
|
||||
if typ == "ZVEI":
|
||||
logging.info("ZVEI: %s wurde auf %s empfangen!", data["zvei"],freq)
|
||||
else:
|
||||
logging.warning(typ + " not supportet")
|
||||
except:
|
||||
logging.exception("Error in Template Plugin")
|
||||
Loading…
Reference in a new issue