Implemented variable descriptor as an object rather than a list for
simplicity of use.
Removed explicit __all__[].
1 parent c1473a6 commit 9c5d93b64298d6871e7b757cd6c81f2c1869bf84
@tundra tundra authored on 19 Mar 2004
Showing 1 changed file
View
101
tconfpy.py
 
# Program Information
 
PROGNAME = "tconfpy"
RCSID = "$Id: tconfpy.py,v 1.122 2004/03/19 22:41:17 tundra Exp $"
RCSID = "$Id: tconfpy.py,v 1.123 2004/03/20 00:02:09 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
#----------------------------------------------------------#
 
 
#------------------- Nothing Below Here Should Need Changing -----------------#
 
#----------------------------------------------------------#
# Public Features Of This Module #
#----------------------------------------------------------#
 
 
__all__ = ["ParseConfig"]
 
 
 
#----------------------------------------------------------#
# Imports #
#----------------------------------------------------------#
# Symbol Table is a dictionary in the form:
#
# {varname : descriptor}
#
# where the descriptor is a list:
# where the descriptor is an object with the following attributes
#
# [value, iswriteable, type, default value, [list of legal vals], min, max]
 
 
# Indexes Into Symbol Table Variable Descriptor
 
SYM_VALUE = 0
SYM_WRITE = 1
SYM_TYPE = 2
SYM_DEFAULT = 3
SYM_VALUES = 4
SYM_MIN = 5
SYM_MAX = 6
 
# Value, Writeable, Type, Default, LegalVals = [list of legal vals], Min, Max]
 
 
#
# Legal Variable Types
 
TYP_BOOL = 'b'
TYPE_CMPLX = 'x'
TYP_FLOAT = 'f'
TYP_INT = 'i'
TYP_STRING = 's'
 
# Boolean Flags
 
SYM_WRITEABLE = True
TYPE_BOOL = type(True)
TYPE_COMPLEX = type(1-1j)
TYPE_FLOAT = type(3.14)
TYPE_INT = type(1)
TYPE_STRING = type('s')
 
# Object to hold full description and options for a given variable
 
class VarDescriptor:
 
# Default variable type is a writeable string with no constraints
def __init__(self):
self.Value = ""
self.Writeable = True
self.Type = TYPE_STRING
self.Default = ""
self.LegalVals = None
self.Min = None
self.Max = None
 
# End of class 'VarDescriptor'
 
 
# Initialize the table using the builtin symbols
 
SymTable = {}
 
for sym in Reserved:
 
SymTable[sym] = [eval(sym),
not SYM_WRITEABLE,
TYP_STRING,
eval(sym),
None,
None,
None
]
descript = VarDescriptor()
descript.Value = eval(sym)
 
SymTable[sym] = descript
 
##########
# Error, Warning, And Debug Message Strings Stored In A Global Dictionary
##########
line = line.replace(var, os.getenv(sym[1:]))
 
# Handle variables in symbol table
elif sym in SymTable:
line = line.replace(var, str(SymTable[sym][SYM_VALUE]))
line = line.replace(var, str(SymTable[sym].Value))
 
# Reference to undefined variable
else:
# There are times a reference to an undefined variable