-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.py
66 lines (43 loc) · 1.59 KB
/
server.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
import tornado
import pyrestful
import services
import sys
from services.dome_service import DomeService
from services.config import ascomConfig, initConfig, getConfig
Services = []
def instanciateDriver(config):
if not('driver_instance' in config):
config['driver_instance'] = None
driver = config['driver_instance']
if (driver is None):
if (config['device_type'] == 'dome'):
# TODO dynamically instanciate the drivers
if (config['device_driver'] == 'MyASCOMDomeDriver'):
from ASCOMDriver.MyDomeDriver import MyDomeDriver
driver = MyDomeDriver() # TODO pass driver_config as well ?
config['driver_instance'] = driver
return driver
def instanciateRestHandler(config):
if (config['device_type'] == 'dome'):
return DomeService
return None
def getRestHandlers():
# instanciate all necessary services defined in the config file
handlers = []
for config in services.config.ascomConfig['drivers']:
instanciateDriver(config)
handler = instanciateRestHandler(config)
if (not(handler is None)):
handlers.append(handler)
return handlers
if __name__ == '__main__':
try:
initConfig()
handlers = getRestHandlers()
print("Start the service")
app = pyrestful.rest.RestService(handlers)
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(11111)
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
print("\nStop the service")