From 0e36e56c1c05d42bed54fa05f44662eba5d7a867 Mon Sep 17 00:00:00 2001 From: ViperMaul Date: Sun, 10 May 2015 22:12:57 -0700 Subject: [PATCH] Proper handling $PBOPREFIX$ backups and cleanup if canceled. #1105 --- tools/make.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/tools/make.py b/tools/make.py index 89ba17a0c1..3d70c28f0a 100644 --- a/tools/make.py +++ b/tools/make.py @@ -533,20 +533,12 @@ def get_commit_ID(): def version_stamp_pboprefix(module,commitID): ### Update pboPrefix with the correct version stamp. Use commit_id as the build number. + #This function will not handle any $PBOPREFIX$ backup or cleanup. global work_drive global prefix - try: - configpath = os.path.join(work_drive, prefix, module, "$PBOPREFIX$") - if os.path.isfile(configpath): - shutil.copyfile(configpath, os.path.join(work_drive, prefix, module, "$PBOPREFIX$.backup")) - else: - print_error("$PBOPREFIX$ Does not exist for module: {}.".format(module)) - return False - except: - print_error("Error updating $PBOPREFIX$ for module {}.") - return False - + configpath = os.path.join(work_drive, prefix, module, "$PBOPREFIX$") + try: f = open(configpath, "r") configtext = f.read() @@ -568,7 +560,6 @@ def version_stamp_pboprefix(module,commitID): f = open(configpath, "w") f.write(configtext) f.close() - os.remove(os.path.join(work_drive, prefix, module, "$PBOPREFIX$.backup")) else: os.remove(os.path.join(work_drive, prefix, module, "$PBOPREFIX$")) os.rename(os.path.join(work_drive, prefix, module, "$PBOPREFIX$.backup"), os.path.join(work_drive, prefix, module, "$PBOPREFIX$")) @@ -578,19 +569,14 @@ def version_stamp_pboprefix(module,commitID): f = open(configpath, "a") f.write("\nversion = {}".format(commitID)) f.close() - os.remove(os.path.join(work_drive, prefix, module, "$PBOPREFIX$.backup")) - + else: + os.remove(os.path.join(work_drive, prefix, module, "$PBOPREFIX$")) + os.rename(os.path.join(work_drive, prefix, module, "$PBOPREFIX$.backup"), os.path.join(work_drive, prefix, module, "$PBOPREFIX$")) except: print_error("Failed to include build number") raise return False - finally: - if os.path.isfile(os.path.join(work_drive, prefix, module, "$PBOPREFIX$.backup")): - if os.path.isfile(os.path.join(work_drive, prefix, module, "$PBOPREFIX$")): - os.remove(os.path.join(work_drive, prefix, module, "$PBOPREFIX$")) - os.rename(os.path.join(work_drive, prefix, module, "$PBOPREFIX$.backup"), os.path.join(work_drive, prefix, module, "$PBOPREFIX$")) - return True ############################################################################### @@ -1018,6 +1004,16 @@ See the make.cfg file for additional build options. if build_tool == "pboproject": try: #PABST: Convert config (run the macro'd config.cpp through CfgConvert twice to produce a de-macro'd cpp that pboProject can read without fucking up: + try: + configpath = os.path.join(work_drive, prefix, module, "$PBOPREFIX$") + if os.path.isfile(configpath): + shutil.copyfile(configpath, os.path.join(work_drive, prefix, module, "$PBOPREFIX$.backup")) + else: + print_error("$PBOPREFIX$ Does not exist for module: {}.".format(module)) + return False + except: + print_error("Error creating backup of $PBOPREFIX$ for module {}.") + shutil.copyfile(os.path.join(work_drive, prefix, module, "config.cpp"), os.path.join(work_drive, prefix, module, "config.backup")) os.chdir("P:\\")