Combined reserved and predfined symbols into a single data dictionary.
1 parent 77c0c2f commit 0536f86d0fb18e8c44f6f07d712a212f33d57347
@tundra tundra authored on 13 Apr 2004
Showing 1 changed file
View
118
tconfpy.py
 
# Program Information
 
PROGNAME = "tconfpy"
RCSID = "$Id: tconfpy.py,v 1.169 2004/04/13 23:06:01 tundra Exp $"
RCSID = "$Id: tconfpy.py,v 1.170 2004/04/14 02:26:08 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
NAMESPACE = "NAMESPACE" # Key used to get current namespace
NSSEP = '.' # Namespace separator character
NOTEQUIV = r"!=" # Used in conditional tests
 
# Pre-Defined System Symbols
 
PREDEFINTRO = '.'
 
Predefined = {PREDEFINTRO + "PLATFORM" : sysplat,
PREDEFINTRO + "OSDETAILS" : platform.platform(),
PREDEFINTRO + "OSNAME" : platform.system(),
PREDEFINTRO + "OSRELEASE" : platform.release(),
PREDEFINTRO + "PYTHONVERSION" : platform.python_version(),
PREDEFINTRO + "MACHINENAME" : platform.node()
}
 
# Control and conditional symbols
 
CONDINTRO = '.' # Conditional introducer token
INCLUDE = CONDINTRO + "include"
ENDIF = CONDINTRO + "endif"
LITERAL = CONDINTRO + "literal"
ENDLITERAL = CONDINTRO + "endliteral"
 
Reserved = ["HASH", "DELIML", "DELIMR", "DOLLAR", "EQUAL", "EQUIV", "NOTEQUIV", "NSSEP",
"INCLUDE", "IF", "IFALL", "IFANY", "IFNONE", "ELSE", "ENDIF", "LITERAL", "ENDLITERAL"]
 
# Pre-Defined System Symbols
 
PREDEFINTRO = '.'
 
Predefined = {"DELIML" : DELIML,
"DELIMR" : DELIMR,
"DOLLAR" : DOLLAR,
"ELSE" : ELSE,
"ENDIF" : ENDIF,
"ENDLITERAL" : ENDLITERAL,
"EQUAL" : EQUAL,
"EQUIV" : EQUIV,
"HASH" : HASH,
"IF" : IF,
"IFALL" : IFALL,
"IFANY" : IFANY,
"IFNONE" : IFNONE,
"INCLUDE" : INCLUDE,
"LITERAL" : LITERAL,
"NOTEQUIV" : NOTEQUIV,
"NSSEP" : NSSEP,
PREDEFINTRO + "MACHINENAME" : platform.node(),
PREDEFINTRO + "OSDETAILS" : platform.platform(),
PREDEFINTRO + "OSNAME" : platform.system(),
PREDEFINTRO + "OSRELEASE" : platform.release(),
PREDEFINTRO + "PLATFORM" : sysplat,
PREDEFINTRO + "PYTHONVERSION" : platform.python_version()
}
 
# Regular Expressions
 
reVARWHITE = r".*\s+.*" # Look for embedded whitespace
 
# End of class 'VarDescriptor'
 
 
# Initialize the table using the builtin symbols
# Initialize the table using the predefined symbols
 
SymTable = {}
 
for sym in Reserved:
 
descript = VarDescriptor()
descript.Value = eval(sym)
descript.Writeable = False
 
SymTable[sym] = descript
 
# Add the predefined symbols
 
for var in Predefined.keys():
 
d = VarDescriptor()
if not ref_ok:
return line, ref_ok
# By default, all variable names assumed to be relative to
# current namespace unless escaped with NSSEP.
# However, environment variables and predefined variables
# are always presumed to be relative to the top-level
# namespace and are left untouched here.
# current namespace unless escaped with NSSEP. However,
# environment variables and predefined variables are always
# presumed to be relative to the top-level namespace and are
# left untouched here.
 
if sym not in Predefined and sym[0] != ENVIRO:
# Look for an escape. This makes the variable
# ***NOTE***
#
# This test needs to happen here before any of the
# namespace stuff below. Doing it here guarantees we
# catch an attempt to modify one of the Predefined or
# Reserved variables, which are always marked RO and are
# always relative to the top-level namespace. This way,
# we don't have to put in an explicit check to ignore
# Predefined and Reserved variables in the namespace
# munging below. IOW, Don't move this test down into the
# body of the variable name processing where namespace
# fiddling takes place.
# catch an attempt to modify one of the Predefined
# variables, which are always marked RO and are always
# relative to the top-level namespace. This way, we don't
# have to put in an explicit check to ignore Predefined
# variables in the namespace munging below. IOW, Don't
# move this test down into the body of the variable name
# processing where namespace fiddling takes place.
 
elif l in SymTable and not SymTable[l].Writeable:
ErrorMsg("eVARREADONLY", (cfgfile, linenum, l))
 
pk = Predefined.keys()
pk.sort()
for var in pk:
 
val = Predefined[var]
print "%s%s%s" % (var, (20-len(var)) * " ", val)
 
 
 
if var[0] == PREDEFINTRO:
val = Predefined[var]
print "%s%s%s" % (var, (20-len(var)) * " ", val)