diff --git a/twander.py b/twander.py index 706f282..7955165 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.80 2002/11/24 22:46:18 tundra Exp $" +RCSID = "$Id: twander.py,v 1.81 2002/11/25 22:35:06 tundra Exp $" VERSION = RCSID.split()[2] @@ -15,6 +15,7 @@ import getopt import os from socket import getfqdn +from stat import * import sys import time @@ -129,12 +130,7 @@ ##### -DETAILVIEW = TRUE # File details on -WARN = TRUE # Warnings on - - - - +WARN = TRUE # Warnings on ##### @@ -147,7 +143,7 @@ MB = KB * KB # 1 MB constant GB = MB * KB # 1 GB constant HOSTNAME = getfqdn() # Full name of this host -REFRESHINT = 5000 # Interval (ms) for automatic refresh +REFRESHINT = 2000 # Interval (ms) for automatic refresh # Stat-related @@ -162,6 +158,19 @@ ST_SPECIALS = {"01":"p", "02":"c", "04":"d", "06":"b", "10":"-", "12":"l", "14":"s"} +# Size of each status display field including trailing space + +ST_SZMODE = 11 +ST_SZNLINK = 5 +ST_SZUNAME = 12 +ST_SZGNAME = 12 +ST_SZLEN = 12 +ST_SZCTIME = 21 + +ST_SZTOTAL = ST_SZMODE + ST_SZNLINK + ST_SZUNAME + ST_SZGNAME + \ + ST_SZLEN + ST_SZCTIME + + # String used to separate symlink entry from its real path SYMPTR = " -> " @@ -497,19 +506,6 @@ ##### - # Support periodic polling to make sure widget stays - # in sync with reality of current directory. - ##### - - def poll(self): - - RefreshDirList() - self.DirList.after(REFRESHINT, self.poll) - - # End of method 'twanderUI.poll()' - - - ##### # Return tuple of all selected items ##### @@ -539,6 +535,47 @@ ##### + # Support periodic polling to make sure widget stays + # in sync with reality of current directory. + ##### + + def poll(self): + + RefreshDirList() + self.DirList.after(REFRESHINT, self.poll) + + # End of method 'twanderUI.poll()' + + + ##### + # Set Detailed View -> FALSE == No Details, TRUE == Details + ##### + + def SetDetailedView(self, details): + + self.DetailsOn = details + + # Tell system where actual file name begins + # For both choices below, we have to set the UI.NameFirst + # value. This tells other handlers where in a given + # selection the actual name of the file can be found. + # This is necessary because we may be selecting a from + # a detailed view and need to know where in that view + # the file name lives. It is not good enough to just + # split() the selected string and use the [-1] entry because + # we may be dealing with a file which has spaces in its + # name. + + + if details: + self.NameFirst = ST_SZTOTAL + else: + self.NameFirst = 0 + + # End of method 'twanderUI.SetDetailedView()' + + + ##### # Update title bar with most current information ##### @@ -611,9 +648,8 @@ ##### def KeyToggleDetail(event): - global DETAILVIEW - - DETAILVIEW = not DETAILVIEW + + UI.SetDetailedView(not UI.DetailsOn) RefreshDirList(event) # End of 'KeyToggleDetail()' @@ -895,7 +931,11 @@ else: fList.append(file) + # Put each in sorted order + dList.sort() + fList.sort() + # Entry to move up one directory is always first, # no matter what the sort. This is necessary because @@ -904,22 +944,8 @@ dList.insert(0, ".." + PSEP) - fList.sort() - - # For both choices below, we have to set the UI.NameFirst - # value. This tells other handlers where in a given - # selection the actual name of the file can be found. - # This is necessary because we may be selecting a from - # a detailed view and need to know where in that view - # the file name lives. It is not good enoch to just - # split() the string and use the [-1] entry because - # we may be dealing with a file which has spaces in its - # name. - - # If user has not requested detailed display, we're done - if not DETAILVIEW: - UI.NameFirst = 0 + if not UI.DetailsOn: return dList + fList # Detailed display requested, do the work @@ -937,7 +963,7 @@ # Mode - 1st get into octal string - mode = stinfo[0] + mode = stinfo[ST_MODE] modestr = str("%06o" % mode) # Set the permission bits @@ -978,15 +1004,16 @@ # Pickup the special file types mode = ST_SPECIALS.get(modestr[0:2], "?") + mode - detlist[index] += str(mode) + (11 - len(str(mode))) * " " + detlist[index] += mode + (ST_SZMODE - len(mode)) * " " # Number of links to entry - detlist[index] += str(stinfo[3]) + ( 5 - len(str(stinfo[3]))) * " " + detlist[index] += str(stinfo[ST_NLINK]) + \ + ( ST_SZNLINK - len(str(stinfo[ST_NLINK]))) * " " - # Get up to 11 characters of owner and group names on unix + # Get first ST_SZxNAME chars of owner and group names on unix if OSNAME == 'posix': - owner = pwd.getpwuid(stinfo[4])[0][:11] - group = grp.getgrgid(stinfo[5])[0][:11] + owner = pwd.getpwuid(stinfo[ST_UID])[0][:ST_SZUNAME-1] + group = grp.getgrgid(stinfo[ST_GID])[0][:ST_SZGNAME-1] # Default names for all other OSs else: @@ -995,24 +1022,20 @@ # Add them to the detail - detlist[index] += owner + (12 - len(owner)) * " " - detlist[index] += group + (12 - len(group)) * " " + detlist[index] += owner + (ST_SZUNAME - len(owner)) * " " + detlist[index] += group + (ST_SZUNAME - len(group)) * " " # Length - flen = FileLength(stinfo[6]) - UI.TotalSize += stinfo[6] - detlist[index] += flen + (11 - len(flen)) * " " + flen = FileLength(stinfo[ST_SIZE]) + UI.TotalSize += stinfo[ST_SIZE] + detlist[index] += flen + (ST_SZLEN - len(flen)) * " " # Ctime - ftime = " ".join(time.ctime(stinfo[9]).split()[1:]) - detlist[index] += ftime + (21 - len(ftime)) * " " - - # Set the index into beginning of file name - UI.NameFirst = len(detlist[index]) + ftime = " ".join(time.ctime(stinfo[ST_CTIME]).split()[1:]) + detlist[index] += ftime + (ST_SZCTIME - len(ftime)) * " " # File name - detlist[index] += all[index] # Include symlink details as necessary @@ -1202,6 +1225,9 @@ # And the flag indicating new directory selected UI.NewDirEntered = FALSE +# Start in detailed mode +UI.SetDetailedView(TRUE) + # Initialize the UI directory listing LoadDirList(STARTDIR) KeySelTop(None)