mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
ifcopenshell.validate - check json_logger more explicitly
This commit is contained in:
@@ -301,7 +301,7 @@ def assert_valid(
|
||||
return True
|
||||
|
||||
|
||||
def log_internal_cpp_errors(f: ifcopenshell.file, filename: str, logger: Logger) -> None:
|
||||
def log_internal_cpp_errors(f: ifcopenshell.file, filename: str, logger: Union[Logger, json_logger]) -> None:
|
||||
import re
|
||||
import bisect
|
||||
|
||||
@@ -325,7 +325,7 @@ def log_internal_cpp_errors(f: ifcopenshell.file, filename: str, logger: Logger)
|
||||
line = lines[bisect.bisect_left(cs, int(offsets[0]))].decode("ascii", errors="ignore").rstrip()
|
||||
m = chr_offset_re.sub("", msg["message"])
|
||||
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("instance", line)
|
||||
logger.set_state("attribute", None)
|
||||
logger.error("%s:\n\n%s" % (m, line))
|
||||
@@ -341,7 +341,7 @@ def log_internal_cpp_errors(f: ifcopenshell.file, filename: str, logger: Logger)
|
||||
inst = f[int(instid[0])]
|
||||
except:
|
||||
inst = None
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("instance", inst)
|
||||
logger.set_state("attribute", None)
|
||||
logger.error(m)
|
||||
@@ -368,7 +368,7 @@ def get_entity_attributes(schema: schema_definition, entity: str) -> tuple[entit
|
||||
return entity_attrs
|
||||
|
||||
|
||||
def validate(f: Union[ifcopenshell.file, str], logger: Logger, express_rules=False) -> None:
|
||||
def validate(f: Union[ifcopenshell.file, str], logger: Union[Logger, json_logger], express_rules=False) -> None:
|
||||
"""
|
||||
For an IFC population model `f` (or filepath to such a file) validate whether the entity attribute values are correctly supplied. As this
|
||||
is a function that is applied after a file has been parsed, certain types of errors in syntax, duplicate
|
||||
@@ -406,7 +406,7 @@ def validate(f: Union[ifcopenshell.file, str], logger: Logger, express_rules=Fal
|
||||
|
||||
filename = None
|
||||
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("type", "schema")
|
||||
|
||||
if not isinstance(f, ifcopenshell.file):
|
||||
@@ -441,7 +441,7 @@ def validate(f: Union[ifcopenshell.file, str], logger: Logger, express_rules=Fal
|
||||
used_guids: dict[str, ifcopenshell.entity_instance] = dict()
|
||||
|
||||
for inst in f:
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("instance", inst)
|
||||
|
||||
guid: Union[str, None, EllipsisType]
|
||||
@@ -476,7 +476,7 @@ def validate(f: Union[ifcopenshell.file, str], logger: Logger, express_rules=Fal
|
||||
|
||||
if entity.is_abstract():
|
||||
e = "Entity %s is abstract" % entity.name()
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("attribute", None)
|
||||
logger.error(e)
|
||||
else:
|
||||
@@ -489,7 +489,7 @@ def validate(f: Union[ifcopenshell.file, str], logger: Logger, express_rules=Fal
|
||||
values[i] = inst[i]
|
||||
pass
|
||||
except:
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("attribute", f"{entity.name()}.{attrs[i].name()}")
|
||||
logger.error("Invalid attribute value")
|
||||
else:
|
||||
@@ -505,7 +505,7 @@ def validate(f: Union[ifcopenshell.file, str], logger: Logger, express_rules=Fal
|
||||
if not has_invalid_value:
|
||||
for i, (attr, val, is_derived) in enumerate(zip(attrs, values, entity.derived())):
|
||||
if is_derived and not isinstance(val, ifcopenshell.ifcopenshell_wrapper.attribute_value_derived):
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("attribute", f"{entity.name()}.{attr.name()}")
|
||||
logger.error("Attribute is derived in subtype")
|
||||
else:
|
||||
@@ -517,7 +517,7 @@ def validate(f: Union[ifcopenshell.file, str], logger: Logger, express_rules=Fal
|
||||
)
|
||||
|
||||
if val is None and not attr.optional() and not is_derived:
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("attribute", f"{entity.name()}.{attr.name()}")
|
||||
logger.error("Attribute not optional")
|
||||
else:
|
||||
@@ -533,7 +533,7 @@ def validate(f: Union[ifcopenshell.file, str], logger: Logger, express_rules=Fal
|
||||
try:
|
||||
assert_valid(attr_type, val, schema, attr=attr)
|
||||
except ValidationError as e:
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("attribute", e.attribute)
|
||||
logger.error(str(e))
|
||||
else:
|
||||
@@ -548,7 +548,7 @@ def validate(f: Union[ifcopenshell.file, str], logger: Logger, express_rules=Fal
|
||||
try:
|
||||
val = getattr(inst, attr.name())
|
||||
except Exception as e:
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("attribute", f"{entity.name()}.{attr.name()}")
|
||||
logger.error(str(e))
|
||||
else:
|
||||
@@ -557,7 +557,7 @@ def validate(f: Union[ifcopenshell.file, str], logger: Logger, express_rules=Fal
|
||||
try:
|
||||
assert_valid_inverse(attr, val, schema)
|
||||
except ValidationError as e:
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("attribute", f"{entity.name()}.{attr.name()}")
|
||||
logger.error(str(e))
|
||||
else:
|
||||
@@ -575,7 +575,7 @@ def validate(f: Union[ifcopenshell.file, str], logger: Logger, express_rules=Fal
|
||||
ifcopenshell.ifcopenshell_wrapper.set_feature("use_attribute_value_derived", attribute_value_derived_org)
|
||||
|
||||
if express_rules:
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("instance", None)
|
||||
logger.set_state("attribute", None)
|
||||
ifcopenshell.express.rule_executor.run(f, logger)
|
||||
@@ -616,7 +616,9 @@ def to_string_header_entity(header_entity):
|
||||
raise TypeError(f"Cannot stringify header_entity of type {type(header_entity)}")
|
||||
|
||||
|
||||
def validate_ifc_header(f: Union[ifcopenshell.file, ifcopenshell.simple_spf.file], logger: Logger) -> None:
|
||||
def validate_ifc_header(
|
||||
f: Union[ifcopenshell.file, ifcopenshell.simple_spf.file], logger: Union[Logger, json_logger]
|
||||
) -> None:
|
||||
header: Union[W.IfcSpfHeader, types.SimpleNamespace] = f.header
|
||||
AGGREGATE_TYPE = "LIST [ 1 : ? ] OF STRING (256)"
|
||||
STRING_TYPE = "STRING (256)"
|
||||
@@ -677,7 +679,7 @@ def validate_ifc_header(f: Union[ifcopenshell.file, ifcopenshell.simple_spf.file
|
||||
validate_attribute(file_name, "authorization", 6)
|
||||
|
||||
|
||||
def validate_ifc_applications(f: ifcopenshell.file, logger: Logger) -> None:
|
||||
def validate_ifc_applications(f: ifcopenshell.file, logger: Union[Logger, json_logger]) -> None:
|
||||
used_names: dict[str, ifcopenshell.entity_instance] = dict()
|
||||
used_ids: dict[str, ifcopenshell.entity_instance] = dict()
|
||||
|
||||
@@ -689,7 +691,7 @@ def validate_ifc_applications(f: ifcopenshell.file, logger: Logger) -> None:
|
||||
if app_name not in used_names:
|
||||
used_names[app_name] = inst
|
||||
else:
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("instance", inst)
|
||||
rule = "Rule IfcApplication.UR2:\n The attribute ApplicationFullName should be unique"
|
||||
previous_element = used_names[app_name]
|
||||
@@ -706,7 +708,7 @@ def validate_ifc_applications(f: ifcopenshell.file, logger: Logger) -> None:
|
||||
if app_id not in used_ids:
|
||||
used_ids[app_id] = inst
|
||||
else:
|
||||
if hasattr(logger, "set_state"):
|
||||
if isinstance(logger, json_logger):
|
||||
logger.set_state("instance", inst)
|
||||
rule = "Rule IfcApplication.UR1:\n The attribute ApplicationIdentifier should be unique"
|
||||
previous_element = used_ids[app_id]
|
||||
|
||||
Reference in New Issue
Block a user