diff --git a/twander.py b/twander.py index e948e89..265522a 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 2.71 2003/01/19 04:55:29 tundra Exp $" +RCSID = "$Id: twander.py,v 2.72 2003/01/19 06:12:56 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -47,6 +47,7 @@ # If we're on Win32, try to load win32all stuff if possible +WIN32ALL = FALSE if OSNAME == 'nt': try: from win32api import GetLogicalDriveStrings as GetDrives @@ -56,6 +57,7 @@ except: WIN32ALL = FALSE + # Get unix password and group features if OSNAME == 'posix': @@ -238,7 +240,10 @@ # Get the user name if OSNAME == 'nt': - USERNAME = os.getenv("LOGNAME") + if WIN32ALL: + USERNAME = GetUserName() + else: + USERNAME = os.getenv("LOGNAME") elif OSNAME == 'posix': @@ -287,6 +292,20 @@ # Stat-Related Constants +if WIN32ALL: + + # Used with win32all-based permissions logic. + # Format for each entry is: (mask to test, symbol if true). + # Position in tuple determines position in display. + + win32all_mode = ((win32con.FILE_ATTRIBUTE_DIRECTORY, 'd'), + (win32con.FILE_ATTRIBUTE_ARCHIVE, 'A'), + (win32con.FILE_ATTRIBUTE_COMPRESSED, 'C'), + (win32con.FILE_ATTRIBUTE_HIDDEN, 'H'), + (win32con.FILE_ATTRIBUTE_NORMAL, 'N'), + (win32con.FILE_ATTRIBUTE_READONLY, 'R'), + (win32con.FILE_ATTRIBUTE_SYSTEM, 'S')) + # Permissions ST_PERMIT = ["---", "--x", "-w-", "-wx", @@ -299,7 +318,7 @@ # Size of each status display field including trailing space -ST_SZMODE = 11 +ST_SZMODE = 12 # Need more space with win32all (11) than Unix (10) ST_SZNLINK = 5 ST_SZUNAME = 12 ST_SZGNAME = 12 @@ -456,17 +475,17 @@ # Debug Strings -dCMD = "" -dCMDTBL = "" -dDIRSTK = "" -dFUNCKEYS = "" +dCMD = "COMMAND" +dCMDTBL = hCOMMANDS +dDIRSTK = "DIRECTORY STACK" +dFUNCKEYS = hDIRSC dHEADER = "twander Debug Dump Run On: %s\n" -dHIST = "" -dINTVAR = "" -dKEYBINDS = "" +dHIST = "COMMAND HISTORY STACK" +dINTVAR = hINTVBLS +dKEYBINDS = hKEYS dNULL = "None" -dOPTVAR = "" -dSYMTBL = "" +dOPTVAR = hOPTVBLS +dSYMTBL = hUSERVBLS # List of internal program variables to dump during debug sessions @@ -861,7 +880,7 @@ def PrintDebug(title, content): - print title + '\n' + print '<%s>\n' % title.upper() if content: for i in content: print i @@ -1987,6 +2006,8 @@ # haven't screwed up the widget's current # contents or program state. + contents = BuildDirList(newdir) + try: contents = BuildDirList(newdir) except: @@ -2132,11 +2153,14 @@ # Make room for the new detailed entry detlist.append("") + # Condition the name + + fn = os.path.join(currentdir, all[index]) + if fn[-1] == PSEP: + fn =fn[:-1] + # Get file details from OS try: - fn = os.path.join(currentdir, all[index]) - if fn[-1] == PSEP: - fn =fn[:-1] stinfo = os.lstat(fn) # 'lstat' failed - provide entry with some indication of this @@ -2148,48 +2172,75 @@ # Done with this file, but keep going continue - # Mode - 1st get into octal string + # Do Win32-specific mode if win32all is loaded + if WIN32ALL: - mode = stinfo[ST_MODE] - modestr = str("%06o" % mode) + modlen = len(win32all_mode) - # Set the permission bits + try: + win32stat = GetFileAttributes(fn) + mode = "" + except: + mode = "Unavailable" - mode = "" - for x in [-3, -2, -1]: - mode += ST_PERMIT[int(modestr[x])] + if not mode: - # Deal with the special permissions + # Test each attribute and set symbol in respective + # position, if attribute is true. - sp = int(modestr[-4]) + for i in range(modlen): + mask, sym = win32all_mode[i] + if win32stat & mask: + mode += sym + else: + mode += '-' + + # We're either on Unix or Win32 w/o win32all available + else: + # Mode - 1st get into octal string - # Sticky Bit + mode = stinfo[ST_MODE] + modestr = str("%06o" % mode) - if 1 & sp: - if mode[-1] == "x": - mode = mode[:-1] + "t" - else: - mode = mode[:-1] + "T" + # Set the permission bits - # Setgid Bit + mode = "" + for x in [-3, -2, -1]: + mode += ST_PERMIT[int(modestr[x])] - if 2 & sp: - if mode[-4] == "x": - mode = mode[:-4] + "g" + mode[-3:] - else: - mode = mode[:-4] + "G" + mode[-3:] + # Deal with the special permissions - # Setuid Bit + sp = int(modestr[-4]) - if 4 & sp: - if mode[-7] == "x": - mode = mode[:-7] + "g" + mode[-6:] - else: - mode = mode[:-7] + "G" + mode[-6:] + # Sticky Bit - # Pickup the special file types - mode = ST_SPECIALS.get(modestr[0:2], "?") + mode + if 1 & sp: + if mode[-1] == "x": + mode = mode[:-1] + "t" + else: + mode = mode[:-1] + "T" + # Setgid Bit + + if 2 & sp: + if mode[-4] == "x": + mode = mode[:-4] + "g" + mode[-3:] + else: + mode = mode[:-4] + "G" + mode[-3:] + + # Setuid Bit + + if 4 & sp: + if mode[-7] == "x": + mode = mode[:-7] + "g" + mode[-6:] + else: + mode = mode[:-7] + "G" + mode[-6:] + + # Pickup the special file types + mode = ST_SPECIALS.get(modestr[0:2], "?") + mode + + + # Pad the result for column alignment detlist[index] += mode + (ST_SZMODE - len(mode)) * " " # Number of links to entry