diff --git a/tsshbatch.py b/tsshbatch.py index 98595c3..3bbd454 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -17,7 +17,7 @@ PROGNAME = "tsshbatch.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -CVSID = "$Id: tsshbatch.py,v 1.159 2013/10/24 18:53:35 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.160 2013/10/26 21:55:51 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" @@ -64,7 +64,6 @@ FAILURE = "FAILURE: %s" HOSTSEP = ":" HOSTNOISE = "[%s]" -INCLUDE = ".include" INDENTWIDTH = 8 OPTIONSLIST = "G:H:NP:Sef:hkn:p:yv" PADWIDTH = 12 @@ -97,6 +96,16 @@ " -v Display extended program version information\n" +\ " -y Turn on 'noisy' reporting for additional detail\n" +##### +# Directives & Related Support +##### + +ASSIGN = '=' +DEFINE = '.define' +INCLUDE = '.include' + +SymbolTable = {} + ##### # Error Messages @@ -106,6 +115,7 @@ eBADFILE = "Cannot open '%s'!" eBADSUDO = "sudo Failed (Check Password Or Command!) sudo Error Report: %s" eBADTXRQ = "Bad Transfer Request: %s Must Have Exactly 1 Source And 1 Destination!" +eBADDEFINE = "Bad Symbol Definition: %s" eFXERROR = "File Transfer Error: %s" eINCLUDECYCLE = "Circular Include At: %s" eNOCONNECT = "Cannot Connect To %s" @@ -376,6 +386,7 @@ # End of 'ProcessTXRQ' + ##### # Read File Handling Comments And Directives ##### @@ -394,14 +405,40 @@ try: f = open(filename) for line in f.readlines(): - line = ConditionLine(line) + + # Cleanup comments and whitespace - if line: + line = ConditionLine(line) + + # Process variable definitions + + if line.startswith(DEFINE): + + line = line.split(DEFINE)[1] + if line.count(ASSIGN) == 0: + ErrorExit(eBADDEFINE % line) + + else: + + name = line.split(ASSIGN)[0].strip() + val = "".join(line.split(ASSIGN)[1:]).strip() + + if name: + SymbolTable[name] = val + + else: + ErrorExit(eBADDEFINE % line) + + # Process file includes + elif line: if line.startswith(INCLUDE): fname = ConditionLine(line.split(INCLUDE)[1]) ReadFile(fname, listcontainer, containingfile=filename) else: + + for symbol in SymbolTable: + line = line.replace(symbol, SymbolTable[symbol]) listcontainer.append(line) f.close()