diff --git a/tren.py b/tren.py index 1576848..c30a4c1 100755 --- a/tren.py +++ b/tren.py @@ -7,7 +7,7 @@ PROGNAME = "tren.py" PROGENV = PROGNAME.split(".py")[0].upper() -RCSID = "$Id: tren.py,v 1.116 2010/01/28 22:55:52 tundra Exp $" +RCSID = "$Id: tren.py,v 1.117 2010/01/28 23:50:25 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -209,10 +209,8 @@ # Ordered lists used by sequence renaming tokens - self.Ctimes = {} # Keys = ctimes, Values = List of corresponding files - self.Sizes = {} # Keys = sizes, Values = List of corresponding files - self.ByCtime = [] # Sorted list of all file ctimes - self.BySize = [] # Sorted list od all file sizes + ctimes = {} # Keys = ctimes, Values = List of corresponding files + sizes = {} # Keys = sizes, Values = List of corresponding files # Populate the data structures @@ -221,59 +219,59 @@ fullname = os.path.abspath(t) basename = os.path.basename(t) - stat = os.stat(fullname) + stats = os.stat(fullname) - time = stat[ST_CTIME] - if time in self.Ctimes: - self.Ctimes[time].append(fullname) - else: - self.Ctimes[time] = [fullname] + # Incrementally build lists of keys that will later be + # used to create sequence renaming tokens + + for statval, vals in ((stats[ST_CTIME], ctimes), (stats[ST_SIZE], sizes)): + + if statval in vals: + vals[statval].append(fullname) + else: + vals[statval] = [fullname] - size = stat[ST_SIZE] - if size in self.Sizes: - self.Sizes[size].append(fullname) - else: - self.Sizes[size] = [fullname] - - self.RenNames[fullname] = [basename, stat, cmdorder] + self.RenNames[fullname] = [basename, stats, cmdorder] cmdorder += 1 - # Sort the relevant sequence renaming token lists + # Create the various sorted views we may need for sequence tokens + + for view, debugmsg in ((ctimes, dSEQCTIME), (sizes, dSEQSIZE)): - self.ByCtime = self.Ctimes.keys() - self.ByCtime.sort() - self.BySize = self.Sizes.keys() - self.BySize.sort() + vieworder = view.keys() + vieworder.sort() - - # Sort alphabetically when multiple targets map to the same key - - for s in (self.Ctimes, self.Sizes): - - for i in s: - s[i].sort() - - # Now store order, ascending- and descending in master dictionary - - for order, table in ((self.ByCtime, self.Ctimes), (self.BySize, self.Sizes)): + # Sort alphabetically when multiple filenames + # map to the same key, creating overall + # ordering as we go. t = [] - for i in order: - for j in table[i]: + for i in vieworder: + view[i].sort() + for j in view[i]: t.append(j) + # Now store the ascending- and descending order it + # the master dictionary + tblz = len(t) + for name in t: self.RenNames[name].append(t.index(name)) # Ascending index self.RenNames[name].append(tblz - t.index(name) - 1) # Descending Index + + if DEBUG: + + DebugMsg(debugmsg) + for item in vieworder: + itemarrow = ColumnPad([item, ARROW], padwidth=SEQPAD) + DebugMsg(ColumnPad([" ", " %s %s" % (itemarrow, view[item])])) + if DEBUG: DumpRenameObj(self) - # Now get rid of temporary working data structures - del self.Ctimes, self.ByCtime, self.Sizes, self.BySize - # End of class 'RenameTargets' @@ -353,20 +351,6 @@ for item in obj.RenNames[name]: DebugMsg(ColumnPad([" ", item])) - # Dump creation date sequence - - DebugMsg(dSEQCTIME) - for item in obj.ByCtime: - itemarrow = ColumnPad([item, ARROW], padwidth=SEQPAD) - DebugMsg(ColumnPad([" ", " %s %s" % (itemarrow, obj.Ctimes[item])])) - - # Dump size sequence - - DebugMsg(dSEQSIZE) - for item in obj.BySize: - itemarrow = ColumnPad([item, ARROW], padwidth=SEQPAD) - DebugMsg(ColumnPad([" ", " %s %s" % (itemarrow, obj.Sizes[item])])) - DebugMsg(SEPARATOR + "\n\n") # End of 'DumpRenameObj()'