Fix scons leaving partially generated files when aborting

This commit is contained in:
Sergey Sharybin 2014-09-12 22:56:11 +06:00
parent d939341b65
commit bd671f1005
1 changed files with 31 additions and 21 deletions

View File

@ -627,6 +627,7 @@ def data_to_c(FILE_FROM, FILE_TO, VAR_NAME):
FILE_FROM = FILE_FROM.replace("/", "\\")
FILE_TO = FILE_TO.replace("/", "\\")
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):
@ -652,6 +653,10 @@ def data_to_c(FILE_FROM, FILE_TO, VAR_NAME):
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]
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)