|
1 # |
|
2 # Copyright (c) 2010 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 # Filter class to print log entries for a selected component |
|
16 # |
|
17 |
|
18 import filter_interface |
|
19 import sys |
|
20 |
|
21 class FilterComp(filter_interface.FilterSAX): |
|
22 |
|
23 def __init__(self, params = []): |
|
24 """parameters to this filter are the path of the bld.inf and some flags. |
|
25 |
|
26 The bld.inf path can be a substring of the path to match. For example, |
|
27 "email" will match an element with bldinf="y:/src/email/group/bld.inf". |
|
28 |
|
29 No flags are supported yet; this is for future expansion. |
|
30 |
|
31 If no parameters are passed then nothing is printed.""" |
|
32 self.bldinf = "" |
|
33 self.flags = "" |
|
34 |
|
35 if len(params) > 0: |
|
36 self.bldinf = params[0] |
|
37 |
|
38 if len(params) > 1: |
|
39 self.flags = params[1] |
|
40 |
|
41 super(FilterComp, self).__init__() |
|
42 |
|
43 def startDocument(self): |
|
44 # mark when we are inside an element with bldinf="the selected one" |
|
45 self.inside = False |
|
46 # and count nested elements so we can toggle off at the end. |
|
47 self.nesting = 0 |
|
48 |
|
49 def printElementStart(self, name, attributes): |
|
50 sys.stdout.write("<" + name) |
|
51 for att,val in attributes.items(): |
|
52 sys.stdout.write(" " + att + "='" + val + "'") |
|
53 sys.stdout.write(">") |
|
54 |
|
55 def startElement(self, name, attributes): |
|
56 if self.inside: |
|
57 self.nesting += 1 |
|
58 self.printElementStart(name, attributes) |
|
59 return |
|
60 |
|
61 if self.bldinf: |
|
62 try: |
|
63 if self.bldinf in attributes["bldinf"]: |
|
64 self.inside = True |
|
65 self.nesting = 1 |
|
66 self.printElementStart(name, attributes) |
|
67 except KeyError: |
|
68 pass |
|
69 |
|
70 def characters(self, char): |
|
71 if self.inside: |
|
72 sys.stdout.write(char) |
|
73 |
|
74 def endElement(self, name): |
|
75 if self.inside: |
|
76 sys.stdout.write("</" + name + ">") |
|
77 |
|
78 self.nesting -= 1 |
|
79 |
|
80 if self.nesting == 0: |
|
81 self.inside = False |
|
82 print |
|
83 |
|
84 def endDocument(self): |
|
85 pass |
|
86 |
|
87 def error(self, exception): |
|
88 print filter_interface.Filter.formatError("FilterComp:" + str(exception)) |
|
89 |
|
90 def fatalError(self, exception): |
|
91 print filter_interface.Filter.formatError("FilterComp:" + str(exception)) |
|
92 |
|
93 def warning(self, exception): |
|
94 print filter_interface.Filter.formatWarning("FilterComp:" + str(exception)) |
|
95 |
|
96 # the end |