mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
h5 cache - improve logs
Now there are logs when cache was successfully loaded/created/failed to load.
This commit is contained in:
@@ -117,22 +117,34 @@ class IfcStore:
|
|||||||
ifc_key = IfcStore.path + IfcStore.file.wrapped_data.header.file_name.time_stamp
|
ifc_key = IfcStore.path + IfcStore.file.wrapped_data.header.file_name.time_stamp
|
||||||
ifc_hash = hashlib.md5(ifc_key.encode("utf-8")).hexdigest()
|
ifc_hash = hashlib.md5(ifc_key.encode("utf-8")).hexdigest()
|
||||||
IfcStore.cache_path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "cache", f"{ifc_hash}.h5")
|
IfcStore.cache_path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "cache", f"{ifc_hash}.h5")
|
||||||
|
cache_path = Path(IfcStore.cache_path)
|
||||||
cache_settings = ifcopenshell.geom.settings()
|
cache_settings = ifcopenshell.geom.settings()
|
||||||
serializer_settings = ifcopenshell.geom.serializer_settings()
|
serializer_settings = ifcopenshell.geom.serializer_settings()
|
||||||
|
cache_preexists = cache_path.exists()
|
||||||
try:
|
try:
|
||||||
IfcStore.cache = ifcopenshell.geom.serializers.hdf5(
|
IfcStore.cache = ifcopenshell.geom.serializers.hdf5(
|
||||||
IfcStore.cache_path, cache_settings, serializer_settings
|
IfcStore.cache_path, cache_settings, serializer_settings
|
||||||
)
|
)
|
||||||
except:
|
if cache_preexists:
|
||||||
if os.path.exists(IfcStore.cache_path):
|
print(f"Successfully loaded existing cache: {cache_path.name}.")
|
||||||
os.remove(IfcStore.cache_path)
|
|
||||||
try:
|
|
||||||
IfcStore.cache = ifcopenshell.geom.serializers.hdf5(
|
|
||||||
IfcStore.cache_path, cache_settings, serializer_settings
|
|
||||||
)
|
|
||||||
except:
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
|
print("New cache was created.")
|
||||||
|
except Exception as e:
|
||||||
|
if cache_preexists:
|
||||||
|
print(f"Failed to create a cache from existing file '{cache_path.name}': {str(e)}.")
|
||||||
|
else:
|
||||||
|
print(f"Failed to create a cache: {str(e)}.")
|
||||||
|
# No point to trying again the same operation.
|
||||||
|
return
|
||||||
|
|
||||||
|
os.remove(IfcStore.cache_path)
|
||||||
|
try:
|
||||||
|
IfcStore.cache = ifcopenshell.geom.serializers.hdf5(
|
||||||
|
IfcStore.cache_path, cache_settings, serializer_settings
|
||||||
|
)
|
||||||
|
print("New cache was created.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to create a cache: {str(e)}.")
|
||||||
return
|
return
|
||||||
return IfcStore.cache
|
return IfcStore.cache
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user