new FilterComp log filter wip
authorRichard Taylor <richard.i.taylor@nokia.com>
Thu, 01 Apr 2010 16:05:35 +0100
branchwip
changeset 452 80e69f7100f1
parent 451 153129bf777e
child 453 aa590b420880
new FilterComp log filter
sbsv2/raptor/python/plugins/filter_component.py
sbsv2/raptor/python/plugins/filter_tagcount.py
sbsv2/raptor/test/smoke_suite/filter_params.py
sbsv2/raptor/test/smoke_suite/test_resources/logexamples/filter_component.log
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sbsv2/raptor/python/plugins/filter_component.py	Thu Apr 01 16:05:35 2010 +0100
@@ -0,0 +1,96 @@
+#
+# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+# All rights reserved.
+# This component and the accompanying materials are made available
+# under the terms of the License "Eclipse Public License v1.0"
+# which accompanies this distribution, and is available
+# at the URL "http://www.eclipse.org/legal/epl-v10.html".
+#
+# Initial Contributors:
+# Nokia Corporation - initial contribution.
+#
+# Contributors:
+#
+# Description: 
+# Filter class to print log entries for a selected component
+#
+
+import filter_interface
+import sys
+
+class FilterComp(filter_interface.FilterSAX):
+	
+	def __init__(self, params = []):
+		"""parameters to this filter are the path of the bld.inf and some flags.
+		
+		The bld.inf path can be a substring of the path to match. For example,
+		"email" will match an element with bldinf="y:/src/email/group/bld.inf".
+		
+		No flags are supported yet; this is for future expansion.
+			
+		If no parameters are passed then nothing is printed."""
+		self.bldinf = ""
+		self.flags = ""
+		
+		if len(params) > 0:
+			self.bldinf = params[0]
+			
+		if len(params) > 1:
+			self.flags = params[1]
+		
+		super(FilterComp, self).__init__()
+		
+	def startDocument(self):
+		# mark when we are inside an element with bldinf="the selected one"
+		self.inside = False
+		# and count nested elements so we can toggle off at the end.
+		self.nesting = 0
+	
+	def printElementStart(self, name, attributes):
+		sys.stdout.write("<" + name)
+		for att,val in attributes.items():
+			sys.stdout.write(" " + att + "='" + val + "'")
+		sys.stdout.write(">")
+		
+	def startElement(self, name, attributes):
+		if self.inside:
+			self.nesting += 1
+			self.printElementStart(name, attributes)
+			return
+		
+		if self.bldinf:
+			try:
+				if self.bldinf in attributes["bldinf"]:
+					self.inside = True
+					self.nesting = 1
+					self.printElementStart(name, attributes)
+			except KeyError:
+				pass
+			
+	def characters(self, char):
+		if self.inside:
+			sys.stdout.write(char)
+		
+	def endElement(self, name):
+		if self.inside:
+			sys.stdout.write("</" + name + ">")
+			
+		self.nesting -= 1
+		
+		if self.nesting == 0:
+			self.inside = False
+			print
+	
+	def endDocument(self):
+		pass
+	
+	def error(self, exception):
+		print filter_interface.Filter.formatError("FilterComp:" + str(exception))
+		
+	def fatalError(self, exception):
+		print filter_interface.Filter.formatError("FilterComp:" + str(exception))
+		
+	def warning(self, exception):
+		print filter_interface.Filter.formatWarning("FilterComp:" + str(exception))
+	
+# the end
--- a/sbsv2/raptor/python/plugins/filter_tagcount.py	Thu Apr 01 11:47:09 2010 +0100
+++ b/sbsv2/raptor/python/plugins/filter_tagcount.py	Thu Apr 01 16:05:35 2010 +0100
@@ -24,7 +24,6 @@
 		
 		If no parameters are passed then all tags are reported."""
 		self.interesting = params
-		print "counting : ", str(params)
 		super(FilterTagCounter, self).__init__()
 		
 	def startDocument(self):
--- a/sbsv2/raptor/test/smoke_suite/filter_params.py	Thu Apr 01 11:47:09 2010 +0100
+++ b/sbsv2/raptor/test/smoke_suite/filter_params.py	Thu Apr 01 16:05:35 2010 +0100
@@ -72,6 +72,69 @@
 	t.command = command + "FilterTagCounter[info,clean],FilterTagCounter[info,clean]"
 	t.run()
 	
+	
+	# parameters must work with the sbs_filter script as well
+	
+	command = "sbs_filter --filters=%s < smoke_suite/test_resources/logexamples/filter_component.log"
+	t.logfileOption = lambda :""
+	t.makefileOption = lambda :""
+
+	# should still work with no parameters
+	t.name = "sbs_filter_no_params"
+	t.command = command % "FilterComp"
+	t.mustmatch_singleline = [
+		]
+	t.mustnotmatch_singleline = [
+		"[<>]" # no elements should be printed at all as no bld.inf is selected
+		]
+	t.run()
+	
+	# should work with an empty parameter list
+	t.name = "sbs_filter_no_params2"
+	t.command = command % "FilterComp[]"
+	t.run()
+	
+	# with a parameter
+	t.name = "sbs_filter_one_param"
+	t.command = command % "FilterComp[email]"
+	t.stdout = [
+		"<error bldinf='y:/src/email/bld.inf'>email error #1</error>",
+		"<error bldinf='y:/src/email/bld.inf'>email error #2</error>",
+		"<warning bldinf='y:/src/email/bld.inf'>email warning #1</warning>",
+		"<warning bldinf='y:/src/email/bld.inf'>email warning #2</warning>",
+		"<whatlog bldinf='y:/src/email/bld.inf' config='armv5_urel' mmp='y:/src/email/a.mmp'>",
+		"<build>/epoc32/data/email_1</build>",
+		"<build>/epoc32/data/email_2</build>",
+		"</whatlog>",
+		"<recipe bldinf='y:/src/email/bld.inf' name='dummy'>",
+		"+ make_email",
+		"email was made fine",
+		"<status exit='ok'></status>",
+		"</recipe>",
+		"<fake bldinf='y:src/email/bld.inf'>",
+		"  <foo>",
+		"   <bar>",
+		"     <fb>fb email</fb>",
+		"   </bar>",
+		" </foo>",
+		"</fake>"
+		]
+	t.mustmatch_singleline = []
+	t.mustnotmatch_singleline = []
+	t.warnings = 2
+	t.errors = 2
+	t.run()
+	
+	# with multiple filters
+	t.name = "sbs_filter_multi"
+	t.command = command % "FilterComp[txt],FilterTagCounter[file,recipe]"
+	t.stdout = []
+	t.mustmatch_singleline = [ "txt", "^file \d+", "^recipe \d+" ]
+	t.mustnotmatch_singleline = [ "email" ]
+	t.warnings = 2
+	t.errors = 0
+	t.run()
+	
 	t.name = "filter_params"
 	t.print_result()
 	return t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sbsv2/raptor/test/smoke_suite/test_resources/logexamples/filter_component.log	Thu Apr 01 16:05:35 2010 +0100
@@ -0,0 +1,42 @@
+<buildlog>
+
+<error bldinf="y:/src/email/bld.inf">email error #1</error>
+<error bldinf="y:/src/email/bld.inf">email error #2</error>
+
+<warning bldinf="y:/src/txt/bld.inf">txt warning #1</warning>
+<warning bldinf="y:/src/txt/bld.inf">txt warning #2</warning>
+
+<warning bldinf="y:/src/email/bld.inf">email warning #1</warning>
+<warning bldinf="y:/src/email/bld.inf">email warning #2</warning>
+
+<whatlog bldinf='y:/src/email/bld.inf' mmp='y:/src/email/a.mmp' config='armv5_urel'>
+<build>/epoc32/data/email_1</build>
+<build>/epoc32/data/email_2</build>
+</whatlog>
+
+<clean bldinf='y:/src/txt/bld.inf' mmp='y:/src/txt/b.mmp' config='armv5_udeb'>
+<file>/epoc32/data/txt_1</file>
+<file>/epoc32/data/txt_2</file>
+</clean>
+
+<recipe name='dummy' bldinf='y:/src/txt/bld.inf'>
++ make_txt
+txt was made fine
+<status exit='ok'/>
+</recipe>
+
+<recipe name='dummy' bldinf='y:/src/email/bld.inf'>
++ make_email
+email was made fine
+<status exit='ok'/>
+</recipe>
+
+<fake bldinf='y:src/email/bld.inf'>
+  <foo>
+    <bar>
+      <fb>fb email</fb>
+    </bar>
+  </foo>
+</fake>
+
+</buildlog>
\ No newline at end of file