New debug feature to purge HDF5 cache in case the cache is corrupted.

This commit is contained in:
Dion Moult
2022-01-11 11:24:13 +11:00
parent ba675c0d28
commit f08ed629b5
8 changed files with 43 additions and 0 deletions
@@ -28,6 +28,7 @@ classes = (
operator.PrintIfcFile,
operator.PrintObjectPlacement,
operator.ProfileImportIFC,
operator.PurgeHdf5Cache,
operator.PurgeIfcLinks,
operator.RewindInspector,
operator.SelectExpressFile,
@@ -328,3 +328,12 @@ class SelectExpressFile(bpy.types.Operator):
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {"RUNNING_MODAL"}
class PurgeHdf5Cache(bpy.types.Operator):
bl_idname = "bim.purge_hdf5_cache"
bl_label = "Purge HDF5 Cache"
def execute(self, context):
core.purge_hdf5_cache(tool.Debug)
return {"FINISHED"}
@@ -46,6 +46,9 @@ class BIM_PT_debug(Panel):
row = layout.row()
row.operator("bim.print_ifc_file")
row = layout.row()
row.operator("bim.purge_hdf5_cache")
row = layout.row()
row.operator("bim.purge_ifc_links")
+4
View File
@@ -19,3 +19,7 @@
def parse_express(debug, filename):
debug.add_schema_identifier(debug.load_express(filename))
def purge_hdf5_cache(debug):
debug.purge_hdf5_cache()
+1
View File
@@ -89,6 +89,7 @@ class Context:
class Debug:
def add_schema_identifier(cls, schema): pass
def load_express(cls, filename): pass
def purge_hdf5_cache(cls): pass
@interface
+8
View File
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import os
import bpy
import ifcopenshell.express
import blenderbim.core.tool
@@ -32,3 +33,10 @@ class Debug(blenderbim.core.tool.Debug):
schema = ifcopenshell.express.parse(filename)
ifcopenshell.register_schema(schema)
return schema
@classmethod
def purge_hdf5_cache(cls):
cache_dir = os.path.join(bpy.context.scene.BIMProperties.data_dir, "cache")
filelist = [f for f in os.listdir(cache_dir) if f.endswith(".h5")]
for f in filelist:
os.remove(os.path.join(cache_dir, f))
+6
View File
@@ -25,3 +25,9 @@ class TestParseExpress:
debug.load_express("filename").should_be_called().will_return("schema")
debug.add_schema_identifier("schema").should_be_called()
subject.parse_express(debug, "filename")
class TestPurgeHdf5Cache:
def test_run(self, debug):
debug.purge_hdf5_cache().should_be_called()
subject.purge_hdf5_cache(debug)
+11
View File
@@ -43,3 +43,14 @@ class TestLoadExpress(NewFile):
schema = subject.load_express(os.path.join(cwd, "..", "files", "test.exp"))
assert schema.schema_name == "IFCROGUE"
return schema
class TestPurgeHdf5Cache(NewFile):
def test_run(self):
cache_dir = os.path.join(bpy.context.scene.BIMProperties.data_dir, "cache")
test_file = os.path.join(cache_dir, "test.h5")
if not os.path.isfile(test_file):
fp = open(test_file, "x")
fp.close()
subject.purge_hdf5_cache()
assert not [f for f in os.listdir(cache_dir) if f.endswith(".h5")]