-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
56 lines (45 loc) · 1.56 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
#!venv/bin/python
# -*- coding: utf-8 -*-
import os
# 加载环境变量
if os.path.exists('.env'):
print('Importing environment from .env...')
for line in open('.env'):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]
from flask_script import Server, Manager, Shell
from flask_script.commands import ShowUrls, Clean
from flask_migrate import Migrate, MigrateCommand
from flask_sqlalchemy import SQLAlchemy
from vimage import create_app, db
from vimage.models import TextSet, ImageSet
from commands.initial import InitialSetting
from config import config
basedir = os.path.abspath(os.path.dirname(__file__))
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)
def make_shell_context():
return dict(app=app, db=db)
@manager.command
def test():
"""Run the unit test."""
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
# 常用操作命令
manager.add_command('shell', Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
manager.add_command('show-urls', ShowUrls())
# 清除工作目录中Python编译的.pyc和.pyo文件
manager.add_command('clean', Clean())
# 初始化系统命令
manager.add_command('initial', InitialSetting())
# 启动测试服务器
# Address: 120.132.59.206
# Name: dev.taihuoniao.com
server = Server(host='0.0.0.0', port=8080, use_debugger=True)
manager.add_command('server', server)
if __name__ == '__main__':
manager.run()