diff --git a/tconfpy.py b/tconfpy.py index d41f686..3cf4abf 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 2.101 2005/01/13 23:03:24 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 2.102 2005/01/14 08:15:52 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -58,6 +58,7 @@ ATEOF = "EOF" # Use as line number when at EOF FILENUM = "[File: %s Line: %s] " # Display filename and linenum +INMEMORY = "In-Memory Configuration" # Configuration is in-memory MSGPROMPT = "%s>" PTR = " ---> " # Textual pointer for debug output STARTUP = "STARTUP" # Indicates message before any lines processed @@ -278,6 +279,7 @@ Messages["eBADCOND"] = FILENUM + "Bad '%s' Directive. %s" Messages["eBADREGEX"] = FILENUM + "Bad Regular Expression, '%s', In Legal Values List For Variable '%s'" Messages["eBADSYNTAX"] = FILENUM + "Syntax Error. Statement Not In Known Form" +Messages["eCONFIGTYPE"] = "Don't Know How To Process Configurations Of Type '%s'" Messages["eCONFOPEN"] = FILENUM + "Cannot Open The File '%s'" Messages["eDESCRIPTBAD"] = "API Error: %s For Variable '%s'" Messages["eELSENOIF"] = FILENUM + "'%s' Without Preceding '%s' Form" % (ELSE, IF) @@ -391,7 +393,7 @@ # Public API To Module # #----------------------------------------------------------# -def ParseConfig(cfgfile, +def ParseConfig(configuration, CallingProgram=PROGINFO, InitialSymTable=SymbolTable(), AllowNewVars=True, @@ -523,25 +525,42 @@ if SymTable.DEBUG: DebugMsg("dNAMESPACE", (STARTUP, STARTUP, SymTable.Symbols[NAMESPACE].Value)) + # We now can parse the configuration, either in a file or in-memory. - # Parse the file + cfgtype = type(configuration) + + # It's a file if the passed parameter is a string - assumed to be the filename + + if cfgtype == type('x'): + ParseFile(configuration, eSTARTUP, 0) + configname = configuration # Name of the configuration - ParseFile(cfgfile, eSTARTUP, 0) + # It's an in-memory configuration if the passed parameter is a list + + elif cfgtype == type([]): + ParseInMemory(configuration) + configname = INMEMORY + pass + + # Anything else is illegal + + else: + ErrorMsg("eCONFIGTYPE", str(cfgtype).split()[-1][1:-2]) # Make sure we had all condition blocks balanced with matching '.endif' finalcond = len(SymTable.CondStack) if finalcond != 1: - ErrorMsg("eENDIFMISS", (cfgfile, ATEOF, finalcond-1)) + ErrorMsg("eENDIFMISS", (configname, ATEOF, finalcond-1)) # Make sure we ended any literal processing properly if SymTable.INLITERAL: - WarningMsg("wENDLITMISS", (cfgfile, ATEOF)) + WarningMsg("wENDLITMISS", (configname, ATEOF)) # Return the parsing results if SymTable.DEBUG: - DebugMsg("dNUMLINES", (cfgfile, SymTable.TotalLines)) + DebugMsg("dNUMLINES", (configname, SymTable.TotalLines)) # Strip out Prefefined Variables if user does not want them @@ -688,6 +707,27 @@ ########## +# Parse An In-Memory Configuration +########## + +def ParseInMemory(cfglist): + + global SymTable + + linenum=0 + + # Process and massage the configuration file + for line in cfglist: + linenum += 1 + SymTable.TotalLines += 1 + + # Parse this line + ParseLine(line, INMEMORY, linenum) + +# End of 'ParseInMemory()' + + +########## # Parse A Line ##########