Cleaned up the rename code further when handling -r =something.
1 parent 272235b commit 64d3250fcb6c6c65cc56262fd2475aa95624fb51
@tundra tundra authored on 4 Feb 2010
Showing 1 changed file
View
50
tren.py
 
PROGNAME = "tren.py"
BASENAME = PROGNAME.split(".py")[0]
PROGENV = BASENAME.upper()
RCSID = "$Id: tren.py,v 1.142 2010/02/05 03:00:24 tundra Exp $"
RCSID = "$Id: tren.py,v 1.143 2010/02/05 03:48:17 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
 
 
for target in self.SortViews[ORDERBYCMDLINE]:
 
newname, pathname = self.RenNames[target][BASE], self.RenNames[target][PATHNAME]
basename, pathname = self.RenNames[target][BASE], self.RenNames[target][PATHNAME]
for renrequest in self.RenRequests:
 
old, new = self.ResolveRenameStrings(renrequest[OLD], renrequest[NEW])
 
oldstrings = []
 
# Build a list of indexes to every occurence of the old string,
# taking case sensitivity into account
# Handle the case when old = "".
# This means to *replace the entire* old name with new.
if not old:
oldstrings = [0,]
newname = ""
 
# Handle case where an old is non-null
else:
name = newname
 
# Collapse case if requested
if not renrequest[CASESENSITIVE]:
 
name = name.lower()
old = old.lower()
 
i = name.find(old)
while i >= 0:
 
oldstrings.append(i)
i = name.find(old, i + len(old))
old = basename
 
# Collapse case if requested
 
name = basename
if not renrequest[CASESENSITIVE]:
 
name = name.lower()
old = old.lower()
 
i = name.find(old)
while i >= 0:
 
oldstrings.append(i)
i = name.find(old, i + len(old))
 
# If we found any maching strings, replace them
 
if oldstrings:
# 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)
basename = basename[:i] + new + basename[i + len(old):]
 
print ColumnPad([target, pathname + basename], padwidth = 50)
 
# End of 'Rename()'
 
 
# Make sure the include argument has trailing space or the
# code below will break.
 
OPTIONS = " ".join(OPTIONS).replace(INCL, INCL+" ").split()
 
# Resolve include file references allowing for nested includes.
# This has to be done here separate from the command line options so
# that getopt() processing below will "see" the included statements.
 
envopt = os.getenv(PROGENV)
if envopt:
OPTIONS = envopt.split() + OPTIONS
 
 
# Check for debug manually to see if we want
# debug info about includes
 
if DEBUGFLAG in OPTIONS: