diff --git a/tren.py b/tren.py index 54fed8f..2bc1aef 100755 --- a/tren.py +++ b/tren.py @@ -9,7 +9,7 @@ BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() INCLENV = PROGENV + "INCL" -RCSID = "$Id: tren.py,v 1.228 2010/08/25 19:47:35 tundra Exp $" +RCSID = "$Id: tren.py,v 1.229 2010/08/25 20:14:14 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -250,6 +250,7 @@ TOKCMDEXEC = "`" # Delimiter for command execution renaming tokens TOKENV = "$" # Introducer for environment variable replacement tokens TOKRAND = "RAND" # Random replacement token +TOKNAMESOFAR = "NAMESOFAR" # New name so far # Sequence Renaming Tokens @@ -513,10 +514,13 @@ # Global Variables & Data Structures # #----------------------------------------------------------# -# Program toggle and option defaults +# List of all the included files IncludedFiles = [] + +# Program toggle and option defaults + ProgramOptions = { ASK : False, # Interactively ask user before renaming each file BACKUPS : True, # Do backups during forced renaming @@ -536,6 +540,11 @@ } +# Used to track the sequence of name transformations as each renaming +# request is applied. The -1th entry is thus also the "name so far" +# used for the /NAMESOFAR/ renaming token. + +RenSequence = [] #--------------------------- Code Begins Here ---------------------------------# @@ -917,6 +926,7 @@ def ProcessRenameRequests(self): + global RenSequence self.indentlevel = -1 # Create a list of all renaming to be done. @@ -924,13 +934,12 @@ for target in self.SortViews[ORDERBYCMDLINE]: - rensequence = [] oldname, pathname = self.RenNames[target][BASE], self.RenNames[target][PATHNAME] newname = oldname name = oldname # Keep track of incremental renaming for use by debug - rensequence.append(oldname) + RenSequence = [oldname] for renrequest in self.RenRequests: @@ -1068,12 +1077,12 @@ name = newname # Keep track of incremental renaming for use by debug - rensequence.append(newname) + RenSequence.append(newname) # Show the incremental renaming steps if debug is on if ProgramOptions[DEBUG]: - DebugMsg(dRENSEQ % ARROW.join(rensequence)) + DebugMsg(dRENSEQ % ARROW.join(RenSequence)) # Nothing to do, if old- and new names are the same @@ -1389,7 +1398,12 @@ ErrorMsg(eTOKRANDIG % fullrentoken) fmt = '"%0' + str(precision) + 'd" % random.randint(0, pow(10, precision)-1)' - r[2] = eval(fmt) + r[2] = eval(fmt) + + # Name So Far Replacement Token + + elif r[2] == (TOKNAMESOFAR): + r[2] = RenSequence[-1] ### # Sequence Renaming Tokens