diff --git a/twander.py b/twander.py index 70ca8d2..fab909d 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.179 2005/01/27 11:15:01 tundra Exp $" +RCSID = "$Id: twander.py,v 3.180 2005/01/28 10:19:42 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -357,6 +357,12 @@ # Name Of Sort Option In Normal View, # Name Of Sort Option In Drive List View) # +# When preparing to actually sort, BuildDirList() gets information on +# each file from FileDetails() in the form of a set of fields in a +# list. The field # entered loaded here, tells BuildDirList() just +# *which* of the fields (list position) is relevant to each of the +# sort types. +# # Placing a None value in either of the last two tuple entries causes the # keystroke combination associated with that sort option to be ignored AND # prevents that option from appearing in the Sort Menu. @@ -926,8 +932,10 @@ def FileLength(flen): if flen >= GB: - flen = str(flen/MB) + "m" + flen = str(flen/GB) + "g" elif flen >= MB: + flen = str(flen/MB) + "m" + elif flen >= KB: flen = str(flen/KB) + "k" else: flen = str(flen) @@ -1672,7 +1680,7 @@ if t[idx]: UI.SortBtn.menu.add_command(label=t[idx], command=lambda parm=t[1] : KeySetSortParm(parm)) - # Store the current directory - used in subsequent calls to this funtion to + # Store the current directory - used in subsequent calls to this function to # determine whether or not we're moving between Normal <--> Drive List Views UI.SortBtn.CurrentDir = UI.CurrentDir @@ -3545,7 +3553,7 @@ # Nothing should be pre-selected in the new directory listing KeySelNone(None) - # Update Help Menu to reflect whether we're in Normal or Drive List View + # Update Sort Menu to reflect whether we're in Normal or Drive List View LoadSortMenu() # Update titlebar to reflect any changes @@ -3604,7 +3612,10 @@ # A normal directory read and a Drive List View # under Win32. + ##### # Normal directory reads + ##### + if currentdir != SHOWDRIVES: # Get and sort directory contents @@ -3624,7 +3635,6 @@ detail, fields = FileDetails(file, currentdir) - # Add trailing path separator to directory entries # Pay attention to pickup symlinks pointing to directories @@ -3632,6 +3642,21 @@ file += PSEP detail += PSEP + # If wildcard filtering is in effect, only let files through that match + + if UI.FilterWildcard[1]: + + matchthis = file + if UI.DetailsOn: + matchthis = detail + + if not UI.FilterWildcard[1].match(matchthis): + continue + + # Keep running tally of total files sizes + + UI.TotalSize += fields[Name2Key[fLENGTH.lower()][0]] + # Decide whether we have to sort or not, act accordingly if SORTBYFIELD.lower() == fNONE.lower(): @@ -3647,29 +3672,27 @@ # Yup, we're going to sort later - build index/return data structures else: - - # Get the key by which to sort - we decrement it by one because - # the user expresses it as a 1-relative value. + + # Get the keystring used for the actual sort # Collapse case on Win32 when sorting by name sortkey = fields[keyindex] if OSNAME == 'nt' and (SORTBYFIELD.lower() == fNAME.lower()): sortkey = sortkey.lower() - # Keep track of the file name and its details, separating directories from files # Treat symlinks pointing to directories as directories for this purpose # Build corresponding key list for sorting - + fileinfo.append((file, detail)) - + currentpos = len(fileinfo)-1 + if detail[0] == ST_SPECIALS["04"] or (SYMDIR and os.path.isdir(detail.split(SYMPTR)[-1].strip())): - dKeys.setdefault(sortkey, []).append(x) + dKeys.setdefault(sortkey, []).append(currentpos) else: - fKeys.setdefault(sortkey, []).append(x) - - + fKeys.setdefault(sortkey, []).append(currentpos) + # If sorting has been requested, do so now if SORTBYFIELD.lower() != fNONE.lower(): @@ -3723,27 +3746,6 @@ # Sorting logic ends here - # Filter through any filtering wildcard (if any). - - if UI.FilterWildcard[1]: - for list in dList, fList: - - # Find the entries that don't match the wildcard. - # We have to store the entries we don't want and then - # remove them, because we cannot reliably remove items - # from a list while we are iterating over it. - - remove = [] - for x in list: - if not UI.FilterWildcard[1].match(x): - remove.append(x) - - # And remove those non-matching entries - - for x in remove: - list.remove(x) - - # Now return results in their final form if UI.DetailsOn: @@ -3775,7 +3777,10 @@ else: return dotdot + dList + fList + ##### # The user requested Drive List View. + ##### + else: @@ -3841,7 +3846,9 @@ # Total Space tspace = clustersz * sectorsz * totalclusters + UI.TotalSize += tspace totalspace = FileLength(tspace) + except: fspace, tspace = (0, 0) freespace, totalspace = ('0', '0') @@ -4100,7 +4107,6 @@ flen = FileLength(rlen) details += PadString(flen, ST_SZLEN) fields.append(rlen) - UI.TotalSize += rlen # mtime