eventman_server.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. """Event Man(ager)
  3. Your friendly manager of attendants at a conference.
  4. """
  5. import os
  6. import tornado.httpserver
  7. import tornado.ioloop
  8. import tornado.options
  9. from tornado.options import define, options
  10. import tornado.web
  11. from tornado import gen
  12. class MainHandler(tornado.web.RequestHandler):
  13. @gen.coroutine
  14. def get(self):
  15. self.redirect('/static/html/index.html')
  16. def main():
  17. define("port", default=5242, help="run on the given port", type=int)
  18. define("config", help="read configuration file",
  19. callback=lambda path: tornado.options.parse_config_file(path, final=False))
  20. define("debug", default=False, help="run in debug mode")
  21. tornado.options.parse_command_line()
  22. application = tornado.web.Application([
  23. (r"/(?:index.html)?", MainHandler),
  24. ],
  25. template_path=os.path.join(os.path.dirname(__file__), "templates"),
  26. static_path=os.path.join(os.path.dirname(__file__), "static"),
  27. debug=options.debug)
  28. http_server = tornado.httpserver.HTTPServer(application)
  29. http_server.listen(options.port)
  30. tornado.ioloop.IOLoop.instance().start()
  31. if __name__ == '__main__':
  32. main()