| |
---|
| | |
---|
| | # 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 |
---|
| | |
---|
| |
---|
| | #----------------------------------------------------------# |
---|
| | |
---|
| | |
---|
| | |
---|
| | #------------------- Nothing Below Here Should Need Changing ------------------# |
---|
| | #------------------- Nothing Below Here Should Need Changing -----------------# |
---|
| | |
---|
| | #----------------------------------------------------------# |
---|
| | # Public Features Of This Module # |
---|
| | #----------------------------------------------------------# |
---|
| | |
---|
| | |
---|
| | __all__ = ["ParseConfig"] |
---|
| | |
---|
| | |
---|
| | |
---|
| | #----------------------------------------------------------# |
---|
| | # Imports # |
---|
| |
---|
| | ########## |
---|
| | # Constants |
---|
| | ########## |
---|
| | |
---|
| | MSGPOS = 10 # Where to start message output |
---|
| | MSGPOS = 10 # Where to start message output |
---|
| | PARSE_GOOD = True # Indicates successful parsing |
---|
| | |
---|
| | ########## |
---|
| | # Literals |
---|
| | ########## |
---|
| |
---|
| | ########## |
---|
| | # Error Messages |
---|
| | ########## |
---|
| | |
---|
| | eERROR = "ERROR" |
---|
| | eCONFOPEN = "Cannot Open The File '%s'" |
---|
| | eERROR = "ERROR" |
---|
| | |
---|
| | |
---|
| | ########## |
---|
| | # Informational Messages |
---|
| | ########## |
---|
| | |
---|
| | iERRTST = "Test Error Message - Ignore" |
---|
| | iINFO = "INFO" |
---|
| | iNUMLINES = "Processed %s Lines In '%s'" |
---|
| | iWARNTST = "Test Warning Message - Ignore" |
---|
| | |
---|
| | |
---|
| | ########## |
---|
| |
---|
| | ########## |
---|
| | # Warning Messages |
---|
| | ########## |
---|
| | |
---|
| | wWARNING = "WARNING" |
---|
| | wWARNING = "WARNING" |
---|
| | |
---|
| | |
---|
| | |
---|
| | #----------------------------------------------------------# |
---|
| | # Global Variables & Data Structures # |
---|
| | #----------------------------------------------------------# |
---|
| | |
---|
| | |
---|
| | 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 ---------------------------------# |
---|
| | |
---|
| | |
---|
| | #----------------------------------------------------------# |
---|
| | # Object Base Class Definitions # |
---|
| | #----------------------------------------------------------# |
---|
| | |
---|
| | |
---|
| | |
---|
| | |
---|
| | |
---|
| | #----------------------------------------------------------# |
---|
| | # Supporting Function Definitions # |
---|
| | #----------------------------------------------------------# |
---|
| | |
---|
| |
---|
| | |
---|
| | return mkmsg(error + "!", eERROR) |
---|
| | |
---|
| | # End of 'ErrorMsg()' |
---|
| | |
---|
| | |
---|
| | ########## |
---|
| | # Create An Informational Message |
---|
| | ########## |
---|
| | |
---|
| | def InfoMsg(info): |
---|
| | |
---|
| | return mkmsg(info + ".", iINFO) |
---|
| | |
---|
| | # End of 'InfoMsg()' |
---|
| | |
---|
| | |
---|
| | ########## |
---|
| | # Construct A Standard Application Message String |
---|
| |
---|
| | # End of 'WarningMsg()' |
---|
| | |
---|
| | |
---|
| | #----------------------------------------------------------# |
---|
| | # Entry Point # |
---|
| | # Entry Point On Direct Invocation # |
---|
| | #----------------------------------------------------------# |
---|
| | |
---|
| | if __name__ == '__main__': |
---|
| | |
---|
| |
---|
| | print ErrorMsg(iERRTST) |
---|
| | 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()' |
---|
| | |
---|
| | |
---|
| | |