forked from juggie/AlarmServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alarmserver.py
executable file
·82 lines (65 loc) · 2 KB
/
alarmserver.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
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python
## Alarm Server
## Supporting Envisalink 2DS/3
## Contributors: https://github.com/juggie/AlarmServer/graphs/contributors
## Compatibility: https://github.com/juggie/AlarmServer/wiki/Compatibility
##
## This code is under the terms of the GPL v3 license.
#python standard modules
import sys, getopt, os, glob
#alarm server modules
from core.config import config
from core.state import state
from core.events import events
from core import logger
from core import httpslistener
from core import envisalink
from core import envisalinkproxy
#TODO: move elsewhere
import tornado.ioloop
def main(argv):
#welcome message
logger.info('Alarm Server Starting')
#set default config
conffile='alarmserver.cfg'
try:
opts, args = getopt.getopt(argv, "c:", ["config="])
except getopt.GetoptError:
sys.exit(2)
for opt, arg in opts:
if opt in ("-c", "--config"):
conffile = arg
#load config
config.load(conffile)
#start logger
if config.LOGTOFILE == True:
logger.start(config.LOGFILE)
else:
logger.start()
#enable the state
state.init()
#set version
state.setVersion(0.3)
#start envisalink client
alarmclient = envisalink.Client()
#start envisalink proxy
alarmproxy = envisalinkproxy.Proxy()
#start https server
if config.HTTPS == True:
httpsserver = httpslistener.start()
#start http server
if config.HTTP == True:
httpserver = httpslistener.start(https = False)
#load plugins - TODO: make this way better
currpath = os.path.dirname(os.path.abspath(__file__))
plugins = glob.glob(currpath+"/plugins/*.py")
for p in plugins:
if str.find(p, '__init__.py') != -1: continue
base=os.path.basename(p)
name=os.path.splitext(base)[0]
exec "from plugins import %s" % name
exec "%s.init()" % name
#start tornado ioloop
tornado.ioloop.IOLoop.instance().start()
if __name__=="__main__":
main(sys.argv[1:])