From 73554e9d4c05ba4fcfb0116875376cb3adb5f0cb Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 31 Dec 2011 10:13:46 +0000 Subject: [PATCH] add writeIfChanged() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@70222 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- buildtools/config.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/buildtools/config.py b/buildtools/config.py index 094d4adc..353d24ce 100644 --- a/buildtools/config.py +++ b/buildtools/config.py @@ -594,3 +594,18 @@ def copyIfNewer(src, dest): if newer(src, dest): shutil.copy(src, dest) + +def writeIfChanged(filename, text): + """ + Check the current contents of filename and only overwrite with text if + the content is different (therefore preserving the timestamp if there is + no update.) + """ + text = str(text) + if os.path.exists(filename): + current = open(filename, 'rt').read() + if current == text: + return + f = open(filename, 'wt') + f.write(text) + f.close()