forked from Schrolli91/BOSWatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin_test.py
70 lines (53 loc) · 1.65 KB
/
plugin_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/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
#create new logger
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')
#create a display loger
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG) #log level >= info
ch.setFormatter(formatter)
logger.addHandler(ch)
#https://docs.python.org/2/howto/logging.html#logging-basic-tutorial
#log levels
#----------
#debug - debug messages only for log
#info - information for normal display
#warning
#error - normal error - program goes further
#exception - error with exception message in log
#critical - critical error, program exit
#ConfigParser
logging.debug("reading config file")
try:
globals.config = ConfigParser.ConfigParser()
globals.config.read(globals.script_path+"./config/config.ini")
except:
logging.exception("cannot read config file")
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...")
while True:
try:
time.sleep(1)
logging.info(" = = = = = = = = = ")
logging.info("Alarm!")
for name, plugin in pluginList.items():
logging.debug("call Plugin: %s", name)
plugin.run("ZVEI","0",data)
except:
logging.exception("Cannot Throw Modules")
exit()