Implemented /NAMESOFAR/ renaming token.
1 parent d18281a commit 0ebdfe3fb6d6ad693595a028cc861f103b0b1e39
@tundra tundra authored on 25 Aug 2010
Showing 1 changed file
View
35
tren.py
PROGNAME = "tren.py"
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
 
 
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
 
TOKASCEND = "+" # Ascending order flag
#----------------------------------------------------------#
# Global Variables & Data Structures #
#----------------------------------------------------------#
 
# List of all the included files
 
IncludedFiles = []
 
 
# Program toggle and option defaults
 
IncludedFiles = []
 
ProgramOptions = {
ASK : False, # Interactively ask user before renaming each file
BACKUPS : True, # Do backups during forced renaming
TESTMODE : False # Test mode off
}
 
 
# 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 ---------------------------------#
 
 
#####
 
def ProcessRenameRequests(self):
 
global RenSequence
self.indentlevel = -1
 
# Create a list of all renaming to be done.
# This includes the renaming of any existing targets.
 
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:
 
# Handle conventional string replacement renaming requests
# Any subsequent replacements operate on the modified name
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
 
if newname != oldname:
if precision < 1:
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
###