Fix error with empty rulesets
This commit is contained in:
parent
51ade25a98
commit
1f54614ae7
1 changed files with 25 additions and 21 deletions
46
validate.py
46
validate.py
|
@ -9,6 +9,7 @@ import click
|
|||
import os
|
||||
import yaml
|
||||
import re
|
||||
import colorful as cf
|
||||
|
||||
try:
|
||||
from yaml import CLoader as Loader, CDumper as Dumper
|
||||
|
@ -19,7 +20,7 @@ except ImportError:
|
|||
@click.command(name="validate")
|
||||
def command():
|
||||
for profile in list_profiles():
|
||||
print(f"Checking {profile}...")
|
||||
print(f"Checking {profile}:")
|
||||
db_path = build_database_filename(profile)
|
||||
rules_path = build_rules_filename(profile)
|
||||
|
||||
|
@ -28,33 +29,36 @@ def command():
|
|||
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 not data:
|
||||
print(cf.green(" Ruleset is empty"))
|
||||
else:
|
||||
for rule in data:
|
||||
if rule.get("name"):
|
||||
try:
|
||||
re.compile(rule["name"])
|
||||
except:
|
||||
print(cf.red(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("description"):
|
||||
try:
|
||||
re.compile(rule["description"])
|
||||
except:
|
||||
print(cf.red(f" Invalid description regex: '{rule.get('description')}'"))
|
||||
|
||||
if rule.get("iban"):
|
||||
try:
|
||||
IBAN(rule.get("iban"))
|
||||
except:
|
||||
print(f"Invalid IBAN: '{rule.get('iban')}'")
|
||||
if rule.get("iban"):
|
||||
try:
|
||||
IBAN(rule.get("iban"))
|
||||
except:
|
||||
print(cf.red(f" Invalid IBAN: '{rule.get('iban')}'"))
|
||||
|
||||
print(f"All rules are valid")
|
||||
print(cf.green(f" All rules are valid"))
|
||||
else:
|
||||
print(f"The rule file doesn't exists")
|
||||
print(cf.red(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")
|
||||
print(cf.green(f" Database exists"))
|
||||
else:
|
||||
print(f"The database file doesn't exists")
|
||||
print(cf.red(f" The database file doesn't exists"))
|
||||
sys.exit(1)
|
||||
|
|
Loading…
Add table
Reference in a new issue