diff --git a/tren.py b/tren.py index f085e38..d949f55 100755 --- a/tren.py +++ b/tren.py @@ -8,7 +8,7 @@ PROGNAME = "tren.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -RCSID = "$Id: tren.py,v 1.165 2010/03/05 19:05:23 tundra Exp $" +RCSID = "$Id: tren.py,v 1.166 2010/03/05 21:54:36 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -98,7 +98,15 @@ OPTINTRO = "-" # Option introducer RANGESEP = ":" # Separator for instance ranges SINGLEINST = "SINGLEINST" # Indicates a single, not range, replacement instance -TOKENDELIM = "/""" # Symbol used to delimit renaming tokens + + +##### +# Replacement Token Literals +##### + +TOKENDELIM = "/" # Symbol used to delimit renaming tokens +TOKENENV = "$" # Environment variable token + # Internal program state literals @@ -682,7 +690,7 @@ # There must be an even number of token delimiters # or the renaming token is malformed - + if rentokens and len(rentokens[-1]) != 2: ErrorMsg(eBADRENAMETOK % renstring) @@ -695,6 +703,22 @@ rentokens[i].append(renstring[rentokens[i][0]+1 : rentokens[i][1]]) i += 1 + # Process each token. Work left to right so as not to mess up + # the previously stored indexes. + + rentokens.reverse() + + for r in rentokens: + + # Environment variable replacement token + + if r[2].startswith(TOKENENV): + r[2] = os.getenv(r[2][1:]) + + # Do the actual replacement + + renstring = renstring[:r[0]] + r[2] + renstring[r[1]+1:] + return renstring # End of '__ResolveRenameTokens()'