diff --git a/tsearchpath.py b/tsearchpath.py index a43dd30..f15295d 100755 --- a/tsearchpath.py +++ b/tsearchpath.py @@ -5,48 +5,14 @@ # Program Information -PROGNAME = "tsearchpath" -BASENAME = PROGNAME.split(".py")[0] -PROGENV = BASENAME.upper() -RCSID = "$Id: tsearchpath.py,v 1.100 2010/06/24 15:27:49 tundra Exp $" -VERSION = RCSID.split()[2] - -# Copyright Information - -CPRT = "(c)" -DATE = "2010" -OWNER = "TundraWare Inc." -RIGHTS = "All Rights Reserved." -COPYRIGHT = "Copyright %s %s, %s %s" % (CPRT, DATE, OWNER, RIGHTS) - - -PROGVER = PROGNAME + " " + VERSION + (" - %s" % COPYRIGHT) -HOMEPAGE = "http://www.tundraware.com/Software/%s\n" % BASENAME - - -#----------------------------------------------------------# -# Variables User Might Change # -#----------------------------------------------------------# - - - -#------------------- Nothing Below Here Should Need Changing ------------------# +RCSID = "$Id: tsearchpath.py,v 1.101 2010/06/24 19:44:52 tundra Exp $" #----------------------------------------------------------# # Imports # #----------------------------------------------------------# -import getopt import os -import sys -import tconfpy - - -#----------------------------------------------------------# -# Aliases & Redefinitions # -#----------------------------------------------------------# - #----------------------------------------------------------# @@ -55,215 +21,30 @@ -##### -# Constants -##### - - - -##### -# Literals -##### - - - -#----------------------------------------------------------# -# Prompts, & Application Strings # -#----------------------------------------------------------# ##### -# Debug Messages +# Search Path For Specific File ##### -##### -# Debug Messages -##### -DEBUGFLAG = "-d" -dDEBUG = "DEBUG" -dPROGENV = "$" + PROGENV +def tsearchpath(filename, searchpath, PATHDELIM=":", PATHSEP=os.path.sep): -##### -# Error Messages -##### + """ Search 'searchpath' looking for 'filename' returning + on first (leftmost) match. -eBADARG = "Invalid command line: %s!" -eERROR = "ERROR" + If found, return the fully qualified filename. + If not found, return None. + 'searchpath' is a list a paths to search separated by + PATHDELIM characters. -##### -# Informational Messages -##### - -iINFO = "INFO" - - -##### -# Usage Prompts -##### - -uTable = [PROGVER, - HOMEPAGE, - "usage: " + PROGNAME + " [-fhv]", - " where,", - " -f file configuration file to use", - " -h print this help information", - " -v print detailed version information", - ] - - -#----------------------------------------------------------# -# Global Variables & Data Structures # -#----------------------------------------------------------# - -CFGFILE = os.path.join(os.getenv("HOME"), "." + PROGNAME) # conf file - - -#--------------------------- Code Begins Here ---------------------------------# - - -#----------------------------------------------------------# -# Object Base Class Definitions # -#----------------------------------------------------------# - + If the 'filename' passed contains 'PATHSEP' characters, + presume it to be a relative/absolute path specified + by the caller. In this case, ignore 'searchpath' + and just return the fully qualified filename. + """ + pass -#----------------------------------------------------------# -# Supporting Function Definitions # -#----------------------------------------------------------# - - -def ColumnPad(list, padchar=" ", padwidth=20): - - retval = "" - for l in list: - l = str(l) - retval += l + ((padwidth - len(l)) * padchar) - - return retval.strip() - -# End of 'ColumnPad()' - - -##### -# Print A Debug Message -##### - -def DebugMsg(msg): - PrintStderr(PROGNAME + " " + dDEBUG + ": " + msg) - -# End of 'DebugMsg()' - - -##### -# Dump The State Of The Program -##### - -def DumpState(): - - # Dump the command line - DebugMsg(ColumnPad(["Command Line", sys.argv])) - - # Names of all the state variables we want dumped - state = [ - ] - - for k in state: - DebugMsg(ColumnPad([k, eval(k)])) - -# End of 'DumpState()' - - -##### -# Print An Error Message -##### - -def ErrorMsg(emsg): - PrintStderr(PROGNAME + " " + eERROR + ": " + emsg) - -# End of 'ErrorMsg()' - - -##### -# Print An Info Message -##### - -def InfoMsg(imsg): - PrintStderr(PROGNAME + " " + iINFO + ": " + imsg) - -# End of 'InfoMsg()' - - -##### -# Print To stderr -##### - -def PrintStderr(msg, trailing="\n"): - sys.stderr.write(msg + trailing) - -# End of 'PrintStderr()' - - -##### -# Print To stdout -##### - -def PrintStdout(msg, trailing="\n"): - sys.stdout.write(msg + trailing) - -# End of 'PrintStdout' - - -##### -# Print Usage Information -##### - -def Usage(): - for line in uTable: - PrintStdout(line) - -# End of 'Usage()' - - -#----------------------------------------------------------# -# Program Entry Point # -#----------------------------------------------------------# - -# Command line processing - Process any options set in the -# environment first, and then those given on the command line - -OPTIONS = sys.argv[1:] -envopt = os.getenv(PROGENV) -if envopt: - OPTIONS = envopt.split() + OPTIONS - -try: - opts, args = getopt.getopt(OPTIONS, '-f:hv') -except getopt.GetoptError as e: - ErrorMsg(eBADARG % e.args[0]) - sys.exit(1) - -for opt, val in opts: - if opt == "-f": - CFGFILE=val - if opt == "-h": - Usage() - sys.exit(0) - if opt == "-v": - print RCSID - sys.exit(0) - -# Process the configuration file - -retval = tconfpy.ParseConfig(CFGFILE, CallingProgram="%s %s " % (PROGNAME, VERSION)) - -# Print any errors or warning generated by the parse - -for x in (retval.ErrMsgs, retval.WarnMsgs): - for y in x: - print y - -# If there were any errors, we're done -if retval.ErrMsgs: - sys.exit(0) +# End of 'tsearchpath()'