Implemented the validate command
This commit is contained in:
parent
3790ab6c65
commit
66c1150f60
5 changed files with 81 additions and 5 deletions
1
Pipfile
1
Pipfile
|
@ -17,6 +17,7 @@ xdg = "*"
|
||||||
pyyaml = "*"
|
pyyaml = "*"
|
||||||
colored = "*"
|
colored = "*"
|
||||||
colorful = "*"
|
colorful = "*"
|
||||||
|
schwifty = "*"
|
||||||
|
|
||||||
[requires]
|
[requires]
|
||||||
python_version = "3.8"
|
python_version = "3.8"
|
||||||
|
|
17
Pipfile.lock
generated
17
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "816c7c2536e6f09c3088905953eb3d20b067dad888a1626eedb2ddef41c6b045"
|
"sha256": "c9d6b64c5d520a15a7e020cdcf1479cd32cd46ce1307d9002d22a5a80d5ab669"
|
||||||
},
|
},
|
||||||
"pipfile-spec": 6,
|
"pipfile-spec": 6,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
@ -47,6 +47,13 @@
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==0.5.4"
|
"version": "==0.5.4"
|
||||||
},
|
},
|
||||||
|
"iso3166": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:b07208703bd881a4f974e39fa013c4498dddd64913ada15f24be75d02ae68a44",
|
||||||
|
"sha256:b1e58dbcf50fbb2c9c418ec7a6057f0cdb30b8f822ac852f72e71ba769dae8c5"
|
||||||
|
],
|
||||||
|
"version": "==1.0.1"
|
||||||
|
},
|
||||||
"mt-940": {
|
"mt-940": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:7cbd88fd7252d5a2694593633b31f819eb302423058fecb9f9959e74c01c2b86",
|
"sha256:7cbd88fd7252d5a2694593633b31f819eb302423058fecb9f9959e74c01c2b86",
|
||||||
|
@ -80,6 +87,14 @@
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==5.3.1"
|
"version": "==5.3.1"
|
||||||
},
|
},
|
||||||
|
"schwifty": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:1774dca3a9224fd98730cb81274d963ed8e545593ffadce56681ebe49cdea7c0",
|
||||||
|
"sha256:98240f53e01a08a59e130e895235e0b69a3f4caf4bd7e9f461e2e317373b9919"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==2020.2.2"
|
||||||
|
},
|
||||||
"sqlalchemy": {
|
"sqlalchemy": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:c4cca4aed606297afbe90d4306b49ad3a4cd36feb3f87e4bfd655c57fd9ef445"
|
"sha256:c4cca4aed606297afbe90d4306b49ad3a4cd36feb3f87e4bfd655c57fd9ef445"
|
||||||
|
|
2
cli
2
cli
|
@ -7,6 +7,7 @@ import sort
|
||||||
import importer
|
import importer
|
||||||
import serve
|
import serve
|
||||||
import autosort
|
import autosort
|
||||||
|
import validate
|
||||||
import info
|
import info
|
||||||
|
|
||||||
from helper import build_database_filename, create_dirs
|
from helper import build_database_filename, create_dirs
|
||||||
|
@ -41,5 +42,6 @@ if __name__ == '__main__':
|
||||||
cli.add_command(importer.command)
|
cli.add_command(importer.command)
|
||||||
cli.add_command(serve.command)
|
cli.add_command(serve.command)
|
||||||
cli.add_command(autosort.command)
|
cli.add_command(autosort.command)
|
||||||
|
cli.add_command(validate.command)
|
||||||
cli.add_command(info.command)
|
cli.add_command(info.command)
|
||||||
cli()
|
cli()
|
||||||
|
|
4
info.py
4
info.py
|
@ -5,10 +5,6 @@ from helper import get_session, list_profiles, build_database_filename, build_ru
|
||||||
import sys
|
import sys
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from prompt_toolkit.completion import FuzzyWordCompleter
|
|
||||||
from prompt_toolkit.shortcuts import prompt
|
|
||||||
|
|
||||||
|
|
||||||
@click.command(name="info")
|
@click.command(name="info")
|
||||||
def command():
|
def command():
|
||||||
for profile in list_profiles():
|
for profile in list_profiles():
|
||||||
|
|
62
validate.py
Normal file
62
validate.py
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#! /usr/bin/env python3
|
||||||
|
from sqlalchemy import create_engine
|
||||||
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
from helper import list_profiles, build_rules_filename, build_database_filename
|
||||||
|
from schwifty import IBAN
|
||||||
|
import sys
|
||||||
|
import click
|
||||||
|
import os
|
||||||
|
import yaml
|
||||||
|
import re
|
||||||
|
|
||||||
|
try:
|
||||||
|
from yaml import CLoader as Loader, CDumper as Dumper
|
||||||
|
except ImportError:
|
||||||
|
from yaml import Loader, Dumper
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@click.command(name="validate")
|
||||||
|
def command():
|
||||||
|
for profile in list_profiles():
|
||||||
|
print(f"Checking {profile}...")
|
||||||
|
db_path = build_database_filename(profile)
|
||||||
|
rules_path = build_rules_filename(profile)
|
||||||
|
|
||||||
|
|
||||||
|
# Rules
|
||||||
|
if os.path.exists(rules_path) and os.path.isfile(rules_path):
|
||||||
|
with open(rules_path) as fh:
|
||||||
|
data = yaml.load(fh, Loader=Loader)
|
||||||
|
|
||||||
|
for rule in data:
|
||||||
|
if rule.get("name"):
|
||||||
|
try:
|
||||||
|
re.compile(rule["name"])
|
||||||
|
except:
|
||||||
|
print(f"Invalid name regex: '{rule.get('name')}'")
|
||||||
|
|
||||||
|
if rule.get("description"):
|
||||||
|
try:
|
||||||
|
re.compile(rule["description"])
|
||||||
|
except:
|
||||||
|
print(f"Invalid description regex: '{rule.get('description')}'")
|
||||||
|
|
||||||
|
if rule.get("iban"):
|
||||||
|
try:
|
||||||
|
IBAN(rule.get("iban"))
|
||||||
|
except:
|
||||||
|
print(f"Invalid IBAN: '{rule.get('iban')}'")
|
||||||
|
|
||||||
|
print(f"All rules are valid")
|
||||||
|
else:
|
||||||
|
print(f"The rule file doesn't exists")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Database
|
||||||
|
if os.path.exists(db_path) and os.path.isfile(db_path):
|
||||||
|
print(f"Database exists")
|
||||||
|
else:
|
||||||
|
print(f"The database file doesn't exists")
|
||||||
|
sys.exit(1)
|
Loading…
Add table
Reference in a new issue