2020-09-23 13:34:54 -04:00
|
|
|
################################################################################
|
|
|
|
|
#
|
|
|
|
|
# Copyright (c) 2019, the Perspective Authors.
|
|
|
|
|
#
|
|
|
|
|
# This file is part of the Perspective library, distributed under the terms of
|
|
|
|
|
# the Apache License 2.0. The full license can be found in the LICENSE file.
|
|
|
|
|
#
|
2020-09-05 14:17:45 -04:00
|
|
|
import os
|
|
|
|
|
import os.path
|
|
|
|
|
import logging
|
|
|
|
|
import tornado.websocket
|
|
|
|
|
import tornado.web
|
|
|
|
|
import tornado.ioloop
|
2020-09-18 02:17:53 -04:00
|
|
|
import threading
|
2020-09-05 14:17:45 -04:00
|
|
|
|
|
|
|
|
from perspective import Table, PerspectiveManager, PerspectiveTornadoHandler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
here = os.path.abspath(os.path.dirname(__file__))
|
2020-09-08 12:08:57 -04:00
|
|
|
file_path = os.path.join(
|
2020-09-18 02:17:53 -04:00
|
|
|
here, "..", "..", "node_modules", "superstore-arrow", "superstore.arrow"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def perspective_thread(manager):
|
|
|
|
|
"""Perspective application thread starts its own tornado IOLoop, and
|
|
|
|
|
adds the table with the name "data_source_one", which will be used
|
|
|
|
|
in the front-end."""
|
|
|
|
|
psp_loop = tornado.ioloop.IOLoop()
|
|
|
|
|
manager.set_loop_callback(psp_loop.add_callback)
|
|
|
|
|
with open(file_path, mode="rb") as file:
|
|
|
|
|
table = Table(file.read(), index="Row ID")
|
|
|
|
|
manager.host_table("data_source_one", table)
|
|
|
|
|
psp_loop.start()
|
2020-09-05 14:17:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_app():
|
2020-09-18 02:17:53 -04:00
|
|
|
manager = PerspectiveManager()
|
|
|
|
|
|
|
|
|
|
thread = threading.Thread(target=perspective_thread, args=(manager,))
|
|
|
|
|
thread.daemon = True
|
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
|
|
return tornado.web.Application(
|
|
|
|
|
[
|
|
|
|
|
(
|
|
|
|
|
r"/websocket",
|
|
|
|
|
PerspectiveTornadoHandler,
|
|
|
|
|
{"manager": manager, "check_origin": True},
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
r"/node_modules/(.*)",
|
|
|
|
|
tornado.web.StaticFileHandler,
|
|
|
|
|
{"path": "../../node_modules/@finos/"},
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
r"/(.*)",
|
|
|
|
|
tornado.web.StaticFileHandler,
|
|
|
|
|
{"path": "./", "default_filename": "index.html"},
|
|
|
|
|
),
|
2020-09-23 20:11:40 -04:00
|
|
|
]
|
2020-09-18 02:17:53 -04:00
|
|
|
)
|
2020-09-05 14:17:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
app = make_app()
|
|
|
|
|
app.listen(8080)
|
|
|
|
|
logging.critical("Listening on http://localhost:8080")
|
|
|
|
|
loop = tornado.ioloop.IOLoop.current()
|
|
|
|
|
loop.start()
|