BOSWatch/plugin_test.py

70 lines
1.7 KiB
Python
Raw Normal View History

2015-05-18 09:04:16 +02:00
#!/usr/bin/python
# -*- coding: cp1252 -*-
import time
import pluginloader
import os #for absolute path: os.path.dirname(os.path.abspath(__file__))
import logging
import globals
import ConfigParser #for parse the config file
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
#ConfigParser
logging.debug("reading config file")
try:
2015-05-19 15:42:25 +02:00
globals.config = ConfigParser.ConfigParser()
globals.config.read(globals.script_path+"./config/config.ini")
except:
2015-05-18 21:49:03 +02:00
logging.exception("cannot read config file")
2015-05-18 12:28:18 +02:00
data = {"zvei":"12345"}
#data = {"ric":"1234567", "function":"1", "msg":"Hello World!"}
logging.debug("Load Plugins...")
pluginList = {}
for i in pluginloader.getPlugins():
plugin = pluginloader.loadPlugin(i)
pluginList[i["name"]] = plugin
logging.debug("All loaded...")
2015-05-18 09:04:16 +02:00
while True:
2015-05-19 07:29:39 +02:00
try:
time.sleep(1)
logging.info(" = = = = = = = = = ")
2015-05-19 07:29:39 +02:00
logging.info("Alarm!")
for name, plugin in pluginList.items():
logging.debug("call Plugin: %s", name)
plugin.run("ZVEI","0",data)
2015-05-19 07:29:39 +02:00
except:
logging.exception("Cannot Throw Modules")
exit()