mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2025-12-16 01:30:07 +01:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user