schmeckels/schmeckels/cli.py
Felix Breidenstein 0c61ee7e71 Soooo many changes
2021-04-12 22:53:01 +02:00

53 lines
1.3 KiB
Python

#! /usr/bin/env python3
import click
import os
import sys
from pathlib import Path
from schmeckels import importer, serve, autosort, validate, info, sort, models, report
from schmeckels.helper import build_database_filename, create_dirs, build_rules_filename
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
__version__ = "0.0.1"
@click.group()
def cli():
pass
@cli.command(name="init")
@click.argument("profile_name", required=True)
def init(profile_name):
create_dirs()
db_path = build_database_filename(profile_name)
rule_path = build_rules_filename(profile_name)
if os.path.exists(db_path) and os.path.exists(rule_path):
print(f"Profile '{profile_name}' already exists")
sys.exit(1)
else:
# database
engine = create_engine(f"sqlite:///{db_path}")
models.Base.metadata.create_all(engine)
# rules
Path(rule_path).touch()
print(f"Sucessfully create the profile '{profile_name}'")
def main():
cli.add_command(sort.command)
cli.add_command(importer.command)
cli.add_command(serve.command)
cli.add_command(autosort.command)
cli.add_command(validate.command)
cli.add_command(info.command)
cli.add_command(report.command)
cli()