From f921b6a7e740162fece5e0bf5f47c3ba28fd66fa Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 30 Mar 2020 12:03:28 +1100 Subject: [PATCH] Make validate module write to logger --- .../ifcopenshell/validate.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/validate.py b/src/ifcopenshell-python/ifcopenshell/validate.py index 4e1ed8e864..a27d1d421d 100644 --- a/src/ifcopenshell-python/ifcopenshell/validate.py +++ b/src/ifcopenshell-python/ifcopenshell/validate.py @@ -73,7 +73,7 @@ def try_valid(attr, val): except ValidationError as e: return False -def validate(f): +def validate(f, logger): schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(f.schema) for inst in f: entity = schema.declaration_by_name(inst.is_a()) @@ -88,17 +88,22 @@ def validate(f): try: assert_valid(attr, val) except ValidationError as e: - print("In", inst) - print(e) - print() + logger.error('In {}\n{}'.format(inst, e)) for attr in entity.all_inverse_attributes(): val = getattr(inst, attr.name()) - assert_valid_inverse(attr, val) + try: + assert_valid_inverse(attr, val) + except ValidationError as e: + logger.error('In {}\n{}'.format(inst, e)) + if __name__ == "__main__": import sys + import logging for fn in sys.argv[1:]: + logger = logging.getLogger('validate') + logger.setLevel(logging.DEBUG) print("Validating", fn) - validate(ifcopenshell.open(fn)) + validate(ifcopenshell.open(fn), logger)