Fix #6136. Allow setting of custom tmp dir, useful for packaged envs like flatpak

This commit is contained in:
Dion Moult
2025-02-19 17:44:48 +11:00
parent a8efd53d6b
commit ee0599e263
6 changed files with 39 additions and 47 deletions
+1 -3
View File
@@ -115,10 +115,8 @@ classes = [
operator.ReloadIfcFile, operator.ReloadIfcFile,
operator.RemoveIfcFile, operator.RemoveIfcFile,
operator.RevertClippingPlaneCut, operator.RevertClippingPlaneCut,
operator.SelectDataDir, operator.SelectDir,
operator.SelectCacheDir,
operator.SelectIfcFile, operator.SelectIfcFile,
operator.SelectSchemaDir,
operator.SelectURIAttribute, operator.SelectURIAttribute,
operator.SetTab, operator.SetTab,
operator.SwitchTab, operator.SwitchTab,
@@ -113,7 +113,7 @@ class AuginCreateNewModel(bpy.types.Operator):
context.scene.collection.objects.link(cam_obj) context.scene.collection.objects.link(cam_obj)
context.scene.camera = cam_obj context.scene.camera = cam_obj
tmpdir = tempfile.mkdtemp() tmpdir = tempfile.mkdtemp(dir=tool.Blender.get_addon_preferences().tmp_dir or None)
thumb_path = os.path.join(tmpdir, "thumb.png") thumb_path = os.path.join(tmpdir, "thumb.png")
context.scene.render.image_settings.file_format = "PNG" context.scene.render.image_settings.file_format = "PNG"
context.scene.render.filepath = thumb_path context.scene.render.filepath = thumb_path
@@ -1057,7 +1057,9 @@ class LoadProjectElements(bpy.types.Operator):
logger = logging.getLogger("ImportIFC") logger = logging.getLogger("ImportIFC")
path_log = tool.Blender.get_data_dir_path("process.log") path_log = tool.Blender.get_data_dir_path("process.log")
if not os.access(path_log.parent, os.W_OK): if not os.access(path_log.parent, os.W_OK):
path_log = os.path.join(tempfile.mkdtemp(), "process.log") path_log = os.path.join(
tempfile.mkdtemp(dir=tool.Blender.get_addon_preferences().tmp_dir or None), "process.log"
)
logging.basicConfig( logging.basicConfig(
filename=path_log, filename=path_log,
filemode="a", filemode="a",
@@ -1579,7 +1581,9 @@ class ExportIFC(bpy.types.Operator):
logger = logging.getLogger("ExportIFC") logger = logging.getLogger("ExportIFC")
path_log = tool.Blender.get_data_dir_path("process.log") path_log = tool.Blender.get_data_dir_path("process.log")
if not os.access(path_log.parent, os.W_OK): if not os.access(path_log.parent, os.W_OK):
path_log = os.path.join(tempfile.mkdtemp(), "process.log") path_log = os.path.join(
tempfile.mkdtemp(dir=tool.Blender.get_addon_preferences().tmp_dir or None), "process.log"
)
logging.basicConfig( logging.basicConfig(
filename=path_log, filename=path_log,
filemode="a", filemode="a",
@@ -72,7 +72,7 @@ class ExecuteIfcTester(bpy.types.Operator):
# No need for if-statement, just postponing lots of diffs. # No need for if-statement, just postponing lots of diffs.
if True: if True:
dirpath = tempfile.mkdtemp() dirpath = tempfile.mkdtemp(dir=tool.Blender.get_addon_preferences().tmp_dir or None)
start = time.time() start = time.time()
output = Path(os.path.join(dirpath, "{}_{}.html".format(Path(ifc_path).name, Path(specs_path).name))) output = Path(os.path.join(dirpath, "{}_{}.html".format(Path(ifc_path).name, Path(specs_path).name)))
+20 -38
View File
@@ -226,47 +226,27 @@ class SelectIfcFile(bpy.types.Operator, IFCFileSelector):
return {"RUNNING_MODAL"} return {"RUNNING_MODAL"}
class SelectDataDir(bpy.types.Operator): class SelectDir(bpy.types.Operator):
bl_idname = "bim.select_data_dir" bl_idname = "bim.select_dir"
bl_label = "Select Data Directory" bl_label = "Select Directory"
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
bl_description = "Select the directory that contains all IFC data es. PSet, styles, etc..." bl_description = "Open a file browser to choose the directory"
filepath: bpy.props.StringProperty(subtype="FILE_PATH") filepath: bpy.props.StringProperty(subtype="FILE_PATH")
data_path: bpy.props.StringProperty(name="Data Path")
def execute(self, context): def execute(self, context):
context.scene.BIMProperties.data_dir = os.path.dirname(self.filepath) crumbs = self.data_path.split(".")
return {"FINISHED"} if crumbs[0] == "preferences":
crumbs.pop(0)
def invoke(self, context, event): data = tool.Blender.get_addon_preferences()
context.window_manager.fileselect_add(self) else:
return {"RUNNING_MODAL"} data = context
while crumbs:
crumb = crumbs.pop(0)
class SelectCacheDir(bpy.types.Operator): if crumbs:
bl_idname = "bim.select_cache_dir" data = getattr(data, crumb)
bl_label = "Select Cache Directory" else:
bl_options = {"REGISTER", "UNDO"} setattr(data, crumb, os.path.dirname(self.filepath))
bl_description = "Select the directory that contains HDF5 cache files"
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
def execute(self, context):
context.scene.BIMProperties.cache_dir = os.path.dirname(self.filepath)
return {"FINISHED"}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {"RUNNING_MODAL"}
class SelectSchemaDir(bpy.types.Operator):
bl_idname = "bim.select_schema_dir"
bl_label = "Select Schema Directory"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Select the directory containing the IFC schema specification"
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
def execute(self, context):
context.scene.BIMProperties.schema_dir = os.path.dirname(self.filepath)
return {"FINISHED"} return {"FINISHED"}
def invoke(self, context, event): def invoke(self, context, event):
@@ -816,7 +796,9 @@ class ReloadIfcFile(bpy.types.Operator, tool.Ifc.Operator):
logger = logging.getLogger("ImportIFC") logger = logging.getLogger("ImportIFC")
path_log = tool.Blender.get_data_dir_path("process.log") path_log = tool.Blender.get_data_dir_path("process.log")
if not os.access(path_log.parent, os.W_OK): if not os.access(path_log.parent, os.W_OK):
path_log = os.path.join(tempfile.mkdtemp(), "process.log") path_log = os.path.join(
tempfile.mkdtemp(dir=tool.Blender.get_addon_preferences().tmp_dir or None), "process.log"
)
logging.basicConfig( logging.basicConfig(
filename=path_log, filename=path_log,
filemode="a", filemode="a",
+10 -2
View File
@@ -245,6 +245,10 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
description="If disabled, the toolbar will only load when an IFC model is active", description="If disabled, the toolbar will only load when an IFC model is active",
) )
should_play_chaching_sound: BoolProperty(name="Play A Cha-Ching Sound When Project Costs Updates", default=False) should_play_chaching_sound: BoolProperty(name="Play A Cha-Ching Sound When Project Costs Updates", default=False)
tmp_dir: StringProperty(
name="Temporary Directory",
description='Path to create and store temporary files. If left blank, a system default will be used.',
)
spatial_elements_unselectable: BoolProperty( spatial_elements_unselectable: BoolProperty(
name="Make Spatial Elements Unselectable By Default", name="Make Spatial Elements Unselectable By Default",
default=True, default=True,
@@ -356,11 +360,15 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
def draw_directories(self, layout, context): def draw_directories(self, layout, context):
row = layout.row(align=True) row = layout.row(align=True)
row.prop(context.scene.BIMProperties, "data_dir") row.prop(context.scene.BIMProperties, "data_dir")
row.operator("bim.select_data_dir", icon="FILE_FOLDER", text="") row.operator("bim.select_dir", icon="FILE_FOLDER", text="").data_path = "scene.BIMProperties.data_dir"
row = layout.row(align=True) row = layout.row(align=True)
row.prop(context.scene.BIMProperties, "cache_dir") row.prop(context.scene.BIMProperties, "cache_dir")
row.operator("bim.select_cache_dir", icon="FILE_FOLDER", text="") row.operator("bim.select_dir", icon="FILE_FOLDER", text="").data_path = "scene.BIMProperties.cache_dir"
row = layout.row(align=True)
row.prop(self, "tmp_dir")
row.operator("bim.select_dir", icon="FILE_FOLDER", text="").data_path = "preferences.tmp_dir"
def draw_drawing_settings(self, layout, context): def draw_drawing_settings(self, layout, context):
layout.prop(context.scene.BIMProperties, "pset_dir") layout.prop(context.scene.BIMProperties, "pset_dir")