diff --git a/tconfpy.py b/tconfpy.py index e5f7fa0..0731bf6 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.101 2004/03/09 08:14:04 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.102 2004/03/09 09:50:32 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -26,7 +26,15 @@ -#------------------- Nothing Below Here Should Need Changing ------------------# +#------------------- Nothing Below Here Should Need Changing -----------------# + +#----------------------------------------------------------# +# Public Features Of This Module # +#----------------------------------------------------------# + + +__all__ = ["ParseConfig"] + #----------------------------------------------------------# @@ -52,7 +60,8 @@ # Constants ########## -MSGPOS = 10 # Where to start message output +MSGPOS = 10 # Where to start message output +PARSE_GOOD = True # Indicates successful parsing ########## # Literals @@ -68,7 +77,8 @@ # Error Messages ########## -eERROR = "ERROR" +eCONFOPEN = "Cannot Open The File '%s'" +eERROR = "ERROR" ########## @@ -76,6 +86,8 @@ ########## iERRTST = "Test Error Message - Ignore" +iINFO = "INFO" +iNUMLINES = "Processed %s Lines In '%s'" iWARNTST = "Test Warning Message - Ignore" @@ -88,7 +100,7 @@ # Warning Messages ########## -wWARNING = "WARNING" +wWARNING = "WARNING" @@ -97,6 +109,13 @@ #----------------------------------------------------------# +IgnoreCase = False # Case observed by default +LineNum = 0 # Keep track of the line number as we go +MsgList = [] # Place to keep any warnings and errors we find +ParseOptions = {} # Options and settings for know variables +SymTable = {} # Results of the parsing stored here + + #--------------------------- Code Begins Here ---------------------------------# @@ -105,8 +124,8 @@ # Object Base Class Definitions # #----------------------------------------------------------# - + #----------------------------------------------------------# # Supporting Function Definitions # #----------------------------------------------------------# @@ -124,6 +143,17 @@ ########## +# Create An Informational Message +########## + +def InfoMsg(info): + + return mkmsg(info + ".", iINFO) + +# End of 'InfoMsg()' + + +########## # Construct A Standard Application Message String ########## @@ -151,7 +181,7 @@ #----------------------------------------------------------# -# Entry Point # +# Entry Point On Direct Invocation # #----------------------------------------------------------# if __name__ == '__main__': @@ -161,3 +191,47 @@ print WarningMsg(iWARNTST) +#----------------------------------------------------------# +# Public API To Module # +#----------------------------------------------------------# + + +def ParseConfig(cfgfile, options, ignorecase=False): + + global IgnoreCase, LineNum, MsgList, ParseOptions, SymTable + + # Initialize the globals + + IgnoreCase = ignorecase + LineNum = 0 + MsgList = [] + ParseOptions = options + SymTable = {} + + try: + cf = open(cfgfile) + # Successful open of config file - Begin processing it + + # Process and massage the configuration file + for line in cf.read().splitlines(): + LineNum += 1 + + # Parse this line + if line: + pass + #ParseLine(line, file, LineNum) + + # Close the config file + cf.close() + + # Return the parsing results + + MsgList.append(InfoMsg(iNUMLINES %(str(LineNum), cfgfile))) + return (SymTable, MsgList, PARSE_GOOD) + + except: + MsgList.append(ErrorMsg(eCONFOPEN % cfgfile)) + return (SymTable, MsgList, not PARSE_GOOD) + +# End of 'ParseConfig()' +