| |
---|
| | |
---|
| | PROGNAME = "tren.py" |
---|
| | BASENAME = PROGNAME.split(".py")[0] |
---|
| | PROGENV = BASENAME.upper() |
---|
| | RCSID = "$Id: tren.py,v 1.158 2010/02/26 00:08:44 tundra Exp $" |
---|
| | RCSID = "$Id: tren.py,v 1.159 2010/02/26 00:24:54 tundra Exp $" |
---|
| | VERSION = RCSID.split()[2] |
---|
| | |
---|
| | # Copyright Information |
---|
| | |
---|
| |
---|
| | # If we found any matching strings, replace them |
---|
| | |
---|
| | if oldstrings: |
---|
| | |
---|
| | # Only process leftmost occurence if global replace is off |
---|
| | |
---|
| | if not renrequest[DEFINST]: |
---|
| | oldstrings = [oldstrings[0],] |
---|
| | # But only process the instances the user asked for |
---|
| | |
---|
| | todo = [] |
---|
| | |
---|
| | # Handle single instance requests |
---|
| | |
---|
| | if (renrequest[INSTANCEEND] == SINGLEINST) and (renrequest[INSTANCESTART] < len(oldstrings)): |
---|
| | todo.append(oldstrings[renrequest[INSTANCESTART]]) |
---|
| | |
---|
| | # Handle instance range requests |
---|
| | |
---|
| | else: |
---|
| | todo = oldstrings[renrequest[INSTANCESTART] : renrequest[INSTANCEEND]] |
---|
| | |
---|
| | |
---|
| | # 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: |
---|
| | todo.reverse() |
---|
| | for i in todo: |
---|
| | newname = newname[:i] + new + newname[i + len(old):] |
---|
| | |
---|
| | |
---|
| | # Nothing to do, if old- and new names are the same |
---|
| |
---|
| | |