-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanage.py
executable file
Β·61 lines (47 loc) Β· 1.64 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
#!/usr/bin/env python
"""Module containing app's entry point, testing and migration commands."""
import os
import unittest
from app.base import database, new_app
from app.models import bucketlist, profile, user
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager, Shell, prompt_bool
app = new_app(enviroment=os.environ.get('APP_SETTINGS') or "default")
manager = Manager(app)
migrate = Migrate(app, database)
@manager.command
def drop_database():
"""Drop database tables."""
if prompt_bool("Are you sure you want to lose all your data"):
try:
database.drop_all()
print("Dropped all tables susscefully.")
except Exception:
print("Failed, make sure your database server is running!")
@manager.command
def create_database():
"""Create database tables from sqlalchemy models."""
try:
database.create_all()
print("Created tables susscefully.")
except Exception:
print("Failed, make sure your database server is running!")
@manager.command
def test():
"""Run tests."""
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
def shell_context():
"""Make a shell context available with defined Classess."""
return dict(
app=new_app,
User=user.User,
UserSchema=user.UserSchema,
Item=bucketlist.Item,
Bucket=bucketlist.Bucket,
Profile=profile.Profile,
database=database)
manager.add_command("shell", Shell(make_context=shell_context))
manager.add_command("database", MigrateCommand)
if __name__ == '__main__':
manager.run()