author | yiluzhu |
Tue, 25 May 2010 16:26:21 +0100 | |
branch | fix |
changeset 571 | 25e377052d9f |
parent 452 | 80e69f7100f1 |
permissions | -rw-r--r-- |
452
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
1 |
# |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
2 |
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
3 |
# All rights reserved. |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
4 |
# This component and the accompanying materials are made available |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
6 |
# which accompanies this distribution, and is available |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
8 |
# |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
9 |
# Initial Contributors: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
10 |
# Nokia Corporation - initial contribution. |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
11 |
# |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
12 |
# Contributors: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
13 |
# |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
14 |
# Description: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
15 |
# Filter class to print log entries for a selected component |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
16 |
# |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
17 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
18 |
import filter_interface |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
19 |
import sys |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
20 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
21 |
class FilterComp(filter_interface.FilterSAX): |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
22 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
23 |
def __init__(self, params = []): |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
24 |
"""parameters to this filter are the path of the bld.inf and some flags. |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
25 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
26 |
The bld.inf path can be a substring of the path to match. For example, |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
27 |
"email" will match an element with bldinf="y:/src/email/group/bld.inf". |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
28 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
29 |
No flags are supported yet; this is for future expansion. |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
30 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
31 |
If no parameters are passed then nothing is printed.""" |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
32 |
self.bldinf = "" |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
33 |
self.flags = "" |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
34 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
35 |
if len(params) > 0: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
36 |
self.bldinf = params[0] |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
37 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
38 |
if len(params) > 1: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
39 |
self.flags = params[1] |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
40 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
41 |
super(FilterComp, self).__init__() |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
42 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
43 |
def startDocument(self): |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
44 |
# mark when we are inside an element with bldinf="the selected one" |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
45 |
self.inside = False |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
46 |
# and count nested elements so we can toggle off at the end. |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
47 |
self.nesting = 0 |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
48 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
49 |
def printElementStart(self, name, attributes): |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
50 |
sys.stdout.write("<" + name) |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
51 |
for att,val in attributes.items(): |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
52 |
sys.stdout.write(" " + att + "='" + val + "'") |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
53 |
sys.stdout.write(">") |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
54 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
55 |
def startElement(self, name, attributes): |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
56 |
if self.inside: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
57 |
self.nesting += 1 |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
58 |
self.printElementStart(name, attributes) |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
59 |
return |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
60 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
61 |
if self.bldinf: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
62 |
try: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
63 |
if self.bldinf in attributes["bldinf"]: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
64 |
self.inside = True |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
65 |
self.nesting = 1 |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
66 |
self.printElementStart(name, attributes) |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
67 |
except KeyError: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
68 |
pass |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
69 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
70 |
def characters(self, char): |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
71 |
if self.inside: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
72 |
sys.stdout.write(char) |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
73 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
74 |
def endElement(self, name): |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
75 |
if self.inside: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
76 |
sys.stdout.write("</" + name + ">") |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
77 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
78 |
self.nesting -= 1 |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
79 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
80 |
if self.nesting == 0: |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
81 |
self.inside = False |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
82 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
83 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
84 |
def endDocument(self): |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
85 |
pass |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
86 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
87 |
def error(self, exception): |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
88 |
print filter_interface.Filter.formatError("FilterComp:" + str(exception)) |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
89 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
90 |
def fatalError(self, exception): |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
91 |
print filter_interface.Filter.formatError("FilterComp:" + str(exception)) |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
92 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
93 |
def warning(self, exception): |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
94 |
print filter_interface.Filter.formatWarning("FilterComp:" + str(exception)) |
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
95 |
|
80e69f7100f1
new FilterComp log filter
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
96 |
# the end |