diff --git a/twander.py b/twander.py index f14f844..387898e 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.72 2002/11/22 20:53:40 tundra Exp $" +RCSID = "$Id: twander.py,v 1.73 2002/11/22 22:29:00 tundra Exp $" VERSION = RCSID.split()[2] @@ -59,20 +59,14 @@ ##### -# Default Directories +# Default Directories & Files ##### # Default startup directory STARTDIR = "." + os.sep -# Default directory for config file -# Use $HOME if available, otherwise use starting directory - HOME = os.getenv("HOME") or STARTDIR -# Configuration file -CONF = os.path.join(HOME, "." + PROGNAME) - ##### # Program Constants @@ -144,6 +138,7 @@ # Configuration File Related Literals ##### +CONF = "" # Config file user selected with -c option CMDKEY = r'&' # Command key delimiter COMMENT = r"#" # Comment character DIRNAME = r'[DIRECTORY]' # Substitution field in config files @@ -179,10 +174,11 @@ # Warnings -wCMDKEY = "Configuration File Entry For: \'%s\' Has No Command Key Defined." -wNOCONF = "Cannot Find Configuration File: %s\n\nRunning With No Commands Defined!" -wSYMBACK = " Symbolic Link %s Points Back To Own Directory" -wWARN = "WARNING" +wCMDKEY = "Configuration File Entry For: \'%s\' Has No Command Key Defined." +wCONFOPEN = "Cannot Open Configuration File:\n%s\n\n%s" +wNOCMDS = "Running With No Commands Defined!" +wSYMBACK = " Symbolic Link %s Points Back To Own Directory" +wWARN = "WARNING" ##### @@ -193,7 +189,8 @@ "usage: " + PROGNAME + " [-bcfhnsvwxy] [startdir] where,\n", " startdir name of directory in which to begin (default: current dir)", " -b color background color (default: black)", - " -c file name of configuration file (default: " + CONF + ")", + " -c file name of configuration file (default: $HOME/." + PROGNAME + + " or PROGDIR/." + PROGNAME + ")", " -f color foreground color (default: green)", " -h print this help information", " -n name name of font to use (default: courier)", @@ -254,16 +251,23 @@ # while the program is running. ##### -def ParseConfFile(*args): - global UI - +def ParseConfFile(event): + global CONF, UI + + # If user specified a config file, try that + # Otherwise use HOME == either $HOME or ./ + + if not CONF: + CONF = os.path.join(HOME, "." + PROGNAME) try: cf = open(CONF) except: - WrnMsg(wNOCONF % CONF) + WrnMsg(wCONFOPEN % (CONF, wNOCMDS)) UI.rcfile = {} return + # Successful open of config file - Begin processing it + # Cleanout any old UI.rcfile = {} @@ -570,7 +574,10 @@ def KeyHomeDir(event): - LoadDirList(HOME) + if HOME: + LoadDirList(HOME) + else: + LoadDirList(STARTDIR) # End of 'KeyHomeDir()' @@ -1005,8 +1012,9 @@ # Get starting directory into canonical form STARTDIR = os.path.abspath(STARTDIR) + # Parse the and store configuration file, if any -ParseConfFile() +ParseConfFile(None) # Initialize directory stack UI.LastDir = []