BOSWatch/plugin_test/plugin_test.py

60 lines
1.6 KiB
Python
Raw Normal View History

2015-05-18 09:04:16 +02:00
#!/usr/bin/python
# -*- coding: cp1252 -*-
import globals # Global variables
2015-05-18 09:04:16 +02:00
import time
import pluginloader
import os #for absolute path: os.path.dirname(os.path.abspath(__file__))
import ConfigParser #for parse the config file
import logging
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 - %(levelname)s: %(message)s', '%d.%m.%Y %I:%M:%S')
#create a file loger
fh = logging.FileHandler('boswatch.log', 'w')
fh.setLevel(logging.DEBUG) #log level >= Debug
fh.setFormatter(formatter)
logger.addHandler(fh)
#create a display loger
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR) #log level >= Error
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 21:49:03 +02:00
#info - inormation 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
try:
2015-05-18 21:49:03 +02:00
logging.debug("reading config file")
script_path = os.path.dirname(os.path.abspath(__file__))
globals.config = ConfigParser.ConfigParser()
globals.config.read(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!"}
2015-05-18 12:28:18 +02:00
2015-05-18 09:04:16 +02:00
while True:
time.sleep(1)
logging.info("Alarm!")
2015-05-18 09:04:16 +02:00
for i in pluginloader.getPlugins():
2015-05-18 15:32:06 +02:00
logging.debug("Load Plugin: " + i["name"])
2015-05-18 09:04:16 +02:00
plugin = pluginloader.loadPlugin(i)
plugin.run("POC","80000000",data)