author | yiluzhu |
Tue, 25 May 2010 16:26:21 +0100 | |
branch | fix |
changeset 571 | 25e377052d9f |
parent 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 |
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
|
28 |
|
5 | 29 |
def startDocument(self): |
30 |
# for each element name count the number of occurences |
|
31 |
# and the amount of body text contained. |
|
32 |
self.names = [] |
|
33 |
self.count = {} |
|
34 |
self.errors = 0 |
|
35 |
self.fatals = 0 |
|
36 |
self.warns = 0 |
|
37 |
||
38 |
def startElement(self, name, attributes): |
|
39 |
if name == "buildlog": |
|
40 |
# print out the attributes of the "top" element |
|
41 |
print "version:" |
|
42 |
for a,v in attributes.items(): |
|
43 |
print a, "=", v |
|
44 |
||
45 |
# push name onto the stack of names and increment the count |
|
46 |
self.names.append(name) |
|
47 |
if name in self.count: |
|
48 |
self.count[name][0] += 1 |
|
49 |
else: |
|
50 |
self.count[name] = [1, 0] # occurs, characters |
|
51 |
||
52 |
def characters(self, char): |
|
53 |
# these are for the current element |
|
54 |
current = self.names[-1] |
|
55 |
self.count[current][1] += len(char) |
|
56 |
||
57 |
def endElement(self, name): |
|
58 |
# pop the name off the stack |
|
59 |
self.names.pop() |
|
60 |
||
61 |
def endDocument(self): |
|
62 |
# report |
|
63 |
print "\nsummary:" |
|
64 |
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
|
65 |
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
|
66 |
print name, nos[0], nos[1] |
5 | 67 |
|
68 |
print "\nparsing:" |
|
69 |
print "errors =", self.errors |
|
70 |
print "fatals =", self.fatals |
|
71 |
print "warnings =", self.warns |
|
72 |
||
73 |
def error(self, exception): |
|
74 |
self.errors += 1 |
|
75 |
||
76 |
def fatalError(self, exception): |
|
77 |
self.fatals += 1 |
|
78 |
||
79 |
def warning(self, exception): |
|
80 |
self.warns += 1 |
|
81 |
||
82 |
# the end |