summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-01-11 20:19:07 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-01-11 20:19:07 (GMT)
commitb4fb2e2aac17975d9c5775eb46d6dec4d0603406 (patch)
tree7671a8c4b8e365ff546b65e15c1de9299a087030 /Tools
parent154dc4e4238bc950292762bcda9b01258a81ad8c (diff)
parenta3a01b6ac3990ddd662b4bcf7de29050bd15c651 (diff)
downloadcpython-b4fb2e2aac17975d9c5775eb46d6dec4d0603406.zip
cpython-b4fb2e2aac17975d9c5775eb46d6dec4d0603406.tar.gz
cpython-b4fb2e2aac17975d9c5775eb46d6dec4d0603406.tar.bz2
Issue #15539: Fix a backup file creation in pindent.py on Windows.
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/scripts/pindent.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/Tools/scripts/pindent.py b/Tools/scripts/pindent.py
index fd04c92..2872dc0 100755
--- a/Tools/scripts/pindent.py
+++ b/Tools/scripts/pindent.py
@@ -370,6 +370,23 @@ def reformat_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs =
return output.getvalue()
# end def reformat_string
+def make_backup(filename):
+ import os, os.path
+ backup = filename + '~'
+ if os.path.lexists(backup):
+ try:
+ os.remove(backup)
+ except os.error:
+ print("Can't remove backup %r" % (backup,), file=sys.stderr)
+ # end try
+ # end if
+ try:
+ os.rename(filename, backup)
+ except os.error:
+ print("Can't rename %r to %r" % (filename, backup), file=sys.stderr)
+ # end try
+# end def make_backup
+
def complete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
with open(filename, 'r') as f:
source = f.read()
@@ -377,10 +394,7 @@ def complete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs =
result = complete_string(source, stepsize, tabsize, expandtabs)
if source == result: return 0
# end if
- import os
- try: os.rename(filename, filename + '~')
- except os.error: pass
- # end try
+ make_backup(filename)
with open(filename, 'w') as f:
f.write(result)
# end with
@@ -394,10 +408,7 @@ def delete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = E
result = delete_string(source, stepsize, tabsize, expandtabs)
if source == result: return 0
# end if
- import os
- try: os.rename(filename, filename + '~')
- except os.error: pass
- # end try
+ make_backup(filename)
with open(filename, 'w') as f:
f.write(result)
# end with
@@ -411,10 +422,7 @@ def reformat_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs =
result = reformat_string(source, stepsize, tabsize, expandtabs)
if source == result: return 0
# end if
- import os
- try: os.rename(filename, filename + '~')
- except os.error: pass
- # end try
+ make_backup(filename)
with open(filename, 'w') as f:
f.write(result)
# end with