sbsv2/raptor/python/plugins/filter_tagcount.py
author timothy.murphy@nokia.com
Fri, 12 Feb 2010 14:57:02 +0200
branchfix
changeset 204 a19456c07783
parent 5 593a8820b912
child 451 153129bf777e
permissions -rw-r--r--
fix: failure of make engine test when a make engine alias contains a modifier. There can be more than one variant per alias via "." e.g. make.extrastuff where make and extrastuff are variants.
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
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    22
	def startDocument(self):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    23
		# for each element name count the number of occurences
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    24
		# and the amount of body text contained.
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    25
		self.names = []
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    26
		self.count = {}
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    27
		self.errors = 0
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    28
		self.fatals = 0
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    29
		self.warns = 0
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    30
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    31
	def startElement(self, name, attributes):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    32
		if name == "buildlog":
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    33
			# print out the attributes of the "top" element
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    34
			print "version:"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    35
			for a,v in attributes.items():
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    36
				print a, "=", v
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    37
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    38
		# push name onto the stack of names and increment the count
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    39
		self.names.append(name)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    40
		if name in self.count:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    41
			self.count[name][0] += 1
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    42
		else:
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    43
			self.count[name] = [1, 0]    # occurs, characters	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    44
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    45
	def characters(self, char):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    46
		# these are for the current element
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    47
		current = self.names[-1]
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    48
		self.count[current][1] += len(char)
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    49
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    50
	def endElement(self, name):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    51
		# pop the name off the stack
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    52
		self.names.pop()
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    53
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    54
	def endDocument(self):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    55
		# report
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    56
		print "\nsummary:"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    57
		for name,nos in sorted(self.count.items()):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    58
			print name, nos[0], nos[1]
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    59
			
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    60
		print "\nparsing:"
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    61
		print "errors =", self.errors
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    62
		print "fatals =", self.fatals
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    63
		print "warnings =", self.warns
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    64
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    65
	def error(self, exception):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    66
		self.errors += 1
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    67
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    68
	def fatalError(self, exception):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    69
		self.fatals += 1
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    70
		
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    71
	def warning(self, exception):
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    72
		self.warns += 1
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    73
	
593a8820b912 Team Wip branch
tnmurphy@4GBL06592.nokia.com
parents:
diff changeset
    74
# the end