diff options
author | vg <vgm+dev@devys.org> | 2020-01-16 12:45:41 +0100 |
---|---|---|
committer | vg <vgm+dev@devys.org> | 2020-01-16 12:45:41 +0100 |
commit | 0855de2b5aa3b26aa61edcdfe5fd2ba612094eb5 (patch) | |
tree | a8b18644e793854d8388ccbffecf1a4bfc16da74 /contacts_validation/contacts_validation | |
parent | 8fe0b2c7754873ec33bccb7952683b96113491bc (diff) | |
download | devys-pim-0855de2b5aa3b26aa61edcdfe5fd2ba612094eb5.tar.gz devys-pim-0855de2b5aa3b26aa61edcdfe5fd2ba612094eb5.tar.bz2 devys-pim-0855de2b5aa3b26aa61edcdfe5fd2ba612094eb5.zip |
return error status on command invocation
Diffstat (limited to 'contacts_validation/contacts_validation')
-rw-r--r-- | contacts_validation/contacts_validation/__init__.py | 5 | ||||
-rw-r--r-- | contacts_validation/contacts_validation/command_line.py | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/contacts_validation/contacts_validation/__init__.py b/contacts_validation/contacts_validation/__init__.py index 822e789..0f00c18 100644 --- a/contacts_validation/contacts_validation/__init__.py +++ b/contacts_validation/contacts_validation/__init__.py @@ -58,10 +58,12 @@ def print_validation_error(data_obj, exception): def validate_yaml_data(data_obj, schema_obj): + valid = True try: jsonschema.validate(convert_types(data_obj), schema_obj) except jsonschema.ValidationError as e: print_validation_error(data_obj, e) + valid = False # schema ok, check for duplicates in display and uuids display_dups = collections.defaultdict(list) @@ -72,7 +74,10 @@ def validate_yaml_data(data_obj, schema_obj): for e in (data_obj[e] for e in display_dups.values() if len(e) > 2): print('WARNING: duplicated display value for these contacts:') print(f'=> display: {e["display"]} uuid: {e["uuid"]}') + valid = False # by default warning are errors on cmdline for e in (data_obj[e] for e in uuid_dups.values() if len(e) > 2): print('ERROR: duplicated uuid value for these contacts:') print(f'=> display: {e["display"]} uuid: {e["uuid"]}') + valid = False + return valid diff --git a/contacts_validation/contacts_validation/command_line.py b/contacts_validation/contacts_validation/command_line.py index 0310c78..29ec2dd 100644 --- a/contacts_validation/contacts_validation/command_line.py +++ b/contacts_validation/contacts_validation/command_line.py @@ -44,8 +44,12 @@ def main(): schema_obj = yaml.safe_load(schema_fh.read()) assert schema_obj + error_occured = False for i, stream in enumerate(gen_streams(args['FILENAME'] or ['-'])): print('#'*60, f'# Valdating stream {i}', '#'*60, sep='\n') yaml_data = yaml.safe_load(stream.read()) assert yaml_data - validate_yaml_data(yaml_data, schema_obj) + if not validate_yaml_data(yaml_data, schema_obj): + error_occured = True + if error_occured: + raise SystemExit(1) |