#! python: #w#VIC redirect.py module # # Copyright 2002, 2003 by Timothy Rue <3seas@threeseas.net> # # VIC redirect.py module: version 0.5.1.python (BETA) # # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation version 2 # of the License. http://www.gnu.org/copyleft/gpl.html # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Or access http://www.gnu.org/copyleft/gpl.html ########################################################################## #August 29, 2003 made file IQ parseable 0.5.1 #July 24, 2003 initial release 0.5 # ########################################################################## #s#system modules import string #s#def getAnyRedirection ### ### If we have a command like "cat < Doco/foo.txt" ### Could also have something like "cat < Doco/foo.txt > output.txt" ### read the content of the redirected input file (Doco/foo.txt) ### Otherwise return "" ### def getAnyRedirections(command_list): redirected_stdin = "" redirected_stdout_filename = "" output_command_list = [] error = 0 error_near = "" append = 0 for j in range(len(command_list)): command = command_list[j] if (string.count(command,">>") > 0): command,redirected_stdout_filename = string.split(command,">>",1) redirected_stdout_filename = string.strip(redirected_stdout_filename) try: infile = open(redirected_stdout_filename,"a") infile.close() except: error = 1 error_near = "Error appending to '"+redirected_stdout_filename+"'" append = 1 elif (string.count(command,">") > 0): command,redirected_stdout_filename = string.split(command,">",1) redirected_stdout_filename = string.strip(redirected_stdout_filename) try: infile = open(redirected_stdout_filename,"w") infile.close() except: error = 1 error_near = "Error writing to '"+redirected_stdout_filename+"'" elif (string.count(command,"<") > 0): command,infilename = string.split(command,"<",1) infilename = string.strip(infilename) try: infile = open(infilename,"r") redirected_stdin = infile.read() infile.close except: error = 1 error_near = "Error reading '"+infilename+"'" if (string.strip(command) != ""): output_command_list.append(command) return output_command_list,redirected_stdin,redirected_stdout_filename,append,error,error_near