| |
---|
| | # Program Information |
---|
| | |
---|
| | PROGNAME = "tren.py" |
---|
| | PROGENV = PROGNAME.split(".py")[0].upper() |
---|
| | RCSID = "$Id: tren.py,v 1.111 2010/01/26 01:23:14 tundra Exp $" |
---|
| | RCSID = "$Id: tren.py,v 1.112 2010/01/26 23:02:40 tundra Exp $" |
---|
| | VERSION = RCSID.split()[2] |
---|
| | |
---|
| | # Copyright Information |
---|
| | |
---|
| |
---|
| | #----------------------------------------------------------# |
---|
| | |
---|
| | import getopt |
---|
| | import os |
---|
| | from stat import * |
---|
| | import sys |
---|
| | |
---|
| | |
---|
| | #----------------------------------------------------------# |
---|
| |
---|
| | DEBUGFLAG = "-d" |
---|
| | dCMDLINE = "Command Line" |
---|
| | dCURSTATE = "Current State Of Program Options" |
---|
| | dDEBUG = "DEBUG" |
---|
| | dDUMPOBJ = "Dumping Object %s" |
---|
| | dELLIPSIS = "..." |
---|
| | dINCLUDING = "Including file '%s'" |
---|
| | dPAIR = "Option/Target Pair" |
---|
| | dPROGENV = "$" + PROGENV |
---|
| | dRESOLVEDOPTS = "Resolved Command Line" |
---|
| |
---|
| | #----------------------------------------------------------# |
---|
| | # Object Base Class Definitions # |
---|
| | #----------------------------------------------------------# |
---|
| | |
---|
| | |
---|
| | ##### |
---|
| | # Container For Holding Rename Targets |
---|
| | ##### |
---|
| | |
---|
| | class RenameTargets: |
---|
| | |
---|
| | def __init__(self, targs): |
---|
| | |
---|
| | # Dictionary of all rename targets and their stat info |
---|
| | |
---|
| | self.RenNames = {} |
---|
| | |
---|
| | # Ordered lists used by sequence renaming tokens |
---|
| | |
---|
| | self.cmdorder = [] # Order targets appear on command line |
---|
| | self.ctimes = {} # List of creation times |
---|
| | self.sizes = {} # list of sizes |
---|
| | |
---|
| | |
---|
| | # Populate the data structures |
---|
| | |
---|
| | for t in targs: |
---|
| | |
---|
| | fullname = os.path.abspath(t) |
---|
| | basename = os.path.basename(t) |
---|
| | stat = os.stat(fullname) |
---|
| | self.RenNames[fullname] = [basename, stat] |
---|
| | |
---|
| | self.cmdorder.append(t) |
---|
| | self.ctimes[stat[ST_CTIME]] = fullname |
---|
| | self.sizes[stat[ST_SIZE]] = fullname |
---|
| | |
---|
| | |
---|
| | # Sort the relevant sequence renaming token lists |
---|
| | |
---|
| | self.ByCtime = self.ctimes.keys() |
---|
| | self.ByCtime.sort() |
---|
| | self.BySize = self.sizes.keys() |
---|
| | self.BySize.sort() |
---|
| | |
---|
| | if DEBUG: |
---|
| | DumpRenameObj(self) |
---|
| | |
---|
| | # End of class 'RenameTargets()' |
---|
| | |
---|
| | |
---|
| | #----------------------------------------------------------# |
---|
| | # Supporting Function Definitions # |
---|
| |
---|
| | for l in list: |
---|
| | l = str(l) |
---|
| | retval += l + ((padwidth - len(l)) * padchar) |
---|
| | |
---|
| | return retval.strip() |
---|
| | return retval.strip() |
---|
| | |
---|
| | # End of 'ColumnPad()' |
---|
| | |
---|
| | |
---|
| |
---|
| | # End of 'DebugMsg()' |
---|
| | |
---|
| | |
---|
| | ##### |
---|
| | # Dump The Contents Of A Rename Object |
---|
| | ##### |
---|
| | |
---|
| | def DumpRenameObj(obj): |
---|
| | |
---|
| | DebugMsg("\n") |
---|
| | DebugMsg(SEPARATOR) |
---|
| | DebugMsg(dDUMPOBJ % str(obj)) |
---|
| | DebugMsg(SEPARATOR) |
---|
| | |
---|
| | for name in obj.RenNames: |
---|
| | DebugMsg(name) |
---|
| | for item in obj.RenNames[name]: |
---|
| | DebugMsg(ColumnPad([dELLIPSIS, item])) |
---|
| | |
---|
| | DebugMsg(SEPARATOR + "\n\n") |
---|
| | |
---|
| | # End of 'DumpRenameObj()' |
---|
| | |
---|
| | |
---|
| | ##### |
---|
| | # Dump The State Of The Program |
---|
| | ##### |
---|
| | |
---|
| | def DumpState(): |
---|
| | |
---|
| | DebugMsg("\n") |
---|
| | DebugMsg(SEPARATOR) |
---|
| | DebugMsg(dCURSTATE) |
---|
| | DebugMsg(SEPARATOR) |
---|
| | |
---|
| | # Names of all the state variables we want dumped |
---|
| |
---|
| | |
---|
| | for k in state: |
---|
| | DebugMsg(ColumnPad([k, eval(k)])) |
---|
| | |
---|
| | DebugMsg(SEPARATOR + "\n") |
---|
| | DebugMsg(SEPARATOR + "\n\n") |
---|
| | |
---|
| | |
---|
| | # End of 'DumpState()' |
---|
| | |
---|
| | |
---|
| |
---|
| | opts, args = getopt.getopt(commandline, '1abbCcdEefghl:qr:tvXx]') |
---|
| | except getopt.GetoptError as e: |
---|
| | ErrorMsg(eBADARG % e.args[0]) |
---|
| | sys.exit(1) |
---|
| | |
---|
| | # Create and populate an object with rename targets. |
---|
| | # We have to do this here so that subsequent |
---|
| | # renaming tokens references can be resolved. |
---|
| | |
---|
| | targs = RenameTargets(args) |
---|
| | |
---|
| | |
---|
| | # Now process the options |
---|
| | |
---|
| | for opt, val in opts: |
---|
| | |
---|
| | if opt == "-1": |
---|
| |
---|
| | if opt == "-x": |
---|
| | REGEX = True |
---|
| | |
---|
| | |
---|
| | # Release the target container |
---|
| | del targs |
---|
| | |
---|
| | |