diff --git a/tren.py b/tren.py index 94ec2a4..615bae4 100755 --- a/tren.py +++ b/tren.py @@ -8,7 +8,7 @@ PROGNAME = "tren.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -RCSID = "$Id: tren.py,v 1.189 2010/03/12 22:19:29 tundra Exp $" +RCSID = "$Id: tren.py,v 1.190 2010/03/13 19:59:52 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -122,6 +122,19 @@ # Replacement Token Literals ##### +# Sequence Alphabets + +DECIMAL = "Decimal" +OCTAL = "Octal" +HEXLOWER = "Hexlower" +HEXUPPER = "Hexupper" +LOWER = "Lower" +LOWERUPPER = "LowerUpper" +UPPER = "Upper" +UPPERLOWER = "UpperLower" + +# General Literals + TOKDELIM = "/" # Delimiter for all renaming tokens # Shared File Attribute And Sequence Renaming Tokens @@ -243,6 +256,7 @@ ##### DEBUGFLAG = "-d" +dALPHABETS = "Alphabets" dCMDLINE = "Command Line" dCURSTATE = "Current State Of Program Options" dDEBUG = "DEBUG" @@ -356,6 +370,34 @@ TOKMYEAR : ("%04d", "ST_MTIME", "tm_year") } +# Alphabets - The User Can Add To These + +ALPHABETS = { + DECIMAL : ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], + + OCTAL : ["0", "1", "2", "3", "4", "5", "6", "7"], + + HEXLOWER : ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"], + + HEXUPPER : ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"], + + LOWER : ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", + "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" ], + + LOWERUPPER : ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", + "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", + "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", + "W", "X", "Y", "Z"], + + UPPER : ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", + "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ], + + UPPERLOWER : ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", + "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", + "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", + "w", "x", "y", "z"] + } + @@ -582,10 +624,10 @@ for i, msg in ((self.RenNames, dRENTARGET), (self.SortViews, dSORTVIEW)): for j in i: - DumpList(DebugMsg, msg, j, i[j]) + DumpList(msg, j, i[j]) for rr in self.RenRequests: - DumpList(DebugMsg, dRENREQ, "", rr) + DumpList(dRENREQ, "", rr) DebugMsg(SEPARATOR + "\n\n") @@ -1058,7 +1100,7 @@ if r[2][0] == TOKDESCEND: orderedlist.reverse() - r[2] = ComputeSeqString(field, orderedlist.index(target), ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]) + r[2] = ComputeSeqString(field, orderedlist.index(target), ALPHABETS[DECIMAL]) ### # Unrecognized Renaming Token @@ -1120,7 +1162,7 @@ fmtlen = len(fmt) - alphalen = len(alphabet) + base = len(alphabet) newval = "" carry = None @@ -1134,9 +1176,9 @@ # alphabet idigits = [] - while incr > alphalen-1: + while incr > base-1: - incr, digit = incr/alphalen, incr % alphalen + incr, digit = incr/base, incr % base idigits.append(alphabet[digit]) idigits.append(alphabet[incr]) @@ -1167,7 +1209,7 @@ # Do arithmetic modulo alphabet length - carry, digit = sum/alphalen, sum % alphalen + carry, digit = sum/base, sum % base if not carry: carry = None @@ -1256,11 +1298,11 @@ # Debug Dump Of A List ##### -def DumpList(handler, msg, listname, content): +def DumpList(msg, listname, content): - handler(msg) + DebugMsg(msg) itemarrow = ColumnPad([listname, " "], WIDTH=LSTPAD) - handler(ColumnPad([" ", " %s %s" % (itemarrow, content)])) + DebugMsg(ColumnPad([" ", " %s %s" % (itemarrow, content)])) # End of 'DumpList()' @@ -1281,6 +1323,8 @@ for o in opts: DebugMsg(ColumnPad([o, ProgramOptions[o]])) + DumpList(dALPHABETS, "", ALPHABETS) + DebugMsg(SEPARATOR) @@ -1730,13 +1774,13 @@ # Dump what we know about the command line - DumpList(DebugMsg, dCMDLINE, "", sys.argv) - DumpList(DebugMsg, dPROGENV, "", envopt) - DumpList(DebugMsg, dRESOLVEDOPTS, "", OPTIONS) + DumpList(dCMDLINE, "", sys.argv) + DumpList(dPROGENV, "", envopt) + DumpList(dRESOLVEDOPTS, "", OPTIONS) # Dump what we know about included files - DumpList(DebugMsg, dINCLFILES, "", IncludedFiles) + DumpList(dINCLFILES, "", IncludedFiles) # Dump what we know about the container