From: Marc Fiuczynski Date: Fri, 15 Feb 2008 22:20:06 +0000 (+0000) Subject: This fix to the MakeRequest() method gets rid of the hiddeous X-Git-Tag: BootManager-3.2-5~26 X-Git-Url: http://git.onelab.eu/?p=bootmanager.git;a=commitdiff_plain;h=47a0bab06bb25472c6ca1304357ec510136c5eeb This fix to the MakeRequest() method gets rid of the hiddeous exception message that shows up when a node goes into debug mode. For example, in the past one would see this type of message on the console: Exception exceptions.OSError: (2, 'No such file or directory', '/tmp/tmpBjmo14') in ', mode 'w+b' at 0xb7b108d8>> ignored This is no longer the case. --- diff --git a/source/BootServerRequest.py b/source/BootServerRequest.py index 75fad3c..1af0ece 100644 --- a/source/BootServerRequest.py +++ b/source/BootServerRequest.py @@ -178,12 +178,11 @@ class BootServerRequest: MaxTransferTime= DEFAULT_CURL_MAX_TRANSFER_TIME, FormData= None): - if hasattr(tempfile, "NamedTemporaryFile"): - buffer = tempfile.NamedTemporaryFile() - buffer_name = buffer.name - else: - buffer_name = tempfile.mktemp("MakeRequest") - buffer = open(buffer_name, "w+") + (fd, buffer_name) = tempfile.mkstemp("MakeRequest-XXXXXX") + os.close(fd) + buffer = open(buffer_name, "w+b") + + # the file "buffer_name" will be deleted by DownloadFile() ok = self.DownloadFile(PartialPath, GetVars, PostVars, DoSSL, DoCertCheck, buffer_name, @@ -191,12 +190,21 @@ class BootServerRequest: MaxTransferTime, FormData) - # check the code, return the string only if it was successfull + # check the ok code, return the string only if it was successfull if ok: buffer.seek(0) - return buffer.read() + ret = buffer.read() else: - return None + ret = None + + buffer.close() + try: + # just in case it is not deleted by DownloadFile() + os.unlink(buffer_name) + except OSError: + pass + + return ret def DownloadFile(self, PartialPath, GetVars, PostVars, DoSSL, DoCertCheck, DestFilePath,