catch up wip
authorRichard Taylor <richard.i.taylor@nokia.com>
Tue, 06 Apr 2010 10:03:18 +0100
branchwip
changeset 454 9de4f2d59255
parent 453 aa590b420880 (diff)
parent 450 63f3bc391c14 (current diff)
child 455 6cc6d1d59188
catch up
--- a/sbsv2/raptor/bin/sbs_filter.py	Thu Apr 01 15:50:33 2010 +0100
+++ b/sbsv2/raptor/bin/sbs_filter.py	Tue Apr 06 10:03:18 2010 +0100
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+# 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 "Symbian Foundation License v1.0"
@@ -58,7 +58,7 @@
 	raptor_params = raptor.BuildStats(the_raptor)
 
 	# Open the requested plugins using the pluginbox
-	the_raptor.out.open(raptor_params, the_raptor.filterList.split(','), pbox)
+	the_raptor.out.open(raptor_params, the_raptor.filterList, pbox)
 	
 except Exception, e:
 	sys.stderr.write("error: problem while creating filters %s\n" % str(e))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sbsv2/raptor/notes/parametric_log_filters.txt	Tue Apr 06 10:03:18 2010 +0100
@@ -0,0 +1,31 @@
+
+It is now possible to pass parameters from the command line into log filters.
+This works in the same way for both sbs and sbs_filter commands.
+
+For example:
+
+sbs --filters=Foo[param1,param2,param3]
+
+sbs_filter --filters=Bar[value] < build.log
+
+
+Multiple filters with parameters can be specified if needed,
+
+sbs --filters=Foo[param1,param2,param3],Bar[value]
+
+
+In the 2.13.0 release there are two filters which take parameters:
+
+1. sbs_filter --filters=FilterComp[wizard/group] < log
+
+Here the parameter is (part of) a bld.inf path and the filter only prints
+parts of the log which are attributable to the matching component. In the
+example above, the log elements from any bld.inf which has "wizard/group" 
+as part of its path will be printed: normally, passing the full path name
+will guarantee that only one component matches.
+
+2. sbs_filter --filters=FilterTagCounter[info,recipe] < log
+
+Here the parameters are a list of the element names to count. This is a
+simple analysis filter that shows you how many instances of XMl elements
+are in a log and how many characters of body text they have.
\ No newline at end of file
--- a/sbsv2/raptor/python/filter_list.py	Thu Apr 01 15:50:33 2010 +0100
+++ b/sbsv2/raptor/python/filter_list.py	Tue Apr 06 10:03:18 2010 +0100
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+# Copyright (c) 2008-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"
@@ -19,6 +19,7 @@
 import os
 import sys
 import raptor
+import re
 import filter_interface
 import pluginbox
 import traceback
@@ -64,8 +65,24 @@
 		"""Nothing to do for stdout"""
 		return True
 
-
-
+def SplitList(listString):
+	"""turn a CLI filter string into a list of (class, param) pairs.
+	
+	for example, "foo[a,b],bar[c,d]"
+	
+	becomes [ ("foo", ["a","b"]) , ("bar", ["c","d"]) ]
+	"""
+	matches = re.findall("(\w+)(\[([^\[\]]*)\])?,?", listString)
+	
+	pairs = []
+	for m in matches:
+		classname = m[0]
+		if len(m[2]) > 0:
+			pairs.append( (classname, m[2].split(",")) )
+		else:
+			pairs.append( (classname, []) )
+	return pairs
+	
 class FilterList(filter_interface.Filter):
 
 	def __init__(self):
@@ -81,13 +98,19 @@
 		# Find all the filter plugins
 		self.pbox = pbox
 		possiblefilters = self.pbox.classesof(filter_interface.Filter)
+		# turn "filternames" into a list of (classname, parameters) pairs
+		filterCalls = SplitList(filternames)
+		# look for each filter class in the box
 		unfound = []
 		self.filters = []
-		for f in filternames:
+		for (f, params) in filterCalls:
 			unfound.append(f) # unfound unless we find it
 			for pl in possiblefilters:
 				if pl.__name__.upper() == f.upper():
-					self.filters.append(pl())
+					if params:
+						self.filters.append(pl(params))
+					else:
+						self.filters.append(pl())
 					unfound = unfound[:-1]
 		if unfound != []:
 			raise ValueError("requested filters not found: %s \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sbsv2/raptor/python/plugins/filter_component.py	Tue Apr 06 10:03:18 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 15:50:33 2010 +0100
+++ b/sbsv2/raptor/python/plugins/filter_tagcount.py	Tue Apr 06 10:03:18 2010 +0100
@@ -19,6 +19,13 @@
 
 class FilterTagCounter(filter_interface.FilterSAX):
 	
+	def __init__(self, params = []):
+		"""parameters to this filter are the names of tags to print.
+		
+		If no parameters are passed then all tags are reported."""
+		self.interesting = params
+		super(FilterTagCounter, self).__init__()
+		
 	def startDocument(self):
 		# for each element name count the number of occurences
 		# and the amount of body text contained.
@@ -55,7 +62,8 @@
 		# report
 		print "\nsummary:"
 		for name,nos in sorted(self.count.items()):
-			print name, nos[0], nos[1]
+			if name in self.interesting or len(self.interesting) == 0:
+				print name, nos[0], nos[1]
 			
 		print "\nparsing:"
 		print "errors =", self.errors
--- a/sbsv2/raptor/python/raptor.py	Thu Apr 01 15:50:33 2010 +0100
+++ b/sbsv2/raptor/python/raptor.py	Tue Apr 06 10:03:18 2010 +0100
@@ -1096,7 +1096,7 @@
 			self.raptor_params = BuildStats(self)
 
 			# Open the requested plugins using the pluginbox
-			self.out.open(self.raptor_params, self.filterList.split(','), self.pbox)
+			self.out.open(self.raptor_params, self.filterList, self.pbox)
 
 			# log header
 			self.out.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sbsv2/raptor/test/smoke_suite/filter_params.py	Tue Apr 06 10:03:18 2010 +0100
@@ -0,0 +1,140 @@
+#
+# 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: 
+#
+
+from raptor_tests import SmokeTest
+
+def run():
+	
+	t = SmokeTest()
+	t.description = "Test the passing of parameters to log filters"
+	
+	command = "sbs -b smoke_suite/test_resources/simple/bld.inf -c armv5_urel --filters="
+	
+	# no parameters means count all tags	
+	t.name = "filter_params_all_tags"
+	t.command = command + "FilterTagCounter"
+	t.mustmatch_singleline = [
+		"^info \d+ \d+",
+		"^whatlog \d+ \d+",
+		"^clean \d+ \d+"	
+		]
+	t.run()
+	
+	# empty parameter lists are valid
+	t.name = "filter_params_all_tags2"
+	t.command = command + "FilterTagCounter[]"
+	t.run()
+	
+	# parameters mean report only those tags	
+	t.name = "filter_params_info"
+	t.command = command + "FilterTagCounter[info]"
+	t.mustmatch_singleline = [
+		"^info \d+ \d+"
+		]
+	t.mustnotmatch_singleline = [
+		"^whatlog \d+ \d+",
+		"^clean \d+ \d+"	
+		]
+	t.run()
+	
+	# multiple parameters are valid	
+	t.name = "filter_params_info_clean"
+	t.command = command + "FilterTagCounter[info,clean]"
+	t.mustmatch_singleline = [
+		"^info \d+ \d+",
+		"^clean \d+ \d+"
+		]
+	t.mustnotmatch_singleline = [
+		"^whatlog \d+ \d+"
+		]
+	t.run()
+	
+	# using the same filter with different parameters is valid
+	t.name = "filter_params_info_clean2"
+	t.command = command + "FilterTagCounter[info],FilterTagCounter[clean]"
+	t.run()
+	
+	# using the same filter with the same parameters is valid too
+	t.name = "filter_params_info_clean3"
+	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	Tue Apr 06 10:03:18 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