diff --git a/tconfpy.py b/tconfpy.py index 9d29857..01d2873 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # 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 @@ -40,7 +40,7 @@ # Imports # #----------------------------------------------------------# -import os.path +import os import re @@ -73,7 +73,8 @@ 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 @@ -402,11 +403,18 @@ # 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 @@ -527,8 +535,9 @@ 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) #####