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