-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.py
executable file
·59 lines (44 loc) · 1.17 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
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import os
import unittest
from app import create_app, db
from app.route import blueprint
from flask_cors import CORS
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
# 获取环境变量
env = os.getenv('RUNTIME_ENV') or 'dev'
# 创建 app
app = create_app(env)
# 加载蓝图
app.register_blueprint(blueprint)
# 创建 manager
manager = Manager(app)
# 创建 migrate
migrate = Migrate(app, db)
# 新增 db 到 manager 中
manager.add_command('db', MigrateCommand)
# 跨域请求
CORS(app, supports_credentials=True)
@manager.command
def run():
""" runs user permission and auth service """
db.create_all()
app.run(debug=True, host='0.0.0.0', port=5000)
@manager.command
def create():
""" runs create db all data """
db.drop_all()
db.create_all()
db.session.commit()
@manager.command
def test():
""" runs the unit tests """
tests = unittest.TestLoader().discover('app/test', pattern='test*.py')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
return 0
return 1
if __name__ == '__main__':
manager.run()