author | Richard Taylor <richard.i.taylor@nokia.com> |
Thu, 01 Apr 2010 11:47:09 +0100 | |
branch | wip |
changeset 451 | 153129bf777e |
parent 5 | 593a8820b912 |
child 452 | 80e69f7100f1 |
permissions | -rw-r--r-- |
5 | 1 |
# |
2 |
# Copyright (c) 2008-2009 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 |
# Example of a Filter class using the SAX parser base class |
|
16 |
# |
|
17 |
||
18 |
import filter_interface |
|
19 |
||
20 |
class FilterTagCounter(filter_interface.FilterSAX): |
|
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 | 30 |
def startDocument(self): |
31 |
# for each element name count the number of occurences |
|
32 |
# and the amount of body text contained. |
|
33 |
self.names = [] |
|
34 |
self.count = {} |
|
35 |
self.errors = 0 |
|
36 |
self.fatals = 0 |
|
37 |
self.warns = 0 |
|
38 |
||
39 |
def startElement(self, name, attributes): |
|
40 |
if name == "buildlog": |
|
41 |
# print out the attributes of the "top" element |
|
42 |
print "version:" |
|
43 |
for a,v in attributes.items(): |
|
44 |
print a, "=", v |
|
45 |
||
46 |
# push name onto the stack of names and increment the count |
|
47 |
self.names.append(name) |
|
48 |
if name in self.count: |
|
49 |
self.count[name][0] += 1 |
|
50 |
else: |
|
51 |
self.count[name] = [1, 0] # occurs, characters |
|
52 |
||
53 |
def characters(self, char): |
|
54 |
# these are for the current element |
|
55 |
current = self.names[-1] |
|
56 |
self.count[current][1] += len(char) |
|
57 |
||
58 |
def endElement(self, name): |
|
59 |
# pop the name off the stack |
|
60 |
self.names.pop() |
|
61 |
||
62 |
def endDocument(self): |
|
63 |
# report |
|
64 |
print "\nsummary:" |
|
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 | 68 |
|
69 |
print "\nparsing:" |
|
70 |
print "errors =", self.errors |
|
71 |
print "fatals =", self.fatals |
|
72 |
print "warnings =", self.warns |
|
73 |
||
74 |
def error(self, exception): |
|
75 |
self.errors += 1 |
|
76 |
||
77 |
def fatalError(self, exception): |
|
78 |
self.fatals += 1 |
|
79 |
||
80 |
def warning(self, exception): |
|
81 |
self.warns += 1 |
|
82 |
||
83 |
# the end |