diff --git a/tren.py b/tren.py index 368ff8b..3dadd54 100755 --- a/tren.py +++ b/tren.py @@ -9,7 +9,7 @@ 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 @@ -943,7 +943,6 @@ 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] @@ -966,11 +965,11 @@ 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 @@ -999,22 +998,24 @@ # 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 + # 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 name and (renrequest[OLD] or renrequest[NEW]): + if newname and (renrequest[OLD] or renrequest[NEW]): # Resolve any embedded renaming tokens @@ -1032,7 +1033,7 @@ # 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 @@ -1061,10 +1062,10 @@ # 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 @@ -1082,16 +1083,16 @@ 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 @@ -1140,17 +1141,16 @@ # 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