Fix autosort

This commit is contained in:
Felix Breidenstein 2020-10-18 20:11:17 +02:00
parent e49e8c51f5
commit db555fa3b3
4 changed files with 50 additions and 41 deletions

23
cli
View file

@ -2,15 +2,16 @@
import click
import os
import sys
from pathlib import Path
import importer
# import serve
# import autosort
# import validate
import autosort
import validate
# import info
# import report
from helper import build_database_filename, create_dirs
from helper import build_database_filename, create_dirs, build_rules_filename
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
@ -26,13 +27,19 @@ def cli():
@cli.command(name="init")
@click.argument("profile_name", required=True)
def init(profile_name):
filename = build_database_filename(profile_name)
if os.path.exists(filename):
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:
engine = create_engine(f"sqlite:///{filename}")
# 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}'")
@ -41,8 +48,8 @@ if __name__ == '__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(autosort.command)
cli.add_command(validate.command)
# cli.add_command(info.command)
# cli.add_command(report.command)
cli()