|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
|
|
3
|
|
|
import os |
|
4
|
|
|
|
|
5
|
|
|
from flask_script import Manager, Server |
|
6
|
|
|
from flask_script.commands import ShowUrls, Clean |
|
7
|
|
|
from flask_migrate import Migrate, MigrateCommand |
|
8
|
|
|
from sugarloaf import create_app |
|
9
|
|
|
from sugarloaf.models import db, User, Trail, TrailStatus, Lift, LiftStatus, SnowReporter, Area, DailyReport |
|
10
|
|
|
|
|
11
|
|
|
# default to dev config because no one should use this in |
|
12
|
|
|
# production anyway |
|
13
|
|
|
env = os.environ.get('SUGARLOAF_ENV', 'dev') |
|
14
|
|
|
app = create_app('sugarloaf.settings.%sConfig' % env.capitalize()) |
|
15
|
|
|
|
|
16
|
|
|
migrate = Migrate(app, db) |
|
17
|
|
|
|
|
18
|
|
|
manager = Manager(app) |
|
19
|
|
|
manager.add_command("server", Server()) |
|
20
|
|
|
manager.add_command("show-urls", ShowUrls()) |
|
21
|
|
|
manager.add_command("clean", Clean()) |
|
22
|
|
|
manager.add_command('db', MigrateCommand) |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
@manager.shell |
|
26
|
|
|
def make_shell_context(): |
|
27
|
|
|
""" Creates a python REPL with several default imports |
|
28
|
|
|
in the context of the app |
|
29
|
|
|
""" |
|
30
|
|
|
|
|
31
|
|
|
return dict(app=app, db=db, User=User, |
|
32
|
|
|
Trail=Trail, TrailStatus=TrailStatus, |
|
33
|
|
|
Lift=Lift, LiftStatus=LiftStatus, |
|
34
|
|
|
Area=Area, |
|
35
|
|
|
SnowReporter=SnowReporter, |
|
36
|
|
|
DailyReport=DailyReport) |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
@manager.command |
|
40
|
|
|
def createdb(): |
|
41
|
|
|
""" Creates a database with all of the tables defined in |
|
42
|
|
|
your SQLAlchemy models |
|
43
|
|
|
""" |
|
44
|
|
|
|
|
45
|
|
|
db.create_all() |
|
46
|
|
|
|
|
47
|
|
|
if __name__ == "__main__": |
|
48
|
|
|
manager.run() |
|
49
|
|
|
|