sbsv2/raptor/test/smoke_suite/test_resources/annofile2log/testanno2log.py
branchfix
changeset 362 0ff20a0b1aa9
parent 357 b4baa7ca35a7
child 490 b60bdff41580
equal deleted inserted replaced
361:e17a12b3db40 362:0ff20a0b1aa9
       
     1 #
       
     2 # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 # Component description file
       
    16 #
       
    17 
       
    18 
     1 import sys
    19 import sys
     2 import os
    20 import os
     3 sys.path.append(os.path.join(os.environ['SBS_HOME'],"python"))
    21 sys.path.append(os.path.join(os.environ['SBS_HOME'],"python"))
     4 from xml.sax.saxutils import escape
       
     5 from xml.sax.saxutils import unescape
       
     6 
    22 
     7 def XMLEscapeLog(stream):
    23 from raptor_make import XMLEscapeLog
     8 	inRecipe = False
    24 from raptor_make import AnnoFileParseOutput
     9 
       
    10 	for line in stream:
       
    11 		if line.startswith("<recipe"):
       
    12 			inRecipe = True
       
    13 		elif line.startswith("</recipe"):
       
    14 			inRecipe = False
       
    15 			
       
    16 		# unless we are inside a "recipe", any line not starting
       
    17 		# with "<" is free text that must be escaped.
       
    18 		if inRecipe or line.startswith("<"):
       
    19 			yield line
       
    20 		else:
       
    21 			yield escape(line)
       
    22 
       
    23 def AnnoFileParseOutput(annofile):
       
    24 	af = open(annofile, "r")
       
    25 
       
    26 	inOutput = False
       
    27 	inParseJob = False
       
    28 	for line in af:
       
    29 		line = line.rstrip("\n\r")
       
    30 
       
    31 		if not inOutput:
       
    32 			if line.startswith("<output>"):
       
    33 				inOutput = True	
       
    34 				yield unescape(line[8:])
       
    35 				# This is make output so don't unescape it.
       
    36 			elif line.startswith('<output src="prog">'):
       
    37 				line = line[19:]
       
    38 				inOutput = True	
       
    39 				yield unescape(line)
       
    40 		else:
       
    41 			end_output = line.find("</output>")
       
    42 		
       
    43 			if end_output != -1:
       
    44 				line = line[:end_output]
       
    45 				inOutput = False
       
    46 			
       
    47 			yield unescape(line)
       
    48 
       
    49 	af.close()
       
    50 
    25 
    51 
    26 
    52 retcode=0
    27 retcode=0
    53 
    28 
    54 
    29 
    55 annofile = sys.argv[1]
    30 annofile = sys.argv[1]
    56 #print "File = ", annofile
       
    57 
    31 
    58 sys.stdout.write("<build>\n")
    32 sys.stdout.write("<build>\n")
    59 try:
    33 try:
    60 	for l in XMLEscapeLog(AnnoFileParseOutput(annofile)):
    34 	for l in XMLEscapeLog(AnnoFileParseOutput(annofile)):
    61 		sys.stdout.write(l+"\n")
    35 		sys.stdout.write(l)
    62 
    36 
    63 except Exception,e:
    37 except Exception,e:
    64 	sys.stderr.write("error: " + str(e) + "\n")
    38 	sys.stderr.write("error: " + str(e) + "\n")
    65 	retcode = 1
    39 	retcode = 1
    66 sys.stdout.write("</build>\n")
    40 sys.stdout.write("</build>\n")