-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
37 lines (32 loc) · 1.18 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
# coding:utf-8
# File Name: manage.py
# Created Date: 2018-02-26 10:43:45
# Last modified: 2018-04-11 13:57:41
# Author: yeyong
import os
from app.flask_init import create_app, db
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand
from werkzeug.utils import find_modules
models = find_modules("app.models")
models_class = set()
for model in models:
if not model in {"app.models.base", "app.models.user_role", "app.models.user_account", "app.models.role_permission"}:
name = "".join(map(lambda c: c.capitalize(), model.split(".")[-1].split("_")))
m = __import__(model, fromlist=[name])
models_class.add(getattr(m, name))
app = create_app(os.getenv("FLASK_ENV") or 'default')
manager = Manager(app)
migrate = Migrate(app, db)
def make_shell_context():
args = {k.__name__: k for k in models_class}
args.update(dict(app=app, db=db))
return args
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command("db", MigrateCommand)
if not app.debug:
import logging
app.logger.addHandler(logging.StreamHandler())
app.logger.setLevel(logging.INFO)
if __name__ == "__main__":
manager.run()