-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
86 lines (68 loc) · 1.91 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
# coding: utf-8
import os
# import daemon
from flask.ext.script import Manager
import random
from weshop import create_app
from weshop.models import db, User
from flask.ext.migrate import Migrate, MigrateCommand
app = create_app()
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
@manager.command
def run():
"""启动网站"""
app.run(host="localhost", port=5000)
@manager.command
def run_80():
"""启动网站"""
app.run(host="0.0.0.0", port=80,threaded=True)
@manager.command
def create_ucode():
"""生成5-6位用户id,u_code"""
users = User.query
for u in users:
u_code = (random.randint(10000, 1000000))
user = User.query.filter(User.id == u.id).first()
while (user.u_code == u_code):
print (user.id)
u_code = (random.randint(10000, 1000000))
user.u_code = u_code
print ("user_id:" + str(u.id) + " u_code:" + str(u_code))
db.session.add(user)
db.session.commit()
@manager.command
def create_admin():
"""Create admin."""
user = User(role='admin', name="admin", email="admin@qq.com", mobile="18812345678")
user.password = "admin"
user.hash_password()
user.gene_token()
db.session.add(user)
db.session.commit()
@manager.command
def createdb():
"""Create database."""
db.create_all()
@manager.command
def delete_version():
"""Create database."""
version=AlembicVersion.query.first()
db.session.delete(version)
db.session.commit()
@manager.command
def reset_users_token():
with app.app_context():
for u in User.query:
u.gene_token()
db.session.add(u)
db.session.commit()
@manager.command
def clean_exercises():
"""删除图片文件不存在的"""
with daemon.DaemonContext():
with app.app_context():
pass
if __name__ == "__main__":
manager.run()