ifctester.main - fail more gracefully for invalid files

This commit is contained in:
Andrej730
2024-11-08 14:47:18 +05:00
parent 466ba6c159
commit 0a7ee4e360
+12 -2
View File
@@ -23,6 +23,7 @@ import argparse
import ifcopenshell
from . import ids
from . import reporter
from pathlib import Path
parser = argparse.ArgumentParser(description="Uses an IDS to audit an IFC")
parser.add_argument("ids", type=str, help="Path to an IDS")
@@ -33,10 +34,19 @@ parser.add_argument("--excel-safe", help="Make sure exported ODS is safely expor
parser.add_argument("-o", "--output", help="Output file (supported for all types of reporting except Console)")
args = parser.parse_args()
specs = ids.open(args.ids)
ids_path = Path(args.ids)
if ids_path.suffix.lower() != ".ids":
raise Exception(f"Provided file is not an .ids file: '{ids_path}'.")
ifc_patch = Path(args.ifc)
if ifc_patch.suffix.lower() != ".ifc":
raise Exception(f"Provided file is not an .ifc file: '{ifc_patch}'.")
specs = ids.open(str(ids_path))
if args.ifc:
start = time.time()
ifc = ifcopenshell.open(args.ifc)
ifc = ifcopenshell.open(ifc_patch)
assert isinstance(ifc, ifcopenshell.file)
print("Finished loading:", time.time() - start)
start = time.time()
specs.validate(ifc)