diff --git a/twander.py b/twander.py index acacb86..bd3efdc 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.75 2002/11/23 03:51:47 tundra Exp $" +RCSID = "$Id: twander.py,v 1.76 2002/11/23 10:07:27 tundra Exp $" VERSION = RCSID.split()[2] @@ -89,7 +89,7 @@ ##### HEIGHT = 25 -WIDTH = 60 +WIDTH = 90 ##### # Colors @@ -141,10 +141,29 @@ # Constants ##### +# General constants + +KB = 1024 # 1 KB constant +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 +# Stat-related constants (in octal) + +ST_PIPE = 0010000 # FIFO +ST_CHAR = 0020000 # Character Special +ST_DIR = 0040000 # Directory +ST_BLOCK = 0060000 # Block Special +ST_REG = 0100000 # Regular File +ST_SYMLINK = 0120000 # Symbolic Link +ST_SOCKET = 0140000 # Socket + +ST_PERMIT = ["---", "--x", "-w-", "-wx", + "r--", "r-x", "rw-", "rwx"] + + ##### # General Literals ##### @@ -898,8 +917,17 @@ stinfo = os.stat(os.path.join(currentdir, all[index])) detlist.append("") - # Mode - detlist[index] += str(stinfo[0]) + (11 - len(str(stinfo[0]))) * " " + # Mode - 1st get into octal string + mode = stinfo[0] + modestr = str("%o" % mode) + + # Set the permission bits + + mode = "" + for x in [-3, -2, -1]: + mode += ST_PERMIT[int(modestr[x])] + + detlist[index] += str(mode) + (11 - len(str(mode))) * " " # Number of links to entry detlist[index] += str(stinfo[3]) + ( 5 - len(str(stinfo[3]))) * " " @@ -920,7 +948,19 @@ detlist[index] += group + (12 - len(group)) * " " # Length - detlist[index] += str(stinfo[6]) + (11 - len(str(stinfo[6]))) * " " + # Files under 1 MB show actual length + # Files < 1 MB < 1 GB shown in KB + # Files 1 GB or greater, shown in MB + + flen = stinfo[6] + if flen >= GB: + flen = str(flen/MB) + "m" + elif flen >= MB: + flen = str(flen/KB) + "k" + else: + flen = str(flen) + + detlist[index] += flen + (11 - len(flen)) * " " # Ctime ftime = " ".join(time.ctime(stinfo[9]).split()[1:])