forked from panoptes/PAWS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
105 lines (86 loc) · 3.83 KB
/
app.py
File metadata and controls
105 lines (86 loc) · 3.83 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Generic stuff
import logging
import os
import os.path
# Web stuff
import tornado
import tornado.options
from bokeh.server.server import Server
# Local video webstream related
from WebcamStreamer import WebcamStreamer
# Local web stuff
from handlers import base
from handlers import websockets
from ui import modules
# Main POCS code
from utils import database, load_module
from utils.config import load_config
tornado.options.define("port", default=8000, help="port", type=int)
#tornado.options.define("debug", default=True, help="debug mode")
#TODO TN THIS DOES NOT WORK: Traceback (most recent call last):
#tornado.options.Error: Option 'log-file-prefix' already defined in /[...]/lib/python3.6/site-packages/tornado/log.py
#tornado.options.define('log_file_prefix', default='/var/RemoteObservatory/logs/paws.log')
class WebAdmin(tornado.web.Application):
""" The main Application entry for our PANOPTES admin interface """
def __init__(self, config={}):
db = database.FileDB()
#db = database.FileDB(db_name='/var/RemoteObservatory/DB')
subscriber_name = config["paws_subscriber"]['module']
subscriber_module = load_module('Service.' + subscriber_name)
msg_subscriber = getattr(subscriber_module, subscriber_name)(
config=config["paws_subscriber"])
publisher_name = config["paws_publisher"]['module']
publisher_module = load_module('Service.' + publisher_name)
cmd_publisher = getattr(publisher_module, publisher_name)(
config=config["paws_publisher"])
if "webcam" in config["observatory"]:
wc = WebcamStreamer(config["observatory"]["webcam"])
wc.launch_webcam_stream_converter()
self._base_dir = f"{os.getenv('PAWS', default='/home/gnthibault/projects/PAWS')}"
name = config.setdefault('name', 'PAWS')
server = config.setdefault('server_url', '0.0.0.0')
server_url = f"{server}:{tornado.options.options.port}"
app_handlers = [
(r"/", base.MainHandler),
(r"/login", base.LoginHandler),
(r"/observations/(.*)", base.ObservationsHistoryHandler),
(r"/ws/(.*)", websockets.PanWebSocket),
]
settings = dict(
template_path=os.path.join(self._base_dir, "templates"),
static_path=os.path.join(self._base_dir, "static"),
xsrf_cookies=True,
cookie_secret="PANOPTES_SUPER_DOOPER_SECRET",
login_url="/login", # redirect() will go there
db=db,
msg_subscriber=msg_subscriber,
cmd_publisher=cmd_publisher,
config=config,
name=name,
server_url=server_url,
site_title=name,
ui_modules=modules,
port=tornado.options.options.port,
compress_response=True,
debug=True,
#debug=tornado.options.options.debug,
#log_to_stderr=True,
#log_file_prefix='/var/RemoteObservatory/logs/paws.log'
)
super().__init__(app_handlers, **settings)
if __name__ == '__main__':
# First instantiate main tornado infrastructure
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(WebAdmin(load_config()))
http_server.listen(tornado.options.options.port)
io_loop = tornado.ioloop.IOLoop.current()
# Now instantiate bokeh app
tornado_port = tornado.options.options.port
bokeh_server = Server({'/bokeh_weather': base.bokeh_weather_app,
'/bokeh_guiding': base.bokeh_guiding_app},
io_loop=io_loop,
allow_websocket_origin=[f"localhost:{tornado_port}",
f"localhost:5006"])
# Launch the whole thing
print(f"Starting PAWS on port {tornado_port}")
io_loop.start()