diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2017-02-25 18:27:07 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2017-02-25 18:27:07 +0100 |
commit | 2148929f3f4157a4bfda318c670290b4391a2739 (patch) | |
tree | 3beef8730addc7bd453a5180b21d7434b695a80a /archivist/cli.py | |
parent | 325fbe44382a3b8ee13d29c3a8ef81660d3a1a6d (diff) | |
download | archivist-2148929f3f4157a4bfda318c670290b4391a2739.tar.gz archivist-2148929f3f4157a4bfda318c670290b4391a2739.tar.bz2 archivist-2148929f3f4157a4bfda318c670290b4391a2739.zip |
Use Peewee instead of SQLAlchemy
Diffstat (limited to 'archivist/cli.py')
-rw-r--r-- | archivist/cli.py | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/archivist/cli.py b/archivist/cli.py index 01c0b57..4316705 100644 --- a/archivist/cli.py +++ b/archivist/cli.py @@ -3,8 +3,13 @@ import click CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) @click.group(context_settings = CONTEXT_SETTINGS) -def cli(): - pass +@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(): @@ -14,12 +19,33 @@ def db(): @db.command() def init(): """Initialize the database, if not done already.""" - from .model import create_all - create_all() + from .model import create_tables, Prefix, db + create_tables() + with db.atomic(): + Prefix.create(name='year', builtin=True) + Prefix.create(name='month', builtin=True) + Prefix.create(name='day', builtin=True) + Prefix.create(name='date', builtin=True, pseudo=True) + Prefix.create(name='direction', builtin=True, pseudo=True) @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_all - drop_all() + 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)) |