This repository has been archived by the owner on Sep 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
74 lines (67 loc) · 3.29 KB
/
main.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
67
68
69
70
71
72
73
74
#!/usr/bin/python
import tornado.ioloop, tornado.web, tornado.options, tornado.httpserver
import sys, os
import controller.base
#Load System Config from command line and config file
tornado.options.define("port", default=80, help="listening port", type=int)
tornado.options.define("addr", default="127.0.0.1", help="listening address")
tornado.options.define("debug", default=False, help="Whether the server is "\
"under the debug mode. CATUION IN PRODUCTION SERVER!"
, type=bool)
tornado.options.define("xheaders", default=False, help="If xheaders is True, "\
"we support the X-Real-Ip/X-Forwarded-For and X-Scheme/X-"\
"Forwarded-Proto headers, which override the remote IP and "\
"URI scheme/protocol for all requests. These headers are "\
"useful when running Tornado behind a reverse proxy or load balancer. "
, type=bool)
tornado.options.define("compress_response", default=False, help="Open it if "\
"you want to compress the response.", type=bool)
tornado.options.define("config_file", default="config.ini", help="Define "\
"the config file.")
tornado.options.define("document_location", default="documents", help="Redefine"\
" the location of your documents. DO NOT ADD SLASHES AFTER"\
" YOUR LOCATION!")
tornado.options.define("domain", default="localhost", help="URL displayed")
tornado.options.define("comment", default=False)
tornado.options.define("comment_js", default="")
tornado.options.define("google_analytics", default="", help="Fill if you have a google analysis script")
tornado.options.parse_command_line()
try:
a=open(tornado.options.options.config_file)
a.close()
tornado.options.parse_config_file(tornado.options.options.config_file)
except:
warning("Unable to use config file. Use default settings.")
#Load settings to var
setting = {
"debug":tornado.options.options.debug,
"compress_response": tornado.options.options.compress_response,
"default_handler_class": controller.base.NotFoundHandler,
"static_handler_class": controller.base.StaticBaseHandler,
"template_path": "template",
"static_path": "static",
}
# Route config
application = tornado.web.Application([
(r"^/$", "controller.page.IndexPage"),
(r"^/article\.aspx/((?:[\w\-!():.,\[\]]|(?:%20))+)$", "controller.article.ArticleHandler"),
(r"^/list\.aspx/*$", "controller.list.FirstPageHandler"),
(r"^/list\.aspx/(\d+)$", "controller.list.PageHandler"),
(r"^/page\.aspx/*$", "controller.page.SpecialPageListHandler"),
(r"^/page\.aspx/((?:[\w\-!():.,\[\]]|(?:%20))+)$", "controller.page.SpecialPageHandler")
], **setting)
# Server loop
if __name__ == "__main__":
try:
http_server = tornado.httpserver.HTTPServer(application,
xheaders=tornado.options.options.xheaders)
http_server.listen(
port=tornado.options.options.port,\
address=tornado.options.options.addr
)
tornado.ioloop.IOLoop.instance().start()
except:
import traceback
error(traceback.print_exc())
finally:
sys.exit(0)