Fixed bugs introduced by -T logic. This removed the 'name' variable from ProcessRenameRequests().
1 parent fdab147 commit fd5f899109b5da0868be772c75d1f72498c48ae7
@tundra tundra authored on 29 Aug 2010
Showing 1 changed file
View
38
tren.py
PROGNAME = "tren.py"
BASENAME = PROGNAME.split(".py")[0]
PROGENV = BASENAME.upper()
INCLENV = PROGENV + "INCL"
RCSID = "$Id: tren.py,v 1.235 2010/08/27 17:08:01 tundra Exp $"
RCSID = "$Id: tren.py,v 1.236 2010/08/30 01:52:23 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
for target in self.SortViews[ORDERBYCMDLINE]:
 
oldname, pathname = self.RenNames[target][BASE], self.RenNames[target][PATHNAME]
newname = oldname
name = oldname
 
# Keep track of incremental renaming for use by debug
RenSequence = [oldname]
if tstart == None:
tstart = 0
 
if tend == None:
tend = len(name)
tend = len(newname)
if tstart or tend:
 
bound = len(name)
bound = len(newname)
# Normalize negative refs so we can use consistent
# logic below
 
# accommodate the request without blowing up
# on the ones that are not long enough.
 
if 0 <= tstart < bound:
lname, name, rname = name[:tstart], name[tstart], name[tstart+1:]
lname, newname, rname = newname[:tstart], newname[tstart], newname[tstart+1:]
 
# Reference is out of bounds - leave name untouched
 
else:
lname, name, rname = name, "", ""
lname, newname, rname = newname, "", ""
 
# Handle slice range requests
 
else:
lname, name, rname = name[:tstart], name[tstart:tend], name[tend:]
lname, newname, rname = newname[:tstart], newname[tstart:tend], newname[tend:]
 
# Handle conventional string replacement renaming requests
 
if name and (renrequest[OLD] or renrequest[NEW]):
# An empty newname here means that the -T argument processing
# selected a new string and/or was out of bounds -> we ignore the request.
 
if newname and (renrequest[OLD] or renrequest[NEW]):
 
# Resolve any embedded renaming tokens
 
old = self.__ResolveRenameTokens(target, renrequest[OLD])
# specifically, replace the entire old name *as
# modified so far by preceding rename commands*.
 
if not old:
old = name
old = newname
 
# Find every instance of the 'old' string in the
# current filename. 'Find' in this case can be either
# a regular expression pattern match or a literal
try:
# Do the match either case-insentitive or not
 
if renrequest[CASESENSITIVE]:
rematches = re.finditer(old, name)
rematches = re.finditer(old, newname)
 
else:
rematches = re.finditer(old, name, re.I)
rematches = re.finditer(old, newname, re.I)
 
# And save off the results
 
for match in rematches:
# Collapse case if requested
 
if not renrequest[CASESENSITIVE]:
 
name = name.lower()
newname = newname.lower()
old = old.lower()
 
oldlen = len(old)
i = name.find(old)
i = newname.find(old)
while i >= 0:
 
nextloc = i + oldlen
oldstrings.append((i, nextloc))
i = name.find(old, nextloc)
i = newname.find(old, nextloc)
 
# If we found any matching strings, replace them
 
if oldstrings:
 
# Handle case conversion renaming requests
elif renrequest[CASECONV]:
newname = CASETBL[renrequest[CASECONV]](name)
newname = CASETBL[renrequest[CASECONV]](newname)
 
# Any subsequent replacements operate on the modified name
# which is reconstructed by combining what we've renamed
# with anything that was excluded from the rename operation.
 
newname = lname + newname + rname
name = newname
 
# Keep track of incremental renaming for use by debug
RenSequence.append(name)
RenSequence.append(newname)
# Show the incremental renaming steps if debug is on
 
if ProgramOptions[DEBUG]: