-
Notifications
You must be signed in to change notification settings - Fork 45
/
manage.py
40 lines (32 loc) · 1.02 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
from os import environ, path
from gloss import create_app, db
from gloss.models import Definition, Interaction
from flask_script import Manager, prompt_bool
from flask_migrate import Migrate, MigrateCommand
# grab environment variables from the .env file if it exists
if path.exists('.env'):
for line in open('.env'):
var = line.strip().split('=')
if len(var) == 2:
environ[var[0]] = var[1]
app = create_app(environ)
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
@manager.shell
def make_shell_context():
return dict(app=app, db=db, Definition=Definition, Interaction=Interaction)
@manager.command
def runtests():
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=1).run(tests)
@manager.command
def dropdb():
if prompt_bool("Are you sure you want to lose all your data?"):
db.drop_all()
@manager.command
def createdb():
db.create_all()
if __name__ == '__main__':
manager.run()