Added ability to use environment variable references throughout.
1 parent 587f3ab commit bb4e4cc89cad06afd9769bf7d5bf511171ac5ad4
@tundra tundra authored on 19 Mar 2004
Showing 1 changed file
View
29
tconfpy.py
 
# Program Information
 
PROGNAME = "tconfpy"
RCSID = "$Id: tconfpy.py,v 1.120 2004/03/19 10:16:16 tundra Exp $"
RCSID = "$Id: tconfpy.py,v 1.121 2004/03/19 11:03:33 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
#----------------------------------------------------------#
# Imports #
#----------------------------------------------------------#
 
import os.path
import os
import re
 
 
#----------------------------------------------------------#
HASH = r'#'
COMMENT = HASH # Comment introducer character
DELIML = r'[' # Left delimiter for vbl reference
DELIMR = r']' # Right delimiter for vbl reference
DOLLAR = r'$' # Used to note enviro vbl
DOLLAR = r'$'
ENVIRO = DOLLAR # Used to note environment variable
EQUAL = r'=' # Used in vbl definition
EQUIV = r"==" # Used in conditional tests
NOTEQUIV = r"!=" # Used in conditional tests
 
def DerefVar(line, cfgfile, linenum, reporterr=True):
 
# Find all symbols refrences and replace w/sym table entry if present
 
 
ref_ok = True
for var in VarRef.findall(line):
 
sym = var[1:-1] # Strip delimiters
if sym in SymTable:
 
# Handle environment variables
if sym[0] == ENVIRO and sym[1:] in os.environ:
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]))
 
# Reference to undefined variable
else:
 
if FIRSTTOK == INCLUDE:
line, ref_ok = DerefVar(line.split(INCLUDE)[1].strip(), cfgfile, linenum)
 
if ref_ok:
ParseFile(line)
# Only attempt the include if all the variable dereferencing was successful
if ref_ok:
ParseFile(line)
 
 
#####
# Conditional Processing