-
Notifications
You must be signed in to change notification settings - Fork 21
/
manage.py
105 lines (76 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
from flask.ext.script import Manager, Command
from flask.ext.script.commands import ShowUrls
from flask.ext.migrate import Migrate, MigrateCommand
from cleansweep.main import app, init_app
from cleansweep.models import db
migrate = Migrate(app, db)
class CleansweepManager(Manager):
"""Flask Script Manager with some customizations.
"""
def __init__(self):
Manager.__init__(self, self.create_app)
self.add_option("-c", "--config", dest="config", required=False)
def create_app(self, config=None):
config = config or "config/development.cfg"
return init_app(config)
def command(self, func=None, name=None):
"""Variant of @manager.command decorator provided by flask-script.
Adds `do_something` function as `do-something` command. It is more convenient
to type a hypen on command-line than an underscre.
"""
command = Command(func)
name = func.__name__.replace("_", "-")
self.add_command(name, command)
return func
manager = CleansweepManager()
manager.add_command('db', MigrateCommand)
manager.add_command('show-urls', ShowUrls)
@manager.command
def init():
"Initiates the application for first time use."
from cleansweep.loaddata import init
init()
@manager.command
def initdb():
"Initiates the database by creating the required tables."
from cleansweep.main import initdb
initdb()
@manager.command
def load(directory):
"Loads data from the specified directory."
from cleansweep.loaddata import main
main(directory)
@manager.command
def load_file(filename):
"Loads data from the specified file."
from cleansweep.loaddata import main_loadfiles
main_loadfiles([filename])
@manager.command
def load_levels(filename):
"Loads levels from the specified file."
from cleansweep.loaddata import main_loadlevels
main_loadlevels(filename)
@manager.command
def add_member(place, name, email, phone):
"Adds a member to the database."
from cleansweep.loaddata import add_member
add_member(place, name, email, phone)
@manager.command
def run_worker():
"Runs a worker."
from cleansweep.core.mailer import run_worker
run_worker()
@manager.command
def help():
"""Shows this help message.
"""
print "USAGE: python manage.py command [arguments]"
print ""
print "The available commands are:"
print ""
width = max(len(name) for name in manager._commands)
for name, command in sorted(manager._commands.items()):
doc = getattr(command, 'help', None) or command.__doc__ or ""
print " {:{w}s}\t{}".format(name, doc.strip(), w=width)
if __name__ == '__main__':
manager.run()