Added remainder of os.stat() info to RenameTargets for potential sequence renaming token use.
Added alpha-order of command line rename targets for potential sequence renaming token use.
1 parent fefda77 commit 098459a30cf19303c028ef3a6b0fb90c3b69ecd5
@tundra tundra authored on 29 Jan 2010
Showing 1 changed file
View
120
tren.py
# Program Information
 
PROGNAME = "tren.py"
PROGENV = PROGNAME.split(".py")[0].upper()
RCSID = "$Id: tren.py,v 1.118 2010/01/29 00:17:13 tundra Exp $"
RCSID = "$Id: tren.py,v 1.119 2010/01/29 18:32:04 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
# General Program Constants
#####
 
MAXINCLUDES = 50 # Maximum number of includes allowed
 
TGTSEQFLG = 9999 # Indicates non-stat() in SeqTypes table
 
#####
# Message Formatting Constants
#####
dINCLUDING = "Including file '%s'"
dPAIR = "Option/Target Pair"
dPROGENV = "$" + PROGENV
dRESOLVEDOPTS = "Resolved Command Line"
dSEQATIME = "Access Time Sequence:"
dSEQCMD = "Command Line Sequence:"
dSEQCTIME = "Creation Time Sequence:"
dSEQDEV = "Device Sequence:"
dSEQGID = "GID Sequence"
dSEQINO = "Inode Sequence:"
dSEQMODE = "Mode Sequence:"
dSEQMTIME = "Modification Time Sequence:"
dSEQNLINK = "Nlinks Sequence"
dSEQSIZE = "Size Sequence:"
dSEQATIME = "Access Time Sequence:"
dSEQCTIME = "Creation Time Sequence:"
dSEQMTIME = "Modification Time Sequence:"
dTARGETS = "Rename Targets: %s"
dSEQTARGS = "Rename Targets:"
dSEQUID = "UID Seqeuence"
 
 
#####
# Error Messages
 
DEBUG = False # Debugging off
CASESENSITIVE = True # Search is case-sensitive
ERRORCONTINUE = False # Do not continue after error
EXTDELIM = EXTDELIM # Extension Delimiter
FORCERENAM = False # Do not rename if target already exists
GLOBAL = False # Only rename first instance of old string
QUIET = False # Display progress
REGEX = False # Do not treat old string as a regex
RenNames dictionary will be populated as follows:
 
fully-qualified name : [ basename,
stat information for the entry,
order of appearance on command line (0-based),
ascending order of appearance by-atime (0-based),
descending order of appearance by-atime (0-based),
ascending order of appearance by-ctime (0-based),
descending order of appearance by-ctime (0-based),
ascending order of appearance by-mtime (0-based),
descending order of appearance by-mtime (0-based),
position in command line args list (0-based)
ascending alpha order of rename targets (O-based)
descending alpha order of rename targets (0-based)
ascending order of appearance by-mode (O-based)
descending order of appearance by-mode (0-based)
ascending order of appearance by-inode (O-based)
descending order of appearance by-inode (0-based)
ascending order of appearance by-devno (O-based)
descending order of appearance by-devno (0-based)
ascending order of appearance by-nlinks (O-based)
descending order of appearance by-nlinks (0-based)
ascending order of appearance by-uid (O-based)
descending order of appearance by-uid (0-based)
ascending order of appearance by-gid (O-based)
descending order of appearance by-gid (0-based)
ascending order of appearance by-atime (0-based)
descending order of appearance by-atime (0-based)
ascending order of appearance by-ctime (0-based)
descending order of appearance by-ctime (0-based)
ascending order of appearance by-mtime (0-based)
descending order of appearance by-mtime (0-based)
ascending order of appearance by-size (0-based)
descending order of appearance by-size (0-based)
]
"""
self.RenNames = {}
 
# Ordered lists used by sequence renaming tokens
 
args = {} # Keys = 0, Values = Rename targets from command line
modes = {} # Keys = modes, Values = List of corresponding files
inodes = {} # Keys = inodes, Values = List of corresponding files
devs = {} # Keys = devs, Values = List of corresponding files
nlinks = {} # Keys = nlinks, Values = List of corresponding files
uids = {} # Keys = uids, Values = List of corresponding files
gids = {} # Keys = gids, Values = List of corresponding files
atimes = {} # Keys = atimes, Values = List of corresponding files
ctimes = {} # Keys = ctimes, Values = List of corresponding files
mtimes = {} # Keys = mtimes, Values = List of corresponding files
sizes = {} # Keys = sizes, Values = List of corresponding files
# This data structure is used to keep track of everything
# we need to build the sequence renaming token support.
# This makes it easy to add more types later on.
 
SeqTypes = [ [ST_ATIME, atimes, dSEQATIME],
[ST_CTIME, ctimes, dSEQCTIME],
[ST_CTIME, mtimes, dSEQMTIME],
[ST_SIZE, sizes, dSEQSIZE],
SeqTypes = [ [TGTSEQFLG, args, dSEQTARGS],
[ST_MODE, modes, dSEQMODE],
[ST_INO, inodes, dSEQINO],
[ST_DEV, devs, dSEQDEV],
[ST_NLINK, nlinks, dSEQNLINK],
[ST_UID, uids, dSEQUID],
[ST_GID, gids, dSEQGID],
[ST_ATIME, atimes, dSEQATIME],
[ST_CTIME, ctimes, dSEQCTIME],
[ST_CTIME, mtimes, dSEQMTIME],
[ST_SIZE, sizes, dSEQSIZE],
]
 
# Incrementally build lists of keys that will later be
# used to create sequence renaming tokens
 
for seqtype in SeqTypes:
 
statval = stats[seqtype[0]]
vals = seqtype[1]
# Handle os.stat() values
 
if seqtype[0] != TGTSEQFLG:
statval = stats[seqtype[0]]
 
# Handle non os.stat() stuff
else:
statval = TGTSEQFLG
 
# Where to put the results
vals = seqtype[1]
 
if statval in vals:
vals[statval].append(fullname)
else:
self.RenNames[fullname] = [basename, stats, cmdorder]
cmdorder += 1
 
 
# Create the various sorted views we may need for sequence tokens
# Create the various sorted views we may need
# for sequence renaming tokens
 
for seqtype in SeqTypes:
 
view = seqtype[1]
debugmsg = seqtype[2]