625
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
2 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
3 |
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
4 |
# All rights reserved.
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
5 |
# This component and the accompanying materials are made available
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
6 |
# under the terms of the License "Symbian Foundation License v1.0"
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
7 |
# which accompanies this distribution, and is available
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
8 |
# at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
|
641
|
9 |
|
|
10 |
'''
|
|
11 |
Tie together a set of HTML build summaries by creating a single index page
|
|
12 |
which shows the total number of Errors, Warnings etc. across all the parts
|
|
13 |
of the build and links to the individual summaries.
|
|
14 |
'''
|
625
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
15 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
16 |
import os
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
17 |
import sys
|
641
|
18 |
import time
|
625
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
19 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
20 |
# get the absolute path to this script
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
21 |
script = os.path.abspath(sys.argv[0])
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
22 |
bindir = os.path.dirname(script)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
23 |
# add the Raptor python and plugins directories to the PYTHONPATH
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
24 |
sys.path.append(os.path.join(bindir, "..", "python"))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
25 |
sys.path.append(os.path.join(bindir, "..", "python", "plugins"))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
26 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
27 |
if len(sys.argv) < 3:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
28 |
sys.stderr.write("""usage: %s input_dir1 [input_dir2...] output_index_file
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
29 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
30 |
The input directories are scanned recursively for totals.txt files and all
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
31 |
those found are added to the generated index.
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
32 |
""" % os.path.basename(script))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
33 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
34 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
35 |
roots = []
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
36 |
for a in sys.argv[1:-1]:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
37 |
if os.path.isdir(a):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
38 |
roots.append(a)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
39 |
else:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
40 |
sys.stderr.write("warning: %s is not a directory\n" % a)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
41 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
42 |
indexfile = sys.argv[-1]
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
43 |
indexdir = os.path.dirname(indexfile)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
44 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
45 |
def findtotals(dirs, files):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
46 |
"recurse directories until we find a totals.txt file."
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
47 |
sub = []
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
48 |
for d in dirs:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
49 |
name = os.path.join(d, "totals.txt")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
50 |
if os.path.isfile(name):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
51 |
files.append(name)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
52 |
else:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
53 |
for s in os.listdir(d):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
54 |
dir = os.path.join(d,s)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
55 |
if os.path.isdir(dir):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
56 |
sub.append(dir)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
57 |
if sub:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
58 |
findtotals(sub, files)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
59 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
60 |
totals = []
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
61 |
findtotals(roots, totals)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
62 |
totals.sort()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
63 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
64 |
# look for a style file we can link to
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
65 |
css = "style.css"
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
66 |
for t in totals:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
67 |
c = os.path.join(os.path.dirname(t),"style.css")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
68 |
if os.path.isfile(c):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
69 |
css = os.path.relpath(c, indexdir)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
70 |
break
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
71 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
72 |
# write the header of the index
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
73 |
import filter_html
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
74 |
try:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
75 |
index = open(indexfile, "w")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
76 |
index.write("""<html>
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
77 |
<head>
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
78 |
<title>Raptor Build Index</title>
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
79 |
<link type="text/css" rel="stylesheet" href="%s">
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
80 |
</head>
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
81 |
<body>
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
82 |
<h1>Raptor Build Index</h1>
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
83 |
<table>
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
84 |
<tr><th>build</th>""" % css)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
85 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
86 |
for i in filter_html.Records.TITLES:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
87 |
index.write('<th class="numbers">%s</th>' % i)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
88 |
index.write("</tr>")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
89 |
except:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
90 |
sys.stderr.write("error: cannot write index file %s\n" % indexfile)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
91 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
92 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
93 |
import csv
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
94 |
grandtotal = [0 for i in filter_html.Records.TITLES]
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
95 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
96 |
for t in totals:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
97 |
columns = []
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
98 |
try:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
99 |
reader = csv.reader(open(t, "rb"))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
100 |
for row in reader:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
101 |
type = int(row[0])
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
102 |
style = row[1]
|
641
|
103 |
|
|
104 |
if style == 'time':
|
|
105 |
count = float(row[2])
|
|
106 |
else:
|
|
107 |
count = int(row[2])
|
|
108 |
|
|
109 |
if count == 0 or filter_html.Records.CLASSES[type] == style:
|
625
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
110 |
grandtotal[type] += count
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
111 |
columns.append((style,count))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
112 |
else:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
113 |
sys.stderr.write("warning: %s appears to be corrupt or out of date\n" % t)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
114 |
except:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
115 |
sys.stderr.write("warning: %s could not be read\n" % t)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
116 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
117 |
if len(columns) == len(filter_html.Records.TITLES):
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
118 |
try:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
119 |
linktext = os.path.dirname(t)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
120 |
linkname = os.path.relpath(os.path.join(linktext, "index.html"), indexdir)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
121 |
index.write('<tr><td class="name"><a href="%s">%s</a></td>' % (linkname, linktext))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
122 |
for (style, count) in columns:
|
641
|
123 |
if style == 'time':
|
|
124 |
n = time.strftime("%H:%M:%S", time.gmtime(count + 0.5))
|
|
125 |
else:
|
|
126 |
n = str(count)
|
|
127 |
index.write('<td class="%s">%s</td>' % (style, n))
|
625
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
128 |
index.write("</tr>")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
129 |
except:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
130 |
sys.stderr.write("error: cannot write index file %s\n" % indexfile)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
131 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
132 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
133 |
# finish off
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
134 |
try:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
135 |
index.write('<tr><td> </td></tr><tr><td class="name">total</td>')
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
136 |
for i, count in enumerate(grandtotal):
|
641
|
137 |
style = filter_html.Records.CLASSES[i]
|
|
138 |
if style == 'time':
|
|
139 |
n = time.strftime("%H:%M:%S", time.gmtime(count + 0.5))
|
|
140 |
else:
|
|
141 |
n = str(count)
|
|
142 |
|
625
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
143 |
if count == 0:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
144 |
index.write('<td class="zero">0</td>')
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
145 |
else:
|
641
|
146 |
index.write('<td class="%s">%s</td>' % (style, n))
|
625
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
147 |
index.write("</tr></table>")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
148 |
index.write("</body></html>\n")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
149 |
index.close()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
150 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
151 |
except:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
152 |
sys.stderr.write("error: cannot close index file %s\n" % indexfile)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
153 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
154 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
155 |
sys.exit(0) |