-
Notifications
You must be signed in to change notification settings - Fork 145
/
manage.py
executable file
·55 lines (39 loc) · 1.23 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
#!/usr/bin/env python
import os
import urllib
import click
from flask import current_app, url_for
from flask.cli import FlaskGroup
from appname import create_app
from appname.models import db
def create_app_with_config(*args):
# default to dev config because no one should use this in
# production anyway
env = os.environ.get('APPNAME_ENV', 'dev')
return create_app('appname.settings.%sConfig' % env.capitalize())
@click.group(cls=FlaskGroup, create_app=create_app_with_config)
def cli():
pass
@cli.command()
def create_all():
""" Creates a database with all of the tables defined in
your SQLAlchemy models
"""
db.create_all()
@cli.command()
def show_urls():
""" List all of the endpoints on the app and the supportted methods
"""
output = []
for rule in current_app.url_map.iter_rules():
options = {}
for arg in rule.arguments:
options[arg] = "<{0}>".format(arg)
methods = ','.join(rule.methods)
url = url_for(rule.endpoint, **options)
line = urllib.parse.unquote("{:45s} {:30s} {}".format(rule.endpoint, methods, url))
output.append(line)
for line in sorted(output):
print(line)
if __name__ == "__main__":
cli()