diff options
-rw-r--r-- | contacts_validation/contacts_validation/__init__.py | 5 | ||||
-rw-r--r-- | contacts_validation/contacts_validation/command_line.py | 6 | ||||
-rw-r--r-- | license.txt | 21 |
3 files changed, 31 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) diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..985ccfe --- /dev/null +++ b/license.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright © 2020 vg <vg@devys.org> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. |