Skip to content

Commit

Permalink
BlenderBIM some data_dir / schema_dir workarounds (#1606)
Browse files Browse the repository at this point in the history
* write process.log to a tempdir if data_dir is not writable

* Don't include filename returned by data_dir and schema_dir chooser
  • Loading branch information
brunopostle committed Jul 29, 2021
1 parent e06591b commit 7b22f9c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/blenderbim/blenderbim/bim/operator.py
Expand Up @@ -2,6 +2,7 @@
import bpy
import time
import json
import tempfile
import logging
import webbrowser
import ifcopenshell
Expand Down Expand Up @@ -43,8 +44,11 @@ def execute(self, context):
def _execute(self, context):
start = time.time()
logger = logging.getLogger("ExportIFC")
path_log = os.path.join(bpy.context.scene.BIMProperties.data_dir, "process.log"),
if not os.access(bpy.context.scene.BIMProperties.data_dir, os.W_OK):
path_log = os.path.join(tempfile.mkdtemp(), "process.log")
logging.basicConfig(
filename=os.path.join(context.scene.BIMProperties.data_dir, "process.log"),
filename=path_log,
filemode="a",
level=logging.DEBUG,
)
Expand Down Expand Up @@ -105,8 +109,11 @@ class ImportIFC(bpy.types.Operator, ImportHelper):
def execute(self, context):
start = time.time()
logger = logging.getLogger("ImportIFC")
path_log = os.path.join(bpy.context.scene.BIMProperties.data_dir, "process.log"),
if not os.access(bpy.context.scene.BIMProperties.data_dir, os.W_OK):
path_log = os.path.join(tempfile.mkdtemp(), "process.log")
logging.basicConfig(
filename=os.path.join(bpy.context.scene.BIMProperties.data_dir, "process.log"),
filename=path_log,
filemode="a",
level=logging.DEBUG,
)
Expand Down Expand Up @@ -169,7 +176,7 @@ class SelectDataDir(bpy.types.Operator):
filepath: bpy.props.StringProperty(subtype="FILE_PATH")

def execute(self, context):
bpy.context.scene.BIMProperties.data_dir = self.filepath
bpy.context.scene.BIMProperties.data_dir = os.path.dirname(self.filepath)
return {"FINISHED"}

def invoke(self, context, event):
Expand All @@ -184,7 +191,7 @@ class SelectSchemaDir(bpy.types.Operator):
filepath: bpy.props.StringProperty(subtype="FILE_PATH")

def execute(self, context):
bpy.context.scene.BIMProperties.schema_dir = self.filepath
bpy.context.scene.BIMProperties.schema_dir = os.path.dirname(self.filepath)
return {"FINISHED"}

def invoke(self, context, event):
Expand Down

0 comments on commit 7b22f9c

Please sign in to comment.