mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Merged revisions 66805,66841,66860,66884-66886,66893,66907,66910 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r66805 | benjamin.peterson | 2008-10-04 20:11:02 -0500 (Sat, 04 Oct 2008) | 1 line mention what the fixes directory is for ........ r66841 | benjamin.peterson | 2008-10-07 17:48:12 -0500 (Tue, 07 Oct 2008) | 1 line use assertFalse and assertTrue ........ r66860 | benjamin.peterson | 2008-10-08 16:05:07 -0500 (Wed, 08 Oct 2008) | 1 line instead of abusing the pattern matcher, use start_tree to find a next binding ........ r66884 | benjamin.peterson | 2008-10-13 15:50:30 -0500 (Mon, 13 Oct 2008) | 1 line don't print tokens to stdout when -v is given ........ r66885 | benjamin.peterson | 2008-10-13 16:28:57 -0500 (Mon, 13 Oct 2008) | 1 line add the -x option to disable fixers ........ r66886 | benjamin.peterson | 2008-10-13 16:33:53 -0500 (Mon, 13 Oct 2008) | 1 line cut down on some crud ........ r66893 | benjamin.peterson | 2008-10-14 17:16:54 -0500 (Tue, 14 Oct 2008) | 1 line add an optional set literal fixer ........ r66907 | benjamin.peterson | 2008-10-15 16:59:41 -0500 (Wed, 15 Oct 2008) | 1 line don't write backup files by default ........ r66910 | benjamin.peterson | 2008-10-15 17:43:10 -0500 (Wed, 15 Oct 2008) | 1 line add the -n option; it stops backupfiles from being written ........
This commit is contained in:
parent
1fb84519b1
commit
6ae94ee299
8 changed files with 248 additions and 53 deletions
|
|
@ -36,9 +36,7 @@ def get_all_fix_names(fixer_pkg, remove_prefix=True):
|
|||
pkg = __import__(fixer_pkg, [], [], ["*"])
|
||||
fixer_dir = os.path.dirname(pkg.__file__)
|
||||
fix_names = []
|
||||
names = os.listdir(fixer_dir)
|
||||
names.sort()
|
||||
for name in names:
|
||||
for name in sorted(os.listdir(fixer_dir)):
|
||||
if name.startswith("fix_") and name.endswith(".py"):
|
||||
if remove_prefix:
|
||||
name = name[4:]
|
||||
|
|
@ -253,7 +251,7 @@ class RefactoringTool(object):
|
|||
there were errors during the parse.
|
||||
"""
|
||||
try:
|
||||
tree = self.driver.parse_string(data,1)
|
||||
tree = self.driver.parse_string(data)
|
||||
except Exception, err:
|
||||
self.log_error("Can't parse %s: %s: %s",
|
||||
name, err.__class__.__name__, err)
|
||||
|
|
@ -352,23 +350,13 @@ class RefactoringTool(object):
|
|||
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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue