diff --git a/twander.py b/twander.py index 49c48d3..2cd2150 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.217 2007/01/09 23:27:51 tundra Exp $" +RCSID = "$Id: twander.py,v 3.218 2007/01/10 09:16:31 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -96,8 +96,9 @@ TOGAUTO = '' # Toggle autorefreshing TOGDETAIL = '' # Toggle detail view TOGLENGTH = '' # Toggle length display between actual and normalized -TOGSYMEXPAND = '' # Toggle symbolic link expansion -TOGSYMRESOLV = '' # Toggle absolute symbolic link resolution +TOGSYMDIR = '' # Toggle sorting of symbolic links pointing to directories +TOGSYMEXPAND = '' # Toggle symbolic link expansion +TOGSYMRESOLV = '' # Toggle absolute symbolic link resolution TOGWIN32ALL = '' # Toggle win32all features, if available # Directory Navigation @@ -711,6 +712,7 @@ TTLSORTFLD = "Sort:" TTLSORTREV = "Rev:" TTLSORTSEP = "Sep:" +TTLSYMLINKS = "Symlinks:" # Convert Logical Values Into Yes/No String @@ -1100,10 +1102,20 @@ def FilterMatching(matchthis): - # Check to see if dotfiles should be hidden + # Check to see if dotfiles should be hidden. - if HIDEDOTFILES and matchthis.split()[-1].startswith(DOTFILE): - return False + if HIDEDOTFILES: + + # For symlinks we want the link name not the target name + if matchthis.count(SYMPTR): + fname = matchthis.split(SYMPTR)[-2].split()[-1] + + # Otherwise just use the filename + else: + fname = matchthis.split()[-1] + + if fname.startswith(DOTFILE): + return False # Accomodate case-insensitive matching # But strict matching overrides this @@ -1220,6 +1232,7 @@ "TOGAUTO":TOGAUTO, "TOGDETAIL":TOGDETAIL, "TOGLENGTH":TOGLENGTH, + "TOGSYMDIR":TOGSYMDIR, "TOGSYMEXPAND":TOGSYMEXPAND, "TOGSYMRESOLV":TOGSYMRESOLV, "TOGWIN32ALL":TOGWIN32ALL, @@ -2257,6 +2270,9 @@ # Bind handler for "Toggle Length Display" self.DirList.bind(self.KeyBindings["TOGLENGTH"],lambda event : KeyToggle(event, "ACTUALLENGTH")) + # Bind handler for "Toggle Sorting Of Symlinks Pointing To Directories" + self.DirList.bind(self.KeyBindings["TOGSYMDIR"],lambda event : KeyToggle(event, "SYMDIR")) + # Bind handler for "Toggle Expand Symlinks" self.DirList.bind(self.KeyBindings["TOGSYMEXPAND"],lambda event : KeyToggle(event, "SYMEXPAND")) @@ -2619,9 +2635,22 @@ filter = "%s %s" % (TTLFILTER, filterwc) hidedotfile = "%s %s" % (TTLHIDEDOT, YesOrNo[HIDEDOTFILES]) - - mainwin.title("%s %s %s: %s %s %s %s %s %s %s %s%s %s %s" % - (PROGNAME, VERSION, FULLNAME, CurrentDir, filter, hidedotfile, TTLFILES, + + # Show state of symlink handling + + symlinks = "D" + if not SYMDIR: + symlinks = "F" + + if SYMEXPAND: + symlinks += "E" + if SYMRESOLV: + symlinks += "R" + + symlinks = "%s %s" % (TTLSYMLINKS, symlinks) + + mainwin.title("%s %s %s: %s %s %s %s %s %s %s %s %s%s %s %s" % + (PROGNAME, VERSION, FULLNAME, CurrentDir, symlinks, filter, hidedotfile, TTLFILES, ttlfiles, TTLSIZE, FileLength(self.TotalSize), sortedby, sepsort, TTLAUTO, autostate)) # Make sure the titlebar gets updated @@ -4157,7 +4186,7 @@ # Add trailing path separator to directory entries # Pay attention to pickup symlinks pointing to directories - if detail[0] == ST_SPECIALS["04"] or (SYMDIR and os.path.isdir(detail.split(SYMPTR)[-1].strip())): + if detail[0] == ST_SPECIALS["04"] or os.path.isdir(detail.split(SYMPTR)[-1].strip()): file += PSEP detail += PSEP @@ -4197,9 +4226,11 @@ if OSPLATFORM == 'win32' 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 + # Keep track of the file name and its details, + # separating directories from files Treat symlinks + # pointing to directories as directories for this + # purpose (if that's what the user wants). + # Build corresponding key list for sorting. fileinfo.append((file, detail)) currentpos = len(fileinfo)-1 @@ -4271,15 +4302,25 @@ dotdot = [".." + PSEP,] - # If the user doesn't want symbolic link expansion, get - # rid of it. + # If the user doesn't want symbolic link expansion, get rid of it. if not SYMEXPAND: - for list, tail in ((fList, ""), (dList, PSEP)): + for list in (fList, dList): + for i in range(len(list)): - list[i] = list[i].split(SYMPTR)[0] - if tail and list[i][-1] != tail: - list[i] += tail + + # Only necessary for symlinks + if list[i].count(SYMPTR): + + # Preserve possible indication this is a directory + tail = list[i][-1] + + # Remove target portion of any symlinks + list[i] = list[i].split(SYMPTR)[0] + + # If not already noted, indicate symlinks pointing to directories + if tail == PSEP and not list[i].endswith(PSEP): + list[i] += tail # Return the results # Entry to move up one directory is always first,