Changed renaming logic to only rename the instances specified on the command line via -i.
1 parent 071a93b commit 872e238c352faec300e5ca8cd5d96e10c260f199
@tundra tundra authored on 25 Feb 2010
Showing 1 changed file
View
34
tren.py
 
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