diff --git a/twander.py b/twander.py index 7955165..7a8ff95 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.81 2002/11/25 22:35:06 tundra Exp $" +RCSID = "$Id: twander.py,v 1.82 2002/11/25 23:06:48 tundra Exp $" VERSION = RCSID.split()[2] @@ -216,18 +216,22 @@ eOPEN = "Cannot Open File: %s" eTOOMANY = "You Can Only Specify One Starting Directory." +# Information + +iNOSTAT = "Details Unavailable For This File ->" + # Prompts -pCHPATH = "Change Path" -pENPATH = "Enter New Path Desired:" +pCHPATH = "Change Path" +pENPATH = "Enter New Path Desired:" # Warnings -wCMDKEY = "Configuration File Entry For: \'%s\' Has No Command Key Defined." -wCONFOPEN = "Cannot Open Configuration File:\n%s\n\n%s" -wNOCMDS = "Running With No Commands Defined!" -wSYMBACK = " Symbolic Link %s Points Back To Own Directory" -wWARN = "WARNING" +wCMDKEY = "Configuration File Entry For: \'%s\' Has No Command Key Defined." +wCONFOPEN = "Cannot Open Configuration File:\n%s\n\n%s" +wNOCMDS = "Running With No Commands Defined!" +wSYMBACK = " Symbolic Link %s Points Back To Own Directory" +wWARN = "WARNING" ##### @@ -954,107 +958,117 @@ detlist = [] UI.TotalSize = 0 for index in range(len(all)): + + # Make room for the new detailed entry + detlist.append("") + + # Get file details from OS try: fn = os.path.join(currentdir, all[index]) if fn[-1] == PSEP: fn =fn[:-1] stinfo = os.lstat(fn) - detlist.append("") - # Mode - 1st get into octal string - - mode = stinfo[ST_MODE] - modestr = str("%06o" % mode) - - # Set the permission bits - - mode = "" - for x in [-3, -2, -1]: - mode += ST_PERMIT[int(modestr[x])] - - # Deal with the special permissions - - sp = int(modestr[-4]) - - # Sticky Bit - - 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 - - detlist[index] += mode + (ST_SZMODE - len(mode)) * " " - - # Number of links to entry - detlist[index] += str(stinfo[ST_NLINK]) + \ - ( ST_SZNLINK - len(str(stinfo[ST_NLINK]))) * " " - - # Get first ST_SZxNAME chars of owner and group names on unix - if OSNAME == 'posix': - 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: - owner = OSNAME + 'user' - group = OSNAME + 'group' - - # Add them to the detail - - detlist[index] += owner + (ST_SZUNAME - len(owner)) * " " - detlist[index] += group + (ST_SZUNAME - len(group)) * " " - - # Length - - flen = FileLength(stinfo[ST_SIZE]) - UI.TotalSize += stinfo[ST_SIZE] - detlist[index] += flen + (ST_SZLEN - len(flen)) * " " - - # Ctime - 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 - if detlist[index][0] == 'l': - - # If the symlink points to a file - # in the same directory, just show - # the filename and not the whole path - - f = os.path.realpath(currentdir + all[index]) - r = os.path.split(f) - if r[0] == currentdir[:-1]: - f = r[1] - - detlist[index] += SYMPTR + f + # 'lstat' failed - provide entry with some indication of this except: - detlist[index] = all[index] - + pad = (UI.NameFirst - len(iNOSTAT) - 1) * " " + detlist[index] = pad + iNOSTAT + " " + all[index] + + # Done with this file, but keep going + continue + + # Mode - 1st get into octal string + + mode = stinfo[ST_MODE] + modestr = str("%06o" % mode) + + # Set the permission bits + + mode = "" + for x in [-3, -2, -1]: + mode += ST_PERMIT[int(modestr[x])] + + # Deal with the special permissions + + sp = int(modestr[-4]) + + # Sticky Bit + + 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 + + detlist[index] += mode + (ST_SZMODE - len(mode)) * " " + + # Number of links to entry + detlist[index] += str(stinfo[ST_NLINK]) + \ + ( ST_SZNLINK - len(str(stinfo[ST_NLINK]))) * " " + + # Get first ST_SZxNAME chars of owner and group names on unix + + if OSNAME == 'posix': + 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: + owner = OSNAME + 'user' + group = OSNAME + 'group' + + # Add them to the detail + + detlist[index] += owner + (ST_SZUNAME - len(owner)) * " " + detlist[index] += group + (ST_SZUNAME - len(group)) * " " + + # Length + + flen = FileLength(stinfo[ST_SIZE]) + UI.TotalSize += stinfo[ST_SIZE] + detlist[index] += flen + (ST_SZLEN - len(flen)) * " " + + # Ctime + 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 + if detlist[index][0] == 'l': + + # If the symlink points to a file + # in the same directory, just show + # the filename and not the whole path + + f = os.path.realpath(currentdir + all[index]) + r = os.path.split(f) + if r[0] == currentdir[:-1]: + f = r[1] + + detlist[index] += SYMPTR + f + return detlist # End of 'BuildDirList()'