/
manage.py
executable file
·77 lines (59 loc) · 1.98 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
#!/usr/bin/env python
import os
from flask_script import Manager, Server, prompt_choices
from flask_script.commands import ShowUrls, Clean
from flask_migrate import Migrate, MigrateCommand
from hospitalSystem import create_app
from hospitalSystem.warmup import setup_db, update_perms, createsuperuser
from hospitalSystem.models import db, User
from hospitalSystem.settings import config_by_name
# default to dev config because no one should use this in
# production anyway
app = create_app(config_by_name[(os.getenv('BOILERPLATE_ENV') or 'dev')])
manager = Manager(app)
@manager.shell
def make_shell_context():
""" Creates a python REPL with several default imports
in the context of the app
"""
return dict(app=app, db=db, User=User)
@manager.command
def create_db():
'''
create database and tables
'''
setup_db(app, db)
@manager.command
def babel():
""" to setup a new language translation.
`pybabel init -i ./babel/messages.pot -d hospitalSystem/translations -l zh`
"""
choices = (
("update", "extract text"),
("compile", "compile the translations")
)
op = prompt_choices("operation", choices=choices, resolve=str,
default="update")
if op == 'update':
os.system(
'pybabel extract -F ./babel/babel.cfg -k lazy_gettext '
'-o ./babel/messages.pot hospitalSystem'
)
os.system(
'pybabel update -i ./babel/messages.pot -d hospitalSystem/translations'
)
elif op == 'compile':
os.system('pybabel compile -d hospitalSystem/translations')
@manager.command
def create_admin():
createsuperuser(db)
@manager.command
def update_db():
update_perms(db)
if __name__ == "__main__":
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
manager.add_command("server", Server(host='0.0.0.0'))
manager.add_command("show_urls", ShowUrls())
manager.add_command("clean", Clean())
manager.run()