-
Notifications
You must be signed in to change notification settings - Fork 6
/
manage.py
59 lines (42 loc) · 1.24 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
from flask import current_app
from flask_script import Shell, Manager, prompt_bool
from flask_migrate import Migrate, MigrateCommand
from demetsiiify import db, create_app, make_worker, make_redis
def _make_context():
return dict(
app=current_app,
worker=worker,
drop=drop,
create=create,
recreate=recreate)
app = create_app()
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('shell', Shell(make_context=lambda: _make_context()))
manager.add_command('db', MigrateCommand)
@manager.command
def worker():
redis = make_redis()
worker = make_worker(redis, 'tasks')
worker.work()
@manager.command
def oai_worker():
redis = make_redis()
worker = make_worker(redis, 'oai_imports')
worker.work()
@manager.command
def drop():
"""Drops database tables"""
if prompt_bool('Are you sure you want to lose all your data?'):
db.drop_all()
@manager.command
def create():
"""Creates database tables from sqlalchemy models"""
db.create_all()
@manager.command
def recreate(default_data=True, sample_data=False):
"""Recreates database tables (same as issuing 'drop' and then 'create')"""
drop()
create()
if __name__ == '__main__':
manager.run()