diff --git a/twander.py b/twander.py index 11a5086..2d25c7a 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.63 2002/11/19 09:31:43 tundra Exp $" +RCSID = "$Id: twander.py,v 1.64 2002/11/19 10:06:07 tundra Exp $" VERSION = RCSID.split()[2] @@ -159,14 +159,15 @@ # Errors -eBADROOT = " %s Is Not A Directory" -eDIRRD = "Cannot Open Directory : %s --- Check Permissions." -eDUPKEY = "Duplicate Key In Configuration File Found In Entry: \'%s\'" -eERROR = "ERROR" -eNOCONF = "Cannot Find Configuration File: %s" -eNOENV = "Configuration File References Undefined Environment Variable: %s" -eOPEN = "Cannot Open File: %s" -eTOOMANY = "You Can Only Specify One Starting Directory." +eBADROOT = " %s Is Not A Directory" +eDIRRD = "Cannot Open Directory : %s --- Check Permissions." +eDUPKEY = "Duplicate Key In Configuration File Found In Entry: \'%s\'" +eERROR = "ERROR" +eINITDIRBAD = "Cannot Open Starting Directory : %s - Check Permissions - ABORTING!." +eNOCONF = "Cannot Find Configuration File: %s" +eNOENV = "Configuration File References Undefined Environment Variable: %s" +eOPEN = "Cannot Open File: %s" +eTOOMANY = "You Can Only Specify One Starting Directory." # Prompts @@ -717,10 +718,32 @@ ##### def LoadDirList(newdir, save=TRUE): - - # Canonicalize the current directory name + + # Get path into canonical form newdir = os.path.abspath(newdir) + # Make sure newdir properly terminated + if newdir[-1] != PSEP: + newdir += PSEP + + # Check right now to see if we can read + # the directory. If not, at least we + # haven't screwed up the widget's current + # contents or program state. + + try: + contents = BuildDirList(newdir) + except: + # If CurrentDir set, we're still there: error w/ recovery + if UI.CurrentDir: + ErrMsg(eDIRRD % newdir) + return + + # If not, we failed on the initial directory: error & abort + else: + ErrMsg(eINITDIRBAD % newdir) + sys.exit(1) + # Push last directory visited onto the visited stack # Do not do this if we've been told not to OR if @@ -739,15 +762,11 @@ # And select new directory to visit UI.CurrentDir = newdir - # And make sure it ends with a path separator character - if UI.CurrentDir[-1] != PSEP: - UI.CurrentDir = UI.CurrentDir + PSEP - # Clear out the old contents UI.DirList.delete(0,END) # Load new directory contents into UI - for x in BuildDirList(UI.CurrentDir): + for x in contents: UI.DirList.insert(END, x) # And update the title to reflect changes @@ -766,41 +785,12 @@ dList, fList = [], [] # Walk the directory separate subdirs and files - try: - for file in os.listdir(currentdir): - if os.path.isdir(os.path.join(currentdir,file)): - dList.append(DIR_LDELIM + file + DIR_RDELIM) - else: - fList.append(file) - except: - # Can't read selected directory - show error - ErrMsg(eDIRRD % currentdir) - - # By setting this to null, we assure that it never gets pushed - UI.CurrentDir = "" - - # If there was a previous dir, go there - if UI.LastDir: - - # Get the previous directory - curdir = UI.LastDir.pop() - - # Make it look like we are coming from the one before that - if UI.LastDir: - UI.CurrentDir = UI.LastDir.pop() - - # Now go there - LoadDirList(curdir) - - # If no previous directory, we failed on pgm startup - abort + for file in os.listdir(currentdir): + if os.path.isdir(os.path.join(currentdir,file)): + dList.append(DIR_LDELIM + file + DIR_RDELIM) else: - sys.exit(1) - + fList.append(file) - # Satisfy the original call - return [] - - # Directory read was fine dList.sort() # Entry to move up one directory is always first,