From 81c5994e05d650777f31a281d3497c2930b01efa Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Tue, 16 Aug 2016 11:17:45 -0300 Subject: [PATCH] Arch: Fixed use of tempfile.mkstemp - fixes #2674 --- src/Mod/Arch/ArchServer.py | 4 +++- src/Mod/Arch/importIFC.py | 5 ++++- src/Mod/Arch/importIFClegacy.py | 3 ++- src/Mod/Arch/importSH3D.py | 6 ++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Mod/Arch/ArchServer.py b/src/Mod/Arch/ArchServer.py index 4fb24a404..8408f0cf6 100644 --- a/src/Mod/Arch/ArchServer.py +++ b/src/Mod/Arch/ArchServer.py @@ -282,12 +282,14 @@ class _BimServerTaskPanel: FreeCAD.Console.PrintMessage(translate("Arch","Opening file...\n")) self.form.labelStatus.setText(translate("Arch","Opening file...")) if not tf: - tf = tempfile.mkstemp(suffix=".ifc")[1] + th,tf = tempfile.mkstemp(suffix=".ifc") f = open(tf,"wb") f.write(base64.b64decode(downloaddata)) f.close() + os.close(th) import importIFC importIFC.open(tf) + os.remove(tf) self.form.labelStatus.setText("") def uploadFile(self): diff --git a/src/Mod/Arch/importIFC.py b/src/Mod/Arch/importIFC.py index 463f89c71..e4639ccad 100644 --- a/src/Mod/Arch/importIFC.py +++ b/src/Mod/Arch/importIFC.py @@ -923,10 +923,11 @@ def export(exportList,filename): template = template.replace("$project",FreeCAD.ActiveDocument.Name) template = template.replace("$filename",filename) template = template.replace("$timestamp",str(time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()))) - templatefile = tempfile.mkstemp(suffix=".ifc")[1] + templatefilehandle,templatefile = tempfile.mkstemp(suffix=".ifc") of = pyopen(templatefile,"wb") of.write(template.encode("utf8")) of.close() + os.close(templatefilehandle) global ifcfile, surfstyles, clones, sharedobjects ifcfile = ifcopenshell.open(templatefile) history = ifcfile.by_type("IfcOwnerHistory")[0] @@ -1280,6 +1281,8 @@ def export(exportList,filename): if STORE_UID: # some properties might have been changed FreeCAD.ActiveDocument.recompute() + + os.remove(templatefile) def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tessellation=1): diff --git a/src/Mod/Arch/importIFClegacy.py b/src/Mod/Arch/importIFClegacy.py index 6db269698..d3d62c17e 100644 --- a/src/Mod/Arch/importIFClegacy.py +++ b/src/Mod/Arch/importIFClegacy.py @@ -691,10 +691,11 @@ def getShape(obj,objid): try: if MAKETEMPFILES: import tempfile - tf = tempfile.mkstemp(suffix=".brp")[1] + th,tf = tempfile.mkstemp(suffix=".brp") of = pyopen(tf,"wb") of.write(brep_data) of.close() + os.close(th) sh = Part.read(tf) os.remove(tf) else: diff --git a/src/Mod/Arch/importSH3D.py b/src/Mod/Arch/importSH3D.py index 67f48cefd..323f0542f 100644 --- a/src/Mod/Arch/importSH3D.py +++ b/src/Mod/Arch/importSH3D.py @@ -125,10 +125,11 @@ class SH3DHandler(xml.sax.ContentHandler): elif tag == "pieceOfFurniture": name = attributes["name"] data = self.z.read(attributes["model"]) - tf = tempfile.mkstemp(suffix=".obj")[1] + th,tf = tempfile.mkstemp(suffix=".obj") f = pyopen(tf,"wb") f.write(data) f.close() + os.close(th) m = Mesh.read(tf) fx = (float(attributes["width"])/100)/m.BoundBox.XLength fy = (float(attributes["height"])/100)/m.BoundBox.YLength @@ -153,10 +154,11 @@ class SH3DHandler(xml.sax.ContentHandler): elif tag == "doorOrWindow": name = attributes["name"] data = self.z.read(attributes["model"]) - tf = tempfile.mkstemp(suffix=".obj")[1] + th,tf = tempfile.mkstemp(suffix=".obj") f = pyopen(tf,"wb") f.write(data) f.close() + os.close(th) m = Mesh.read(tf) fx = (float(attributes["width"])/100)/m.BoundBox.XLength fy = (float(attributes["height"])/100)/m.BoundBox.YLength