diff --git a/twander.py b/twander.py index dca78b7..1732d58 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ # For Updates See: http://www.tundraware.com/Software/twander PROGNAME = "twander" -RCSID = "$Id: twander.py,v 2.41 2003/01/02 22:58:36 tundra Exp $" +RCSID = "$Id: twander.py,v 2.42 2003/01/03 20:45:53 tundra Exp $" VERSION = RCSID.split()[2] @@ -26,18 +26,27 @@ from tkMessageBox import showerror, showwarning from tkSimpleDialog import askstring +##### # Imports conditional on OS +##### # Set OS type - this allows us to trigger OS-specific code # where needed. OSNAME = os.name +DriveList = [] +if OSNAME == 'nt': + try: + from win32api import GetLogicalDriveStrings as GetDrives + except: + def GetDrives(): + return [] + if OSNAME == 'posix': import grp import pwd - #----------------------------------------------------------# @@ -188,16 +197,6 @@ Button4Mask = (1<<11) Button5Mask = (1<<12) -# Debug Levels - -DEBUGQUIT = (1<<0) # Dump debug info and quit program -DEBUGVARS = (1<<1) # Dump internal variables -DEBUGSYMS = (1<<2) # Dump symbol table -DEBUGCTBL = (1<<3) # Dump command table -DEBUGCMDS = (1<<4) # Dump command execution string -DEBUGKEYS = (1<<5) # Dump key bindings -DEBUGDIRS = (1<<6) # Dump directory stack contents as it changes - # Stat-Related Constants @@ -269,20 +268,9 @@ ##### -# Debug, Error, Information, & Warning Messages +# Error, Information, & Warning Messages ##### -# Debug Strings - -dCMD = "" -dCMDTBL = "" -dDIRSTK = "" -dHEADER = "twander Debug Dump Run On: %s\n" -dINTVAR = "" -dKEYBINDS = "" -dNULL = "None" -dSYMTBL = "" - # Errors eBADCFGLINE = "Bogus Configuration Entry In Line %s:\n\n%s" @@ -321,6 +309,39 @@ ##### +# Debug-Related Stuff +##### + +# Debug Levels + +DEBUGQUIT = (1<<0) # Dump debug info and quit program +DEBUGVARS = (1<<1) # Dump internal variables +DEBUGSYMS = (1<<2) # Dump symbol table +DEBUGCTBL = (1<<3) # Dump command table +DEBUGCMDS = (1<<4) # Dump command execution string +DEBUGKEYS = (1<<5) # Dump key bindings +DEBUGDIRS = (1<<6) # Dump directory stack contents as it changes + +# Debug Strings + +dCMD = "" +dCMDTBL = "" +dDIRSTK = "" +dHEADER = "twander Debug Dump Run On: %s\n" +dINTVAR = "" +dKEYBINDS = "" +dNULL = "None" +dSYMTBL = "" + +# List of internal program variables to dump during debug sessions + +DebugVars = ["RCSID","OSNAME", "STARTDIR", "HOME", "CONF", "HEIGHT", "WIDTH", + "BCOLOR", "FCOLOR", "FNAME", "FSZ", "FWT", "AUTOREFRESH", + "DEBUGLEVEL", "WARN", "PSEP", "QUOTECHAR", "POLLINT", + "REFRESHINT", "DriveList"] + + +##### # Usage Information ##### @@ -330,7 +351,7 @@ " -b color background color (default: black)", " -c file name of configuration file (default: $HOME/." + PROGNAME + " or PROGDIR/." + PROGNAME + ")", - " -d turn on debugging (default: debugging off)", + " -d level set debugging level (default: 0, debugging off)", " -f color foreground color (default: green)", " -h print this help information", " -n name name of font to use (default: courier)", @@ -365,6 +386,20 @@ ##### +# Build List Of Win32 Drives +##### + +def GetWin32Drives(): + + # Get Win32 drive string, split on nulls, and get + # rid of any resulting null entries. + + return filter(lambda x : x, GetDrives().split('\x00')) + +# End of 'GetWin32Drives()' + + +##### # Convert A File Size Into Equivalent String With Scaling # Files under 1 MB show actual length # Files < 1 MB < 1 GB shown in KB @@ -1908,23 +1943,6 @@ if opt == "-y": HEIGHT = val - -# List of internal program variables to dump during debug sessions - -DebugVars = ["RCSID","OSNAME", "STARTDIR", "HOME", "CONF", "HEIGHT", "WIDTH", - "BCOLOR", "FCOLOR", "FNAME", "FSZ", "FWT", - "AUTOREFRESH", "DEBUGLEVEL", "WARN", "PSEP", "QUOTECHAR", "POLLINT", "REFRESHINT"] - -# Dump program variable during debug sessions -if int(DEBUGLEVEL) & DEBUGVARS: - - debuginfo = [] - for v in DebugVars: - debuginfo.append(v + " " * (12-len(v)) + (str(eval(v)) or dNULL)) - - PrintDebug(dINTVAR, debuginfo) - - # Create an instance of the UI UIroot = Tk() UI = twanderUI(UIroot) @@ -1954,6 +1972,10 @@ ErrMsg(eBADROOT % STARTDIR) sys.exit(1) +# Initialize The Drive List On Win32 +if OSNAME == 'nt': + DriveList = GetWin32Drives() + # Get starting directory into canonical form STARTDIR = os.path.abspath(STARTDIR) @@ -1995,13 +2017,23 @@ LoadDirList(STARTDIR) KeySelTop(None) -# And start the periodic polling of the widget -UI.poll() +# Dump program variable during debug sessions +if int(DEBUGLEVEL) & DEBUGVARS: + + debuginfo = [] + for v in DebugVars: + debuginfo.append(v + " " * (12-len(v)) + (str(eval(v)) or dNULL)) + + PrintDebug(dINTVAR, debuginfo) + # If we just wanted debug output, quit now if int(DEBUGLEVEL) & DEBUGQUIT: sys.exit() +# And start the periodic polling of the widget +UI.poll() + # Run the program interface UIroot.mainloop()