|
19 | 19 | # along with this program. If not, see http://www.gnu.org/licenses/. |
20 | 20 | # |
21 | 21 | import os |
| 22 | +import time |
22 | 23 |
|
23 | 24 | from rest.domain import DomainInfo, DomainProperties |
24 | 25 | from rest.application import Applications |
|
33 | 34 | import tornado.httpserver |
34 | 35 | import tornado.web |
35 | 36 | import tornado.websocket |
36 | | -from tornado import ioloop |
| 37 | +from tornado import ioloop, gen |
37 | 38 |
|
38 | 39 | from model.redhawk import Redhawk |
39 | 40 |
|
@@ -73,10 +74,12 @@ def __init__(self, *args, **kwargs): |
73 | 74 | handlers = [ |
74 | 75 | (r"/apps/(.*)/$", IndexHandler), |
75 | 76 | (r"/apps/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(cwd, "apps")}), |
| 77 | + (r"/client/(.*)/$", IndexHandler), |
76 | 78 | (r"/client/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(cwd, "client")}), |
77 | 79 |
|
78 | 80 | # Top-level Event Handler REDHAWK status channel and event channel system |
79 | 81 | # The event handler sorts out what to do for us. |
| 82 | + (_BASE_URL + _LIST + r"$", BaseInfo), |
80 | 83 | (_BASE_URL + r'/(redhawk|events)', EventHandler, dict(redhawk=redhawk, _ioloop=_ioloop)), |
81 | 84 |
|
82 | 85 | # Domains, wild guess on the eventChannels one. |
@@ -143,12 +146,26 @@ class IndexHandler(tornado.web.RequestHandler): |
143 | 146 | def get(self, path): |
144 | 147 | self.render("apps/"+path+"/index.html") |
145 | 148 |
|
| 149 | +class BaseInfo(tornado.web.RequestHandler): |
| 150 | + @tornado.web.asynchronous |
| 151 | + @gen.engine |
| 152 | + def get(self, *args): |
| 153 | + self.write("<h1>The rest-python server is running!</h1>") |
| 154 | + self.flush() |
| 155 | + yield gen.Task(ioloop.IOLoop.instance().add_timeout, time.time()+1) |
| 156 | + self.write("<p>Now try this URL: {0}</p>".format(_DOMAIN_PATH)) |
| 157 | + self.finish() |
146 | 158 |
|
147 | 159 | def main(): |
148 | 160 | tornado.options.parse_command_line() |
149 | 161 | application = Application(debug=options.debug) |
150 | 162 | application.listen(options.port) |
151 | | - ioloop.IOLoop.instance().start() |
| 163 | + |
| 164 | + try: |
| 165 | + ioloop.IOLoop.instance().start() |
| 166 | + except KeyboardInterrupt: |
| 167 | + pass |
| 168 | + |
152 | 169 |
|
153 | 170 | if __name__ == '__main__': |
154 | 171 | main() |
|
0 commit comments