[Python-checkins] r66907 - in sandbox/trunk/2to3/lib2to3: main.py refactor.py tests/test_refactor.py
benjamin.peterson
python-checkins at python.org
Wed Oct 15 23:59:42 CEST 2008
Author: benjamin.peterson
Date: Wed Oct 15 23:59:41 2008
New Revision: 66907
Log:
don't write backup files by default
Modified:
sandbox/trunk/2to3/lib2to3/main.py
sandbox/trunk/2to3/lib2to3/refactor.py
sandbox/trunk/2to3/lib2to3/tests/test_refactor.py
Modified: sandbox/trunk/2to3/lib2to3/main.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/main.py (original)
+++ sandbox/trunk/2to3/lib2to3/main.py Wed Oct 15 23:59:41 2008
@@ -19,6 +19,22 @@
self.errors.append((msg, args, kwargs))
self.logger.error(msg, *args, **kwargs)
+ def write_file(self, new_text, filename, old_text):
+ # Make backup
+ backup = filename + ".bak"
+ if os.path.lexists(backup):
+ try:
+ os.remove(backup)
+ except os.error, err:
+ self.log_message("Can't remove backup %s", backup)
+ try:
+ os.rename(filename, backup)
+ except os.error, err:
+ self.log_message("Can't rename %s to %s", filename, backup)
+ # Actually write the new file
+ super(StdoutRefactoringTool, self).write_file(new_text,
+ filename, old_text)
+
def print_output(self, lines):
for line in lines:
print line
Modified: sandbox/trunk/2to3/lib2to3/refactor.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/refactor.py (original)
+++ sandbox/trunk/2to3/lib2to3/refactor.py Wed Oct 15 23:59:41 2008
@@ -350,23 +350,13 @@
else:
self.log_debug("Not writing changes to %s", filename)
- def write_file(self, new_text, filename, old_text=None):
+ def write_file(self, new_text, filename, old_text):
"""Writes a string to a file.
It first shows a unified diff between the old text and the new text, and
then rewrites the file; the latter is only done if the write option is
set.
"""
- backup = filename + ".bak"
- if os.path.lexists(backup):
- try:
- os.remove(backup)
- except os.error, err:
- self.log_message("Can't remove backup %s", backup)
- try:
- os.rename(filename, backup)
- except os.error, err:
- self.log_message("Can't rename %s to %s", filename, backup)
try:
f = open(filename, "w")
except os.error, err:
Modified: sandbox/trunk/2to3/lib2to3/tests/test_refactor.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_refactor.py (original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_refactor.py Wed Oct 15 23:59:41 2008
@@ -123,7 +123,6 @@
def test_refactor_file(self):
test_file = os.path.join(FIXER_DIR, "parrot_example.py")
- backup = test_file + ".bak"
old_contents = open(test_file, "r").read()
rt = self.rt()
@@ -133,14 +132,8 @@
rt.refactor_file(test_file, True)
try:
self.assertNotEqual(old_contents, open(test_file, "r").read())
- self.assertTrue(os.path.exists(backup))
- self.assertEqual(old_contents, open(backup, "r").read())
finally:
open(test_file, "w").write(old_contents)
- try:
- os.unlink(backup)
- except OSError:
- pass
def test_refactor_docstring(self):
rt = self.rt()
More information about the Python-checkins
mailing list