diff --git a/twander.py b/twander.py index 1116e54..7fc3810 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 2.86 2003/01/30 23:02:58 tundra Exp $" +RCSID = "$Id: twander.py,v 2.87 2003/01/31 00:50:13 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -28,6 +28,7 @@ import re from socket import getfqdn from stat import * +from string import atoi import sys import thread import time @@ -495,6 +496,7 @@ # Warnings wBADCFGLINE = "Ignoring Line %s.\nBogus Configuration Entry:\n\n%s" +wBADDEBUG = "Ignoring Bogus Debug Level! - %s Is Not In Integer Or Hex Format." wBADENVVBL = "Ignoring Line %s.\nEnvironment Variable %s Not Set:\n\n%s" wBADEXE = "Could Not Execute Command:\n\n%s" wBADRHS = "Ignoring Line %s.\nOption Assignment Has Bad Righthand Side:\n\n%s" @@ -895,7 +897,7 @@ elif name in UI.OptionsNumeric.keys(): try: - globals()[name] = int(val) + globals()[name] = StringToNum(val) except: WrnMsg(wBADRHS % (num, line)) return @@ -1069,6 +1071,24 @@ ##### +# Convert A String In Integer Or Hex Format To An Equivalent Numeric +# We assume that the string is either in correct format or that +# the calling routine will catch any error. +##### + +def StringToNum(string): + + if string.lower().startswith('0x'): + value = atoi(string, 16) + else: + value = atoi(string) + + return value + +# End of 'StringToNum() + + +##### # Strip Trailing Path Separator ##### @@ -1095,6 +1115,24 @@ ##### +# Check Debug Level To See If It Is A Properly Formed Integer Or Hex Value +# If So, Convert To Numeric, If Not, Warn User, And Set To 0 +##### + +def ValidateDebugLevel(): + global DEBUGLEVEL + + d = DEBUGLEVEL # Save, in case of error + try: + DEBUGLEVEL = StringToNum(DEBUGLEVEL) + except: + DEBUGLEVEL = 0 + WrnMsg(wBADDEBUG % d) + +# End of 'ValidateDebugLevel()' + + +##### # Print A Warning Message ##### @@ -2127,7 +2165,7 @@ # Just dump command if we're debugging - if int(DEBUGLEVEL) & DEBUGCMDS: + if DEBUGLEVEL & DEBUGCMDS: PrintDebug(dCMD, [newcmd,]) # Otherwise,actually execute the command. @@ -2166,7 +2204,7 @@ # Dump Command History stack if requested - if int(DEBUGLEVEL) & DEBUGHIST: + if DEBUGLEVEL & DEBUGHIST: PrintDebug(dHIST, UI.CmdHist) # End of 'ExecuteCommand() @@ -2250,7 +2288,7 @@ UI.LastDir.append(UI.CurrentDir) # Dump directory stack if debug requested it - if int(DEBUGLEVEL) & DEBUGDIRS: + if DEBUGLEVEL & DEBUGDIRS: PrintDebug(dDIRSTK, UI.LastDir) # And select new directory to visit @@ -2305,6 +2343,21 @@ dList, fList = [], [] + # Indicate where in each display string the actual file name + # can be found. This is used both in the code in this routine + # and other places in the program where just the file name is + # needed - for example, when we want to execute it or replace it + # in one of the built-ins. This value depends on whether or + # not we are viewing details or not. + + if UI.DetailsOn: + if currentdir == SHOWDRIVES: + UI.NameFirst = SZ_DRIVE_TOTAL + else: + UI.NameFirst = ST_SZTOTAL + else: + UI.NameFirst = 0 + # Two possible cases have to be handled: # A normal directory read and a Drive List View # under Win32. @@ -2361,7 +2414,6 @@ # If details are off, just return the list of drives if not UI.DetailsOn: - UI.NameFirst = 0 # Note where name actually begins return drivelist # We're returning detailed information about each drive @@ -2424,7 +2476,6 @@ # Save final result in detailed list details.append(entry) - UI.NameFirst = SZ_DRIVE_TOTAL # Note where entry name actually begins return details # Get details on directory contents @@ -2634,10 +2685,8 @@ detlist[index] += SYMPTR + f if UI.DetailsOn: - UI.NameFirst = ST_SZTOTAL # Note where name actually begins return detlist else: - UI.NameFirst = 0 # Note where name actually begins return dList + fList # End of 'BuildDirList()' @@ -2875,7 +2924,7 @@ ##### # Keyboard Assignments - if int(DEBUGLEVEL) & DEBUGKEYS: + if DEBUGLEVEL & DEBUGKEYS: # Keyboard Bindings PrintDebug(dKEYBINDS, GetKeyBindings()) @@ -2884,15 +2933,15 @@ PrintDebug(dFUNCKEYS, GetDirShortcuts()) # User-Defined Variables - if int(DEBUGLEVEL) & DEBUGSYMS: + if DEBUGLEVEL & DEBUGSYMS: PrintDebug(dSYMTBL, GetUserVbls()) # Command Definitions - if int(DEBUGLEVEL) & DEBUGCTBL: + if DEBUGLEVEL & DEBUGCTBL: PrintDebug(dCMDTBL, GetCommandTable()) # Internal Program Variables AndOptions - if int(DEBUGLEVEL) & DEBUGVARS: + if DEBUGLEVEL & DEBUGVARS: # Internal variabled PrintDebug(dINTVAR, GetIntVars()) @@ -2901,7 +2950,7 @@ PrintDebug(dOPTVAR, GetOptions()) # If we just wanted debug output, quit now - if int(DEBUGLEVEL) & DEBUGQUIT: + if DEBUGLEVEL & DEBUGQUIT: sys.exit() # End of 'ProcessOptions()' @@ -3231,8 +3280,12 @@ for opt, val in opts: if opt == "-d": DEBUGLEVEL = val - if int(DEBUGLEVEL): + ValidateDebugLevel() + + # If we're going to be dumping debug info, print header + if DEBUGLEVEL: print dHEADER % time.asctime() + if opt == "-q": WARN = FALSE if opt == "-r":