sbsv2/raptor/python/plugins/filter_tagcount.py
author Richard Taylor <richard.i.taylor@nokia.com>
Thu, 01 Apr 2010 11:47:09 +0100
branchwip
changeset 451 153129bf777e
parent 5 593a8820b912
child 452 80e69f7100f1
permissions -rw-r--r--
pass optional parameters to log filters from the command line
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     1
#
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     2
# Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     3
# All rights reserved.
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     4
# This component and the accompanying materials are made available
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     6
# which accompanies this distribution, and is available
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     8
#
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
     9
# Initial Contributors:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    11
#
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    12
# Contributors:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    13
#
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    14
# Description: 
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    15
# Example of a Filter class using the SAX parser base class
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    16
#
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    17
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    18
import filter_interface
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    19
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    20
class FilterTagCounter(filter_interface.FilterSAX):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    21
	
451
153129bf777e pass optional parameters to log filters from the command line
Richard Taylor <richard.i.taylor@nokia.com>
parents: 5
diff changeset
    22
	def __init__(self, params = []):
153129bf777e pass optional parameters to log filters from the command line
Richard Taylor <richard.i.taylor@nokia.com>
parents: 5
diff changeset
    23
		"""parameters to this filter are the names of tags to print.
153129bf777e pass optional parameters to log filters from the command line
Richard Taylor <richard.i.taylor@nokia.com>
parents: 5
diff changeset
    24
		
153129bf777e pass optional parameters to log filters from the command line
Richard Taylor <richard.i.taylor@nokia.com>
parents: 5
diff changeset
    25
		If no parameters are passed then all tags are reported."""
153129bf777e pass optional parameters to log filters from the command line
Richard Taylor <richard.i.taylor@nokia.com>
parents: 5
diff changeset
    26
		self.interesting = params
153129bf777e pass optional parameters to log filters from the command line
Richard Taylor <richard.i.taylor@nokia.com>
parents: 5
diff changeset
    27
		print "counting : ", str(params)
153129bf777e pass optional parameters to log filters from the command line
Richard Taylor <richard.i.taylor@nokia.com>
parents: 5
diff changeset
    28
		super(FilterTagCounter, self).__init__()
153129bf777e pass optional parameters to log filters from the command line
Richard Taylor <richard.i.taylor@nokia.com>
parents: 5
diff changeset
    29
		
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    30
	def startDocument(self):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    31
		# for each element name count the number of occurences
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    32
		# and the amount of body text contained.
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    33
		self.names = []
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    34
		self.count = {}
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    35
		self.errors = 0
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    36
		self.fatals = 0
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    37
		self.warns = 0
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    38
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    39
	def startElement(self, name, attributes):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    40
		if name == "buildlog":
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    41
			# print out the attributes of the "top" element
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    42
			print "version:"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    43
			for a,v in attributes.items():
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    44
				print a, "=", v
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    45
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    46
		# push name onto the stack of names and increment the count
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    47
		self.names.append(name)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    48
		if name in self.count:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    49
			self.count[name][0] += 1
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    50
		else:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    51
			self.count[name] = [1, 0]    # occurs, characters	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    52
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    53
	def characters(self, char):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    54
		# these are for the current element
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    55
		current = self.names[-1]
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    56
		self.count[current][1] += len(char)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    57
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    58
	def endElement(self, name):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    59
		# pop the name off the stack
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    60
		self.names.pop()
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    61
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    62
	def endDocument(self):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    63
		# report
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    64
		print "\nsummary:"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    65
		for name,nos in sorted(self.count.items()):
451
153129bf777e pass optional parameters to log filters from the command line
Richard Taylor <richard.i.taylor@nokia.com>
parents: 5
diff changeset
    66
			if name in self.interesting or len(self.interesting) == 0:
153129bf777e pass optional parameters to log filters from the command line
Richard Taylor <richard.i.taylor@nokia.com>
parents: 5
diff changeset
    67
				print name, nos[0], nos[1]
5
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    68
			
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    69
		print "\nparsing:"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    70
		print "errors =", self.errors
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    71
		print "fatals =", self.fatals
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    72
		print "warnings =", self.warns
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    73
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    74
	def error(self, exception):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    75
		self.errors += 1
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    76
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    77
	def fatalError(self, exception):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    78
		self.fatals += 1
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    79
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    80
	def warning(self, exception):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    81
		self.warns += 1
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    82
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    83
# the end