BOSWatch/plugin_test.py

90 lines
2.3 KiB
Python
Raw Normal View History

2015-05-18 09:04:16 +02:00
#!/usr/bin/python
# -*- coding: cp1252 -*-
2015-05-22 11:44:50 +02:00
###########################################################################
# Use this as a simple Plugin Loading Tool to test your own Coded Plugins #
###########################################################################
2015-05-18 09:04:16 +02:00
import logging
import ConfigParser #for parse the config file
2015-05-22 11:44:50 +02:00
import os #for log mkdir
import time #timestamp for doublealarm
2015-05-18 21:49:03 +02:00
from includes import globals # Global variables
from includes import pluginloader
2015-05-18 21:49:03 +02:00
#create new logger
2015-05-18 12:28:18 +02:00
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
#set log string format
formatter = logging.Formatter('%(asctime)s - %(module)-12s [%(levelname)-8s] %(message)s', '%d.%m.%Y %H:%M:%S')
2015-05-18 12:28:18 +02:00
#create a display loger
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG) #log level >= info
2015-05-18 12:28:18 +02:00
ch.setFormatter(formatter)
logger.addHandler(ch)
#https://docs.python.org/2/howto/logging.html#logging-basic-tutorial
#log levels
2015-05-18 12:28:18 +02:00
#----------
#debug - debug messages only for log
2015-05-18 22:10:23 +02:00
#info - information for normal display
#warning
#error - normal error - program goes further
2015-05-18 21:49:03 +02:00
#exception - error with exception message in log
2015-05-18 14:49:10 +02:00
#critical - critical error, program exit
2015-05-18 12:28:18 +02:00
2015-05-22 11:44:50 +02:00
globals.script_path = os.path.dirname(os.path.abspath(__file__))
try:
2015-05-22 11:44:50 +02:00
logging.debug("reading config file")
2015-05-19 15:42:25 +02:00
globals.config = ConfigParser.ConfigParser()
2015-05-22 11:44:50 +02:00
globals.config.read(globals.script_path+"/config/config.ini")
for key,val in globals.config.items("Plugins"):
logging.debug(" - %s = %s", key, val)
except:
logging.exception("cannot read config file")
2015-05-18 12:28:18 +02:00
2015-05-22 11:44:50 +02:00
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")
2015-05-22 11:44:50 +02:00
# ----- Test Data ----- #
#typ = "FMS"
#data = {"fms":"12345678", "status":"2", "direction":"1", "tsi":"III"}
2015-05-22 11:44:50 +02:00
typ = "ZVEI"
data = {"zvei":"12345"}
#typ = "POC"
#data = {"ric":"1234567", "function":"1", "msg":"Hello World!, "bitrate":"1200"}
2015-05-18 09:04:16 +02:00
while True:
2015-05-19 07:29:39 +02:00
try:
time.sleep(1)
2015-05-22 11:44:50 +02:00
print ""
logging.debug("[ ALARM ]")
for name, plugin in pluginList.items():
logging.debug("call Plugin: %s", name)
2015-05-22 11:44:50 +02:00
plugin.run(typ,"0",data)
logging.debug("[END ALARM]")
except KeyboardInterrupt:
logging.warning("Keyboard Interrupt")
exit()
2015-05-19 07:29:39 +02:00
except:
2015-05-22 11:44:50 +02:00
logging.exception("unknown error")
exit()