[scannermain] Use mkstemp
authorJohan Dahlin <johan@gnome.org>
Thu, 2 Sep 2010 20:36:09 +0000 (17:36 -0300)
committerJohan Dahlin <johan@gnome.org>
Thu, 2 Sep 2010 20:36:09 +0000 (17:36 -0300)
Since the delete parameter of NamedTemporaryFile is only
available on python 2.6

giscanner/scannermain.py

index 9b6d67512dffa3d3aa784b6aff86580063f2401d..42f74b7d562b1cb3490f3ecc85fecc96611138e5 100644 (file)
@@ -353,22 +353,24 @@ def scanner_main(args):
     if options.output == "-":
         output = sys.stdout
     elif options.reparse_validate_gir:
-        main_f = tempfile.NamedTemporaryFile(suffix='.gir', delete=False)
+        main_f, main_f_name = tempfile.mkstemp(suffix='.gir')
+        main_f = os.fdopen(main_f, 'w')
         main_f.write(data)
         main_f.close()
 
-        temp_f = tempfile.NamedTemporaryFile(suffix='.gir', delete=False)
-        passthrough_gir(main_f.name, temp_f)
+        temp_f, temp_f_name = tempfile.mkstemp(suffix='.gir')
+        temp_f = os.fdopen(temp_f, 'w')
+        passthrough_gir(main_f_name, temp_f)
         temp_f.close()
-        if not files_are_identical(main_f.name, temp_f.name):
+        if not files_are_identical(main_f_name, temp_f_name):
             _error("Failed to re-parse gir file; scanned=%r passthrough=%r" % (
-                main_f.name, temp_f.name))
-        os.unlink(temp_f.name)
+                main_f_name, temp_f_name))
+        os.unlink(temp_f_name)
         try:
-            shutil.move(main_f.name, options.output)
+            shutil.move(main_f_name, options.output)
         except OSError, e:
             if e.errno == errno.EPERM:
-                os.unlink(main_f.name)
+                os.unlink(main_f_name)
                 return 0
             raise
         return 0