[Bf-blender-cvs] [bd671f1] master: Fix scons leaving partially generated files when aborting

Sergey Sharybin noreply at git.blender.org
Fri Sep 12 18:56:43 CEST 2014


Commit: bd671f10055b86a6a2a114f8e323414823ce18d2
Author: Sergey Sharybin
Date:   Fri Sep 12 22:56:11 2014 +0600
Branches: master
https://developer.blender.org/rBbd671f10055b86a6a2a114f8e323414823ce18d2

Fix scons leaving partially generated files when aborting

===================================================================

M	SConstruct

===================================================================

diff --git a/SConstruct b/SConstruct
index d1d0db9..1ff984a 100644
--- a/SConstruct
+++ b/SConstruct
@@ -627,31 +627,36 @@ def data_to_c(FILE_FROM, FILE_TO, VAR_NAME):
         FILE_FROM = FILE_FROM.replace("/", "\\")
         FILE_TO   = FILE_TO.replace("/", "\\")
 
-    # first check if we need to bother.
-    if os.path.exists(FILE_TO):
-        if os.path.getmtime(FILE_FROM) < os.path.getmtime(FILE_TO):
-            return
-
-    print(B.bc.HEADER + "Generating: " + B.bc.ENDC + "%r" % os.path.basename(FILE_TO))
-    fpin = open(FILE_FROM, "rb")
-    fpin.seek(0, os.SEEK_END)
-    size = fpin.tell()
-    fpin.seek(0)
-
-    fpout = open(FILE_TO, "w")
-    fpout.write("int  %s_size = %d;\n" % (VAR_NAME, size))
-    fpout.write("char %s[] = {\n" % VAR_NAME)
-
-    while size > 0:
-        size -= 1
-        if size % 32 == 31:
-            fpout.write("\n")
-
-        fpout.write("%3d," % ord(fpin.read(1)))
-    fpout.write("\n  0};\n\n")
-
-    fpin.close()
-    fpout.close()
+    try:
+        # first check if we need to bother.
+        if os.path.exists(FILE_TO):
+            if os.path.getmtime(FILE_FROM) < os.path.getmtime(FILE_TO):
+                return
+
+        print(B.bc.HEADER + "Generating: " + B.bc.ENDC + "%r" % os.path.basename(FILE_TO))
+        fpin = open(FILE_FROM, "rb")
+        fpin.seek(0, os.SEEK_END)
+        size = fpin.tell()
+        fpin.seek(0)
+
+        fpout = open(FILE_TO, "w")
+        fpout.write("int  %s_size = %d;\n" % (VAR_NAME, size))
+        fpout.write("char %s[] = {\n" % VAR_NAME)
+
+        while size > 0:
+            size -= 1
+            if size % 32 == 31:
+                fpout.write("\n")
+
+            fpout.write("%3d," % ord(fpin.read(1)))
+        fpout.write("\n  0};\n\n")
+
+        fpin.close()
+        fpout.close()
+    except KeyboardInterrupt:
+        if os.path.exists(FILE_TO):
+            os.remove(FILE_TO)
+        raise KeyboardInterrupt
 
 def data_to_c_simple(FILE_FROM):
 	filename_only = os.path.basename(FILE_FROM)
@@ -676,7 +681,12 @@ def data_to_c_simple_icon(PATH_FROM):
     FILE_TO_PNG = os.path.join(env['DATA_SOURCES'], filename_only + ".png")
     FILE_TO = FILE_TO_PNG + ".c"
     argv = [PATH_FROM, FILE_TO_PNG]
-    datatoc_icon.main_ex(argv)
+    try:
+        datatoc_icon.main_ex(argv)
+    except KeyboardInterrupt:
+        if os.path.exists(FILE_TO_PNG):
+            os.remove(FILE_TO_PNG)
+        raise KeyboardInterrupt
 
     # then the png to a c file
     data_to_c_simple(FILE_TO_PNG)




More information about the Bf-blender-cvs mailing list