-
Notifications
You must be signed in to change notification settings - Fork 59
/
manager.py
71 lines (58 loc) · 2.04 KB
/
manager.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
#!/usr/bin/env python
#coding=utf-8
import uuid
import tornado.httpserver
import tornado.ioloop
import tornado.options
from tornado.options import define, options
from pypress import Application
from pypress.models import *
from pypress.database import db
define("cmd", default='runserver',
metavar="runserver|createall|dropall|createcode",
help=("Default use runserver"))
define("port", default=9000, help="default: 9000, required runserver", type=int)
define("num", default=1, help="number of create codes. required createcode", type=int)
define("role", default='admin', metavar="admin|moderator|member", help="required createcode")
def main():
tornado.options.parse_command_line()
if options.cmd == 'runserver':
print 'server started. port %s' % options.port
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
elif options.cmd == 'createall':
"Creates database tables"
db.create_all()
print 'create all [ok]'
elif options.cmd == 'dropall':
"Drops all database tables"
db.drop_all()
print 'drop all [ok]'
elif options.cmd == 'createcode':
codes = []
usercodes = []
for i in range(options.num):
code = unicode(uuid.uuid4()).split('-')[0]
codes.append(code)
usercode = UserCode()
usercode.code = code
if options.role == "admin":
usercode.role = User.ADMIN
elif options.role == "moderator":
usercode.role = User.MODERATOR
else:
usercode.role = User.MEMBER
usercodes.append(usercode)
if options.num==1:
db.session.add(usercode)
else:
db.session.add_all(usercodes)
db.session.commit()
print "Sign up code:"
for i in codes:
print i
else:
print 'error cmd param: python manager.py --help'
if __name__=='__main__':
main()