-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhello.py
64 lines (53 loc) · 1.56 KB
/
hello.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import options
import argparse
import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.options
from log import logger
from options.url import handlers
from anwen.uimodules import EntryModule, UseradminModule
options.web_server.update(
dict(ui_modules={"Entry": EntryModule, "Useradmin": UseradminModule},))
application = tornado.web.Application(handlers, **options.web_server)
def create_db():
import db.models
db.models.main()
logger.info('create db success')
def launch():
tornado.locale.load_translations(options.web_server['locale_path'])
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(application, xheaders=True)
http_server.listen(options.port)
logger.info('Server started on %s' % options.port)
tornado.ioloop.IOLoop.instance().start()
parser = argparse.ArgumentParser(description='Anwen Server')
parser.add_argument(
'-c', '--create-db',
dest='create_db',
action='store_const',
const=create_db,
help='create database'
)
parser.add_argument(
'-t', '--test',
dest='run_tests',
action='store_const',
const=True,
default=False,
help='run tests'
)
if __name__ == '__main__':
args = parser.parse_args()
if args.run_tests:
import tests
import sys
locals()['all'] = tests.all
sys.argv = sys.argv[:1]
tests.main()
elif args.create_db:
create_db()
else:
launch()