| |
---|
| | |
---|
| | # Program Information |
---|
| | |
---|
| | PROGNAME = "tconfpy" |
---|
| | RCSID = "$Id: tconfpy.py,v 1.149 2004/03/27 01:24:34 tundra Exp $" |
---|
| | RCSID = "$Id: tconfpy.py,v 1.150 2004/03/31 21:40:42 tundra Exp $" |
---|
| | VERSION = RCSID.split()[2] |
---|
| | |
---|
| | # Copyright Information |
---|
| | |
---|
| |
---|
| | IF = CONDINTRO + "if" |
---|
| | IFALL = IF + "all" |
---|
| | IFANY = IF + "any" |
---|
| | IFNONE = IF + "none" |
---|
| | ELSE = CONDINTRO + "else" |
---|
| | ENDIF = CONDINTRO + "endif" |
---|
| | LITERAL = CONDINTRO + "literal" |
---|
| | ENDLITERAL = CONDINTRO + "endliteral" |
---|
| | |
---|
| | Reserved = ["HASH", "DELIML", "DELIMR", "DOLLAR", "EQUAL", "EQUIV", "NOTEQUIV", "NSSEP", |
---|
| | "INCLUDE", "IF", "IFALL", "IFANY", "IFNONE", "ENDIF", "LITERAL", "ENDLITERAL"] |
---|
| | "INCLUDE", "IF", "IFALL", "IFANY", "IFNONE", "ELSE", "ENDIF", "LITERAL", "ENDLITERAL"] |
---|
| | |
---|
| | |
---|
| | # Regular Expressions |
---|
| | |
---|
| |
---|
| | 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["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) |
---|
| | Messages["eENDIFEXTRA"] = FILENUM + "'" + ENDIF + "' Without Matching Condition" |
---|
| | Messages["eENDIFMISS"] = FILENUM + "Missing %d" + " '%s' " % ENDIF + " Statement(s)" |
---|
| | 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" |
---|
| |
---|
| | # Close the config file |
---|
| | cf.close() |
---|
| | |
---|
| | # File open failed for some reason |
---|
| | except: |
---|
| | except IOError: |
---|
| | ErrorMsg("eCONFOPEN", (current_cfg, current_linenum, cfgfile)) # Record the error |
---|
| | |
---|
| | # End of 'ParseFile()' |
---|
| | |
---|
| |
---|
| | |
---|
| | |
---|
| | # Get first token on the line |
---|
| | FIRSTTOK = line.split()[0] |
---|
| | |
---|
| | |
---|
| | ##### |
---|
| | # ELSE Processing |
---|
| | ##### |
---|
| | |
---|
| | if line == ELSE: |
---|
| | |
---|
| | # Get the enclosing block type and state |
---|
| | |
---|
| | btyp, bst = CondStack.pop() |
---|
| | |
---|
| | # ELSE is only permitted after an immediately preceding IF form |
---|
| | |
---|
| | |
---|
| | if btyp != IF: |
---|
| | ErrorMsg("eELSENOIF", (cfgfile, linenum)) |
---|
| | CondStack.append(["", False]) # Error makes all that follows False |
---|
| | |
---|
| | # We *are* in an IF block and ELSE is appropriate. |
---|
| | # To determine whether the ELSE should be taken or not we have |
---|
| | # to look at the state of that IF block AND the state of |
---|
| | # the block that contains the IF. This is because the IF |
---|
| | # block state is the AND of the state of its parent block |
---|
| | # and its own logical state - i.e. A block can be made |
---|
| | # logically False by its containing block even if the condition |
---|
| | # tested is True. |
---|
| | |
---|
| | else: |
---|
| | |
---|
| | # If the containing block is True, the contained IF state is legitimate. |
---|
| | # The ELSE inverts the IF state in that case. |
---|
| | |
---|
| | if CondStack[-1][1]: |
---|
| | CondStack.append([ELSE, not bst]) |
---|
| | |
---|
| | # The containing block is false, so everything within it is also false |
---|
| | |
---|
| | else: |
---|
| | CondStack.append([ELSE, False]) |
---|
| | |
---|
| | if DEBUG: |
---|
| | DebugMsg("dPARSEDLINE", (cfgfile, linenum, orig, line)) |
---|
| | |
---|
| | return |
---|
| | |
---|
| | |
---|
| | ##### |
---|
| | # ENDIF Processing |
---|
| | ##### |
---|
| |
---|
| | # For all numeric types, the test is to see if the new |
---|
| | # value is one of the ones enumerated in LegalVals. |
---|
| | # |
---|
| | # For strings, LegalVals is presumed to contain a list |
---|
| | # of regular expressions. The test is to compile |
---|
| | each |
---|
| | # of regular expressions. The test is to compile each |
---|
| | # regex and see if any match the new value. |
---|
| | |
---|
| | if update and lv: |
---|
| | |
---|
| |
---|
| | |