diff --git a/tren.py b/tren.py index 707d8cd..54ad8b2 100755 --- a/tren.py +++ b/tren.py @@ -8,7 +8,7 @@ PROGNAME = "tren.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -RCSID = "$Id: tren.py,v 1.161 2010/02/26 18:15:15 tundra Exp $" +RCSID = "$Id: tren.py,v 1.162 2010/02/26 18:56:41 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -450,6 +450,7 @@ oldname, pathname = self.RenNames[target][BASE], self.RenNames[target][PATHNAME] newname = oldname + name = oldname for renrequest in self.RenRequests: @@ -465,14 +466,6 @@ if not old: old = oldname - # Collapse case if requested - - name = oldname - if not renrequest[CASESENSITIVE]: - - name = name.lower() - old = old.lower() - # 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 @@ -497,7 +490,15 @@ if renrequest[REGEX]: try: - rematches = re.finditer(old, name) + # Do the match either case-insentitive or not + + if renrequest[CASESENSITIVE]: + rematches = re.finditer(old, name) + else: + rematches = re.finditer(old, name, re.I) + + # And save off the results + for match in rematches: oldstrings.append((match.start(), match.end())) @@ -508,6 +509,13 @@ else: + # Collapse case if requested + + if not renrequest[CASESENSITIVE]: + + name = name.lower() + old = old.lower() + oldlen = len(old) i = name.find(old) while i >= 0: @@ -519,7 +527,7 @@ # If we found any matching strings, replace them if oldstrings: - + # But only process the instances the user asked for todo = [] @@ -559,6 +567,9 @@ for i in todo: newname = newname[:i[0]] + new + newname[i[1]:] + # Any subsequent replacements operate on the modified name + + name = newname # Nothing to do, if old- and new names are the same