diff --git a/tsshbatch.py b/tsshbatch.py index a01c688..f9a0dbe 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.156 2013/10/23 22:22:26 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.157 2013/10/24 02:19:42 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" @@ -63,6 +63,7 @@ CONSUCCESS = "SUCCESS: Connection Established" FAILURE = "FAILURE: %s" HOSTSEP = ":" +INCLUDE = ".include" INDENTWIDTH = 8 OPTIONSLIST = "G:H:NP:Sef:hkn:p:v" PADWIDTH = 12 @@ -103,6 +104,7 @@ eBADSUDO = "sudo Failed (Check Password Or Command!) sudo Error Report: %s" eBADTXRQ = "Bad Transfer Request: %s Must Have Exactly 1 Source And 1 Destination!" eFXERROR = "File Transfer Error: %s" +eINCLUDECYCLE = "Circular Include At: %s" eNOCONNECT = "Cannot Connect To %s" eNOHOSTS = "No Hosts Specified!" eNOLOGIN = "Cannot Login! (Login/Password Bad?)" @@ -125,6 +127,29 @@ ##### +# Options That Can Be Overriden By User +#### + +GETSUDOPW = False # Prompt for sudo password +HOSTS = [] # List of hosts to target +KEYEXCHANGE = False # Do key exchange-based auth? +PROMPTUSERNAME = False # Don't use $USER, prompt for username +PWORD = "" # Password +REPORTERR = True # Report stderr output from remote host +UNAME = "" # Login name + + +##### +# Global Data Structures +##### + +Commands = [] +FileIncludeStack = [] +Get_Transfer_List = {} +Put_Transfer_List = {} + + +##### # Functions ##### @@ -165,7 +190,7 @@ def ErrorExit(msg): PrintStderr(msg) - sys.exit(1) + os._exit(1) # End Of 'ErrorExit()' @@ -341,18 +366,35 @@ # End of 'ProcessTXRQ' ##### -# Read File Handling Comments And Metacommands +# Read File Handling Comments And Directives ##### -def ReadFile(filename, listcontainer): +def ReadFile(filename, listcontainer, containingfile=""): + + # Make sure we don't have a cyclic include reference + + filename = os.path.realpath(filename) + if filename in FileIncludeStack: + ErrorExit(eINCLUDECYCLE % containingfile + SEPARATOR + filename) + + else: + FileIncludeStack.append(filename) # Push it on to the stack history + try: f = open(filename) for line in f.readlines(): line = ConditionLine(line) + if line: - listcontainer.append(line) + if line.startswith(INCLUDE): + fname = ConditionLine(line.split(INCLUDE)[1]) + ReadFile(fname, listcontainer, containingfile=filename) + + else: + listcontainer.append(line) f.close() + FileIncludeStack.pop() # Remove this invocation from the stack return listcontainer except: @@ -367,22 +409,6 @@ # Process Any Options User Set In The Environment Or On Command Line ##### -# Options that can be overriden by user - -GETSUDOPW = False # Prompt for sudo password -HOSTS = [] # List of hosts to target -KEYEXCHANGE = False # Do key exchange-based auth? -PROMPTUSERNAME = False # Don't use $USER, prompt for username -PWORD = "" # Password -REPORTERR = True # Report stderr output from remote host -UNAME = "" # Login name - -# Data Structures - -Commands = [] -Put_Transfer_List = {} -Get_Transfer_List = {} - # Handle any options set in the environment OPTIONS = sys.argv[1:]