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 os
|
||||||
import yaml
|
import yaml
|
||||||
import re
|
import re
|
||||||
|
import colorful as cf
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from yaml import CLoader as Loader, CDumper as Dumper
|
from yaml import CLoader as Loader, CDumper as Dumper
|
||||||
|
@ -19,7 +20,7 @@ except ImportError:
|
||||||
@click.command(name="validate")
|
@click.command(name="validate")
|
||||||
def command():
|
def command():
|
||||||
for profile in list_profiles():
|
for profile in list_profiles():
|
||||||
print(f"Checking {profile}...")
|
print(f"Checking {profile}:")
|
||||||
db_path = build_database_filename(profile)
|
db_path = build_database_filename(profile)
|
||||||
rules_path = build_rules_filename(profile)
|
rules_path = build_rules_filename(profile)
|
||||||
|
|
||||||
|
@ -28,33 +29,36 @@ def command():
|
||||||
with open(rules_path) as fh:
|
with open(rules_path) as fh:
|
||||||
data = yaml.load(fh, Loader=Loader)
|
data = yaml.load(fh, Loader=Loader)
|
||||||
|
|
||||||
for rule in data:
|
if not data:
|
||||||
if rule.get("name"):
|
print(cf.green(" Ruleset is empty"))
|
||||||
try:
|
else:
|
||||||
re.compile(rule["name"])
|
for rule in data:
|
||||||
except:
|
if rule.get("name"):
|
||||||
print(f"Invalid name regex: '{rule.get('name')}'")
|
try:
|
||||||
|
re.compile(rule["name"])
|
||||||
|
except:
|
||||||
|
print(cf.red(f" Invalid name regex: '{rule.get('name')}'"))
|
||||||
|
|
||||||
if rule.get("description"):
|
if rule.get("description"):
|
||||||
try:
|
try:
|
||||||
re.compile(rule["description"])
|
re.compile(rule["description"])
|
||||||
except:
|
except:
|
||||||
print(f"Invalid description regex: '{rule.get('description')}'")
|
print(cf.red(f" Invalid description regex: '{rule.get('description')}'"))
|
||||||
|
|
||||||
if rule.get("iban"):
|
if rule.get("iban"):
|
||||||
try:
|
try:
|
||||||
IBAN(rule.get("iban"))
|
IBAN(rule.get("iban"))
|
||||||
except:
|
except:
|
||||||
print(f"Invalid IBAN: '{rule.get('iban')}'")
|
print(cf.red(f" Invalid IBAN: '{rule.get('iban')}'"))
|
||||||
|
|
||||||
print(f"All rules are valid")
|
print(cf.green(f" All rules are valid"))
|
||||||
else:
|
else:
|
||||||
print(f"The rule file doesn't exists")
|
print(cf.red(f" The rule file doesn't exists"))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
if os.path.exists(db_path) and os.path.isfile(db_path):
|
if os.path.exists(db_path) and os.path.isfile(db_path):
|
||||||
print(f"Database exists")
|
print(cf.green(f" Database exists"))
|
||||||
else:
|
else:
|
||||||
print(f"The database file doesn't exists")
|
print(cf.red(f" The database file doesn't exists"))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue