diff --git a/twander.py b/twander.py index 68cce2a..8c8c18b 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.181 2005/01/28 11:09:27 tundra Exp $" +RCSID = "$Id: twander.py,v 3.182 2005/01/28 22:26:21 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -549,7 +549,7 @@ ST_SZNLINK = 5 ST_SZUNAME = 18 ST_SZGNAME = 18 -ST_SZLEN = 12 +ST_SZLEN = 15 ST_SZMTIME = 18 ST_SZTOTAL = ST_SZMODE + ST_SZNLINK + ST_SZUNAME + ST_SZGNAME + \ @@ -933,17 +933,53 @@ def FileLength(flen): - if ACTUALLENGTH: - return str(flen) + # Return actual length of file - if flen >= GB: - flen = str(flen/GB) + "g" - elif flen >= MB: - flen = str(flen/MB) + "m" - elif flen >= KB: - flen = str(flen/KB) + "k" + if ACTUALLENGTH: + + # Insert commas for readability + + length = str(flen) + index = len(length)-3 + flen = "" + + while index > -3: + if index <= 0: + flen = length[:index+3] + flen + else: + flen = ',' + length[index:index+3] + flen + index -= 3 + + # Return normalized length of file + else: - flen = str(flen) + + # Set the scaling factor and indicator + + if flen >= GB: + norms = (GB, "g") + elif flen >= MB: + norms = (MB, "m") + elif flen >= KB: + norms = (KB, "k") + else: + norms = (1, "") + + # Scale the results + + factor = norms[0] + div, rem = flen/factor, flen%factor + + # If remainder is >= half the scaling factor, bump the count + # up one Do not do this when we want the actual length - + # i.e., When the scaling factor is 1. + + if (factor > 1) and (rem >= factor/2): + div += 1 + + # Make a string to return out of the result + + flen = str(div) + norms[1] return flen @@ -954,11 +990,11 @@ # Pad A String With Trailing Spaces To Specified Width # Return either that padded string or, if the passed # string is too large, truncate it and return a string -# of exactly the specified with whose last character is +# of exactly the specified width whose last character is # a space. ##### -def PadString(string, width, Rjust=False): +def PadString(string, width, Rjust=False, Trailing=0): s = string[:(width-1)] if Rjust: @@ -966,6 +1002,12 @@ else: s = s.ljust(width) + # Rotate 'Trailing' number of spaces from left of string to right + + while (Trailing > 0) and (s[0] == ' ') : + s = s[1:] + ' ' + Trailing -= 1 + return s # End of 'PadString()' @@ -4128,7 +4170,7 @@ rlen = stinfo[ST_SIZE] flen = FileLength(rlen) - details += PadString(flen, ST_SZLEN) + details += PadString(flen, ST_SZLEN, Rjust=True, Trailing=4) fields.append(rlen) # mtime