add writeIfChanged()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@70222 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2011-12-31 10:13:46 +00:00
parent a22be70a88
commit 73554e9d4c

View File

@@ -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()