blob: f73a7a40b63604974fa3c679ba9dce9d37d3249c (
plain)
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
|
import click
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@click.group(context_settings = CONTEXT_SETTINGS)
@click.option('--debug', '-d', is_flag=True, default=False)
def cli(debug):
if debug:
import logging
logger = logging.getLogger('peewee')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
@cli.group()
def db():
"""Database Management"""
pass
@db.command()
def init():
"""Initialize the database, if not done already."""
from .model import create_tables, db
from .prefixes import register_prefixes
create_tables()
with db.atomic():
register_prefixes()
@db.command()
@click.confirmation_option(prompt="Are you sure you want to drop the database?")
def drop():
"""Completely drop all tables."""
from .model import drop_tables
drop_tables()
@cli.group()
def list():
pass
@list.command("prefixes")
def list_prefixes():
from .model import Prefix, db
print("Prefixes")
print("========")
print()
for p in Prefix.select():
print(" * %s (builtin: %s; pseudo: %s)" % (p.name, p.builtin, p.pseudo))
|