| |
---|
| | |
---|
| | 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 |
---|
| | |
---|
| |
---|
| | ##### |
---|
| | # 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 |
---|
| | |
---|
| |
---|
| | # Debug Messages |
---|
| | ##### |
---|
| | |
---|
| | DEBUGFLAG = "-d" |
---|
| | dALPHABETS = "Alphabets" |
---|
| | dCMDLINE = "Command Line" |
---|
| | dCURSTATE = "Current State Of Program Options" |
---|
| | dDEBUG = "DEBUG" |
---|
| | dDUMPOBJ = "Dumping Object %s" |
---|
| |
---|
| | TOKMSEC : ("%02d", "ST_MTIME", "tm_sec"), |
---|
| | 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"] |
---|
| | } |
---|
| | |
---|
| | |
---|
| | |
---|
| | |
---|
| | #----------------------------------------------------------# |
---|
| |
---|
| | |
---|
| | 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") |
---|
| | |
---|
| | # End of 'DumpObj()' |
---|
| |
---|
| | |
---|
| | 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 |
---|
| | ### |
---|
| |
---|
| | """ |
---|
| | |
---|
| | |
---|
| | fmtlen = len(fmt) |
---|
| | alphalen = len(alphabet) |
---|
| | base = len(alphabet) |
---|
| | newval = "" |
---|
| | carry = None |
---|
| | |
---|
| | |
---|
| |
---|
| | # First convert the increment into a string in the base of the |
---|
| | # alphabet |
---|
| | |
---|
| | idigits = [] |
---|
| | while incr > alphalen-1: |
---|
| | |
---|
| | incr, digit = incr/alphalen, incr % alphalen |
---|
| | while incr > base-1: |
---|
| | |
---|
| | incr, digit = incr/base, incr % base |
---|
| | idigits.append(alphabet[digit]) |
---|
| | |
---|
| | idigits.append(alphabet[incr]) |
---|
| | idigits.reverse() |
---|
| |
---|
| | sum += alphabet.index(incr[i]) |
---|
| | |
---|
| | # Do arithmetic modulo alphabet length |
---|
| | |
---|
| | carry, digit = sum/alphalen, sum % alphalen |
---|
| | carry, digit = sum/base, sum % base |
---|
| | |
---|
| | if not carry: |
---|
| | carry = None |
---|
| | |
---|
| |
---|
| | ##### |
---|
| | # Debug Dump Of A List |
---|
| | ##### |
---|
| | |
---|
| | def DumpList(handler, msg, listname, content): |
---|
| | |
---|
| | handler(msg) |
---|
| | def DumpList(msg, listname, content): |
---|
| | |
---|
| | DebugMsg(msg) |
---|
| | itemarrow = ColumnPad([listname, " "], WIDTH=LSTPAD) |
---|
| | handler(ColumnPad([" ", " %s %s" % (itemarrow, content)])) |
---|
| | DebugMsg(ColumnPad([" ", " %s %s" % (itemarrow, content)])) |
---|
| | |
---|
| | # End of 'DumpList()' |
---|
| | |
---|
| | |
---|
| |
---|
| | opts = ProgramOptions.keys() |
---|
| | opts.sort() |
---|
| | for o in opts: |
---|
| | DebugMsg(ColumnPad([o, ProgramOptions[o]])) |
---|
| | |
---|
| | DumpList(dALPHABETS, "", ALPHABETS) |
---|
| | |
---|
| | DebugMsg(SEPARATOR) |
---|
| | |
---|
| | |
---|
| |
---|
| | if ProgramOptions[DEBUG]: |
---|
| | |
---|
| | # 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 |
---|
| | |
---|
| | targs.DumpObj() |
---|
| |
---|
| | |
|