| |
---|
| | |
---|
| | PROGNAME = "tren.py" |
---|
| | BASENAME = PROGNAME.split(".py")[0] |
---|
| | PROGENV = BASENAME.upper() |
---|
| | RCSID = "$Id: tren.py,v 1.140 2010/02/03 23:56:38 tundra Exp $" |
---|
| | RCSID = "$Id: tren.py,v 1.141 2010/02/04 19:55:27 tundra Exp $" |
---|
| | VERSION = RCSID.split()[2] |
---|
| | |
---|
| | # Copyright Information |
---|
| | |
---|
| |
---|
| | old, new = self.ResolveRenameStrings(renrequest[OLD], renrequest[NEW]) |
---|
| | |
---|
| | # Handle global vs. 1st occurence replacement |
---|
| | |
---|
| | if renrequest[GLOBAL]: |
---|
| | newname = newname.replace(old, new) |
---|
| | |
---|
| | else: |
---|
| | i = newname.find(old) |
---|
| | if i >= 0: |
---|
| | oldstrings = [] |
---|
| | |
---|
| | # Build a list of indexes to every occurence of the old string |
---|
| | |
---|
| | i = newname.find(old) |
---|
| | while i >= 0: |
---|
| | |
---|
| | oldstrings.append(i) |
---|
| | |
---|
| | i = newname.find(old, i + len(old)) |
---|
| | |
---|
| | if oldstrings: |
---|
| | |
---|
| | # Only process leftmost occurence if global replace is off |
---|
| | |
---|
| | if not renrequest[GLOBAL]: |
---|
| | oldstrings = [oldstrings[0],] |
---|
| | |
---|
| | # Replace selected substring(s). |
---|
| | # Substitute from R->L in original string |
---|
| | # so as not to mess up the replacement indicies. |
---|
| | |
---|
| | oldstrings.reverse() |
---|
| | for i in oldstrings: |
---|
| | newname = newname[:i] + new + newname[i + len(old):] |
---|
| | |
---|
| | print ColumnPad([target, pathname + newname], padwidth = 50) |
---|
| | |
---|
| |
---|
| | |