625
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
1 |
#
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
2 |
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
3 |
# All rights reserved.
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
4 |
# This component and the accompanying materials are made available
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
6 |
# which accompanies this distribution, and is available
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
8 |
#
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
9 |
# Initial Contributors:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
10 |
# Nokia Corporation - initial contribution.
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
11 |
#
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
12 |
# Contributors:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
13 |
#
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
14 |
# Description:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
15 |
# Annofile class
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
16 |
#
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
17 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
18 |
import xml.sax
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
19 |
import os
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
20 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
21 |
class Annofile(xml.sax.handler.ContentHandler):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
22 |
"""A class to represent an emake anno file"""
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
23 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
24 |
def __init__(self, name, maxagents=30):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
25 |
self.name = name
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
26 |
self.overallAggregateTime = 0
|
641
|
27 |
self.duration = 0
|
625
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
28 |
self.inJob = False
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
29 |
self.inMetricDuration = False
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
30 |
self.jobType = ''
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
31 |
self.nodes = set()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
32 |
self.maxagents = maxagents
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
33 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
34 |
parser = xml.sax.make_parser()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
35 |
parser.setContentHandler(self)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
36 |
try:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
37 |
parser.parse(open(name))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
38 |
except xml.sax._exceptions.SAXParseException, e:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
39 |
print "Error:\n" + str(e)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
40 |
print "Ignore that file, parsing continues..."
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
41 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
42 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
43 |
def startElement(self, name, attrs):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
44 |
if name == 'build':
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
45 |
# attrs.get() returns unicode type
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
46 |
self.cm = attrs.get('cm', '')
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
47 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
48 |
elif name == 'job':
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
49 |
self.inJob = True
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
50 |
self.jobType = attrs.get('type', '')
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
51 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
52 |
elif name == 'timing':
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
53 |
# Find agent number
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
54 |
node = attrs.get('node')
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
55 |
if node not in self.nodes:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
56 |
self.nodes.add(node)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
57 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
58 |
# Calculate aggregate build time
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
59 |
# This is the sum of time spending on each node
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
60 |
# Ideally it equals the build time if there is
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
61 |
# only one node
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
62 |
time = float(attrs.get('completed')) \
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
63 |
- float(attrs.get('invoked'))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
64 |
self.overallAggregateTime += time
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
65 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
66 |
# Calculate parse time
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
67 |
if self.inJob and self.jobType == 'parse':
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
68 |
self.parseTime = time
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
69 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
70 |
elif name == 'metric':
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
71 |
if attrs.get('name') == 'duration':
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
72 |
self.inMetricDuration = True
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
73 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
74 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
75 |
def endElement(self, name):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
76 |
if name == 'job':
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
77 |
self.inJob = False
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
78 |
elif name == 'metric':
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
79 |
if self.inMetricDuration:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
80 |
self.inMetricDuration = False
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
81 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
82 |
# Parse to the end of XML file
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
83 |
elif name == 'build':
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
84 |
self.doFinal()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
85 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
86 |
def characters(self, ch):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
87 |
if self.inMetricDuration:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
88 |
self.duration = ch
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
89 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
90 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
91 |
# Get class attributes
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
92 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
93 |
def getParseTime(self):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
94 |
"""Get the time that emake spends on
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
95 |
parsing all makefiles
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
96 |
"""
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
97 |
return self.parseTime
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
98 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
99 |
def getOverallDuration(self):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
100 |
"""Get the overall build duration"""
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
101 |
return float(self.duration)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
102 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
103 |
def getClusterManager(self):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
104 |
return self.cm
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
105 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
106 |
def getAggregateTime(self):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
107 |
"""This is the sum of time spending on each node.
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
108 |
Ideally it equals the build time if there is
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
109 |
only one node
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
110 |
"""
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
111 |
return self.overallAggregateTime
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
112 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
113 |
# Calculate two efficiencies:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
114 |
# first includes makefile parse time; second doesn't
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
115 |
def getEfficiency(self):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
116 |
"""100% means all nodes are busy from start to finish.
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
117 |
"""
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
118 |
at = self.getAggregateTime()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
119 |
num = self.maxagents
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
120 |
d = self.getOverallDuration()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
121 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
122 |
idealDuration = at / num
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
123 |
if d != 0:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
124 |
efficiency = round(idealDuration / d, 3)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
125 |
else:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
126 |
efficiency = 0
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
127 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
128 |
# This is efficiency WITHOUT counting makefile
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
129 |
# parsing time. Tempararily still useful.
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
130 |
pt = self.getParseTime()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
131 |
idealD_wo = (at - pt) / num
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
132 |
if d != pt:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
133 |
e_wo = round(idealD_wo / (d - pt), 3)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
134 |
else:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
135 |
e_wo = 0
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
136 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
137 |
#return str(efficiency * 100) + '%', str(e_wo * 100) + '%'
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
138 |
return efficiency, e_wo
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
139 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
140 |
def doFinal(self):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
141 |
report = open('anno_report.xml', 'a')
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
142 |
report.write("<annofile name='%s'>\n" % self.name)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
143 |
report.write("<metric name='agentNumber' value='%s'/>\n" % len(self.nodes))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
144 |
report.write("<metric name='makefileParseTime' value='%s'/>\n" \
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
145 |
% self.getParseTime())
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
146 |
report.write("<metric name='duration' value='%s'/>\n" \
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
147 |
% self.getOverallDuration())
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
148 |
report.write("<metric name='aggregateTime' value='%s'/>\n" \
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
149 |
% self.getAggregateTime())
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
150 |
report.write("<metric name='efficiency' value='%f'/>\n" \
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
151 |
% self.getEfficiency()[0])
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
152 |
report.write("<metric name='efficiencyNoMakefile' value='%f'/>\n" \
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
153 |
% self.getEfficiency()[1])
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
154 |
report.write("</annofile>\n")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
155 |
report.close()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
156 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
157 |
def __str__(self):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
158 |
s = " <metric name='agentcount' value='%d' />\n" % len(self.nodes) + \
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
159 |
" <metric name='maxagents' value='%d' />\n" % self.maxagents + \
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
160 |
" <metric name='parsetimesecs' value='%s' />\n" % self.getParseTime() + \
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
161 |
" <metric name='overallduration' value='%s' />\n" % self.getOverallDuration() + \
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
162 |
" <metric name='aggregatetime' value='%s' />\n" % self.getAggregateTime() + \
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
163 |
" <metric name='efficiency' value='%s' />\n" % self.getEfficiency()[0] + \
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
164 |
" <metric name='efficiency_nomake' value='%s' />\n" % self.getEfficiency()[1]
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
165 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
166 |
return s
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
167 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
168 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
169 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
170 |
if __name__ == '__main__':
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
171 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
172 |
# Work around annoying DOCTYPE error by
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
173 |
# creating a dummy DTD file
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
174 |
if not os.path.exists('build.dtd'):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
175 |
dummy = open('build.dtd', 'w')
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
176 |
dummy.close()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
177 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
178 |
################## Edit this basepath ################
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
179 |
basepath = '92_7952_201022_logs\\output\\logs'
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
180 |
######################################################
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
181 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
182 |
# Find out all the annofiles
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
183 |
annofiles = []
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
184 |
for dirpath, dirs, files in os.walk(basepath):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
185 |
for f in files:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
186 |
if f.endswith('.anno') or f.endswith('.anno.xml'):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
187 |
annofiles.append(dirpath + '\\' + f)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
188 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
189 |
#print annofiles # debug
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
190 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
191 |
# Parse all the annofiles and generate report
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
192 |
# Write XML header
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
193 |
report = open('anno_report.xml', 'w')
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
194 |
report.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n')
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
195 |
report.write("<report>\n")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
196 |
report.close()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
197 |
# Parse each annofile
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
198 |
#num = 0 # debug
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
199 |
parser = xml.sax.make_parser()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
200 |
for afilename in annofiles:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
201 |
parser.setContentHandler(Annofile(afilename))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
202 |
try:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
203 |
parser.parse(open(afilename))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
204 |
except xml.sax._exceptions.SAXParseException, e:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
205 |
print "Error:\n" + str(e)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
206 |
print "Ignore that file, parsing continues..."
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
207 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
208 |
#num += 1 # <debug> only process num annofiles
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
209 |
#if num == 3:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
210 |
# break
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
211 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
212 |
# Write XML footer
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
213 |
report = open('anno_report.xml', 'a')
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
214 |
report.write("</report>")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
215 |
report.close()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
216 |
|