From 6616879d158b4347a6b951421701d8a042ed089a Mon Sep 17 00:00:00 2001 From: tobigun Date: Fri, 18 Jun 2010 04:37:08 +0000 Subject: - backup file extension changed from .old to .bak - backup files are only created for files that changed git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2546 b956fd51-792f-4845-bead-9b4dfca2ff2c --- game/languages/update.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'game/languages') diff --git a/game/languages/update.py b/game/languages/update.py index 74b4b774..7447b19e 100755 --- a/game/languages/update.py +++ b/game/languages/update.py @@ -111,17 +111,31 @@ def update(lang): print (" -" + m.group(1)) outList.append(";UNUSED: " + m.group(1) + "=" + m.group(2)) - oldLang = lang + ".old" - if (os.path.exists(oldLang)): - os.remove(oldLang) - os.rename(lang, oldLang) + # check if file changed + changed = False + if (len(outList) != len(translation)): + changed = True + else: + # search for a changed line + for i in range(len(outList)): + if (outList[i] != translation[i]): + changed = True + break + + # write changes + if changed: + # create a backup first + oldLang = lang + ".bak" + if (os.path.exists(oldLang)): + os.remove(oldLang) + os.rename(lang, oldLang) - f = open(lang, 'wb') - for line in outList: - # binary mode does not convert "\n" to the os specific line-ending. - # Use os.linesep instead. - f.write(line + os.linesep) - f.close() + f = open(lang, 'wb') + for line in outList: + # binary mode does not convert "\n" to the os specific line-ending. + # Use os.linesep instead. + f.write(line + os.linesep) + f.close() if len(sys.argv) >= 2: # update specific language file passed as command-line argument -- cgit v1.2.3