-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
executable file
·88 lines (66 loc) · 2.31 KB
/
manage.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
import argparse
import sys
import os
import tornado.httpserver
import tornado.ioloop
import tornado.web
ADMIN_TYPE = 2
def main():
parser = argparse.ArgumentParser()
cmdparsers = parser.add_subparsers(dest="command")
# launch
launch_parser = cmdparsers.add_parser('launch')
launch_parser.add_argument('-i', '--ipaddr', help='bind instance to ip')
launch_parser.add_argument('-p', '--port', help='bind instance to port')
# create admin
admin_parser = cmdparsers.add_parser('createadmin')
# create module
module_parser = cmdparsers.add_parser('createmodule')
module_parser.add_argument('-n', '--name', help='module name to create')
args = parser.parse_args()
cmd = globals()[args.command]
cmd(args)
def createmodule(args):
# Create module directory structure
print "Create the module",
if args.name:
print args.name
def createadmin(args):
from app import settings
from hashlib import md5
if settings.connection.User.find_one({'usertype':ADMIN_TYPE}):
print "An administrator already exists in the database."; return
email = raw_input("Enter the e-mail address: ")
pass1 = raw_input("Enter the password: ")
pass2 = raw_input("Confirm password: ")
if pass1 != pass2:
print "Passwords do not match"; return
admin_user = settings.connection.User()
admin_user.usertype = ADMIN_TYPE
admin_user.set_password(pass1)
admin_user.name = u'Administrator'
admin_user.email = unicode(email)
admin_user.save()
print "Administrator user created : %s" % (email)
def launch(args):
from app import tornapp
if args.port:
tornapp.settings['instance_port'] = int(args.port)
if args.ipaddr:
tornapp.settings['instance_ipv4'] = str(args.ipaddr)
print "Launching Tornado %s:%s" % (
tornapp.settings['instance_ipv4'],
tornapp.settings['instance_port']
)
start_instance(tornapp)
def start_instance(application):
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(
application.settings.get('instance_port'),
address=application.settings.get('instance_ipv4')
)
try: tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt: pass
if __name__ == "__main__":
main()