This repository has been archived by the owner on Jan 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
manage.py
executable file
·113 lines (79 loc) · 2.67 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python
from __future__ import (
absolute_import, division, print_function, with_statement,
unicode_literals)
import os.path as p
import swutils
import config
from subprocess import call
from functools import partial
from flask import current_app as app
from flask.ext.script import Manager
from tabutils.process import merge
from app import create_app, db, utils, __title__
from app.models import BaseMixin
manager = Manager(create_app)
manager.add_option('-m', '--mode', default='Development')
manager.main = manager.run
_basedir = p.dirname(__file__)
@manager.command
def check():
"""Check staged changes for lint errors"""
call(p.join(_basedir, 'bin', 'check-stage'), shell=True)
@manager.command
def lint():
"""Check style with flake8"""
call('flake8')
@manager.command
def pipme():
"""Install requirements.txt"""
call('sudo pip install -r requirements.txt', shell=True)
@manager.command
def require():
"""Create requirements.txt"""
cmd = 'pip freeze -l | grep -vxFf dev-requirements.txt > requirements.txt'
call(cmd, shell=True)
@manager.command
def test():
"""Run nose and script tests"""
call('nosetests -xv', shell=True)
@manager.command
def createdb():
"""Creates database if it doesn't already exist"""
with app.app_context():
db.create_all()
print('Database created')
@manager.command
def cleardb():
"""Removes all content from database"""
with app.app_context():
db.drop_all()
print('Database cleared')
@manager.command
def setup():
"""Removes all content from database and creates new tables"""
with app.app_context():
cleardb()
createdb()
@manager.command
def run():
"""Populates all tables in db with most recent data"""
with app.app_context():
args = (config.RECIPIENT, app.config.get('LOGFILE'), __title__)
exception_handler = swutils.ExceptionHandler(*args).handler
extra = {'mixin': BaseMixin, 'get_name': lambda x: 'ym%s' % x}
kwargs = merge([app.config, extra])
job = partial(swutils.populate, utils.gen_data, db.engine, **kwargs)
swutils.run_or_schedule(job, app.config['SW'], exception_handler)
@manager.option(
'-s', '--stag', help='upload to staging site', action='store_true')
def upload(stag=False):
"""Upload files to HDX"""
call([p.join(_basedir, 'bin', 'upload'), 'stag' if stag else 'prod'])
@manager.option(
'-s', '--stag', help='upload to staging site', action='store_true')
def update(stag=False):
"""Update dataset metadata"""
call([p.join(_basedir, 'bin', 'update'), 'stag' if stag else 'prod'])
if __name__ == '__main__':
manager.run()