| |
---|
| | |
---|
| | # Program Information |
---|
| | |
---|
| | PROGNAME = "tconfpy" |
---|
| | RCSID = "$Id: tconfpy.py,v 2.110 2005/01/19 23:39:29 tundra Exp $" |
---|
| | RCSID = "$Id: tconfpy.py,v 2.111 2005/01/20 00:31:24 tundra Exp $" |
---|
| | VERSION = RCSID.split()[2] |
---|
| | |
---|
| | # Copyright Information |
---|
| | |
---|
| |
---|
| | |
---|
| | class SymbolTable(object): |
---|
| | |
---|
| | def __init__(self): |
---|
| | |
---|
| | # Returned by the parser |
---|
| | |
---|
| | self.Symbols = {} |
---|
| | self.DebugMsgs = [] |
---|
| | self.ErrMsgs = [] |
---|
| | self.WarnMsgs = [] |
---|
| | self.LiteralLines = [] |
---|
| | self.TotalLines = 0 |
---|
| | self.Visited = [] |
---|
| | |
---|
| | # Anything below here is used interally and not returned |
---|
| | |
---|
| | self.Templates = Template() |
---|
| | self.ALLOWNEWVAR = True |
---|
| | self.TEMPONLY = False |
---|
| | self.LITERALVARS = False |
---|
| | self.INLITERAL = False |
---|
| | self.DEBUG = False |
---|
| | self.CondStack = [["", True],] # Always has one entry as a sentinel |
---|
| | self.TotalLines = 0 |
---|
| | |
---|
| | # End of class 'SymbolTable' |
---|
| | |
---|
| | class Template(object): |
---|
| |
---|
| | Messages["dPARSEDLINE"] = FILENUM + "'%s'" + PTR + "'%s'" |
---|
| | Messages["dREGEXMATCH"] = FILENUM + "Value '%s' Matched Regex '%s' For Variable '%s'" |
---|
| | Messages["dVAREXISTS"] = FILENUM + "Checking To See If Variable '%s' Exists" |
---|
| | Messages["dVARREF"] = FILENUM + "Variable Dereference: '%s'" + PTR + "'%s'" |
---|
| | Messages["dVISITED"] = "Configuration Files Processed: '%s'" |
---|
| | |
---|
| | |
---|
| | ########### |
---|
| | # Error Literals And Messages |
---|
| |
---|
| | Messages["eEQUIVEXTRA"] = FILENUM + "Only a single '%s' Or '%s' Operator Permitted" % (EQUIV, NOTEQUIV) |
---|
| | Messages["eIFEXTRATXT"] = FILENUM + "Extra Text On Line. '%s' Only Accepts Variable References As Arguments" |
---|
| | Messages["eNOTLEGALVAL"] = FILENUM + "'%s' Not Found In List Of Legal Values For Variable '%s'" |
---|
| | Messages["eNOTSTRING"] = FILENUM + "%s Is Not A String Type - Ignoring" |
---|
| | Messages["eRECURSIVE"] = FILENUM + "Recursive .includes Forbidden" |
---|
| | Messages["eSTRINGLONG"] = FILENUM + "'%s' Too Long For Variable '%s'. Maximum Length Is %s" |
---|
| | Messages["eSTRINGSHORT"] = FILENUM + "'%s' Too Short For Variable '%s'. Minimum Length is %s" |
---|
| | Messages["eSYMBADCHAR"] = FILENUM + "Symbol '%s' Contains Illegal Character '%s'" |
---|
| | Messages["eSYMBADSTART"] = FILENUM + "Symbol '%s' Begins With An Illegal Character" |
---|
| |
---|
| | # Return the parsing results |
---|
| | |
---|
| | if SymTable.DEBUG: |
---|
| | DebugMsg("dNUMLINES", (configname, SymTable.TotalLines)) |
---|
| | DebugMsg("dVISITED", (SymTable.Visited)) |
---|
| | |
---|
| | # Strip out Prefefined Variables if user does not want them |
---|
| | |
---|
| | if not ReturnPredefs: |
---|
| |
---|
| | def ParseFile(cfgfile, current_cfg, current_linenum): |
---|
| | |
---|
| | global SymTable |
---|
| | |
---|
| | linenum = 0 |
---|
| | |
---|
| | # Inhbit recursive includes |
---|
| | |
---|
| | if cfgfile in SymTable.Visited: |
---|
| | |
---|
| | ErrorMsg("eRECURSIVE", (current_cfg, current_linenum)) |
---|
| | return |
---|
| | |
---|
| | else: |
---|
| | SymTable.Visited.append(cfgfile) |
---|
| | |
---|
| | try: |
---|
| | cf = open(cfgfile) |
---|
| | |
---|
| | # Process and massage the configuration file |
---|
| | for line in cf.read().splitlines(): |
---|
| | |
---|
| | SymTable.TotalLines += 1 |
---|
| | linenum +=1 |
---|
| | |
---|
| | # Parse this line |
---|
| | ParseLine(line, cfgfile, SymTable.TotalLines) |
---|
| | ParseLine(line, cfgfile, linenum) |
---|
| | |
---|
| | # Close the config file |
---|
| | cf.close() |
---|
| | |
---|
| |
---|
| | def ParseInMemory(cfglist, configname): |
---|
| | |
---|
| | global SymTable |
---|
| | |
---|
| | linenum = 0 |
---|
| | |
---|
| | SymTable.Visited.append(configname) |
---|
| | |
---|
| | # Process and massage the configuration file |
---|
| | |
---|
| | for line in cfglist: |
---|
| | |
---|
| | SymTable.TotalLines += 1 |
---|
| | linenum += 1 |
---|
| | |
---|
| | # The entry must be a string |
---|
| | if type(line) == TYPE_STRING: |
---|
| | |
---|
| | # Parse this line |
---|
| | ParseLine(line, configname, SymTable.TotalLines) |
---|
| | ParseLine(line, configname, linenum) |
---|
| | |
---|
| | # Anything else is a problem |
---|
| | else: |
---|
| | ErrorMsg("eNOTSTRING", (configname, SymTable.TotalLines, str(line))) |
---|
| | ErrorMsg("eNOTSTRING", (configname, linenum, str(line))) |
---|
| | |
---|
| | # End of 'ParseInMemory()' |
---|
| | |
---|
| | |
---|
| |
---|
| | |