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