123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #!/usr/bin/python
- # Copyright (c) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
- # All rights reserved.
- # This component and the accompanying materials are made available
- # under the terms of the License "Symbian Foundation License v1.0"
- # which accompanies this distribution, and is available
- # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
- '''
- Tie together a set of HTML build summaries by creating a single index page
- which shows the total number of Errors, Warnings etc. across all the parts
- of the build and links to the individual summaries.
- '''
- import os
- import sys
- import time
- import traceback
- # get the absolute path to this script
- script = os.path.abspath(sys.argv[0])
- bindir = os.path.dirname(script)
- # add the Raptor python and plugins directories to the PYTHONPATH
- sys.path[0:0]=[os.path.join(bindir, ".."),os.path.join(bindir, "..","raptor","plugins")]
- if len(sys.argv) < 3:
- sys.stderr.write("""usage: %s input_dir1 [input_dir2...] output_index_file
-
- The input directories are scanned recursively for totals.txt files and all
- those found are added to the generated index.
- """ % os.path.basename(script))
- sys.exit(1)
- roots = []
- for a in sys.argv[1:-1]:
- if os.path.isdir(a):
- roots.append(a)
- else:
- sys.stderr.write("warning: %s is not a directory\n" % a)
- indexfile = sys.argv[-1]
- indexdir = os.path.dirname(indexfile)
-
- def findtotals(dirs, files):
- "recurse directories until we find a totals.txt file."
- sub = []
- for d in dirs:
- name = os.path.join(d, "totals.txt")
- if os.path.isfile(name):
- files.append(name)
- else:
- for s in os.listdir(d):
- dir = os.path.join(d,s)
- if os.path.isdir(dir):
- sub.append(dir)
- if sub:
- findtotals(sub, files)
- totals = []
- findtotals(roots, totals)
- totals.sort()
- # look for a style file we can link to
- css = "style.css"
- for t in totals:
- c = os.path.join(os.path.dirname(t),"style.css")
- if os.path.isfile(c):
- css = os.path.relpath(c, indexdir)
- break
-
- # write the header of the index
- import raptor.filter_interface as filter_interface
- try:
- index = open(indexfile, "w")
- index.write("""<html>
- <head>
- <title>Raptor Build Index</title>
- <link type="text/css" rel="stylesheet" href="%s">
- </head>
- <body>
- <h1>Raptor Build Index</h1>
- <table>
- <tr><th>build</th>""" % css)
- for i in filter_interface.Records.TITLES:
- index.write('<th class="numbers">%s</th>' % i)
- index.write("</tr>")
- except:
- sys.stderr.write("error: cannot write index file %s\n" % indexfile)
- traceback.print_exc()
- sys.exit(1)
-
- import csv
- grandtotal = [0 for i in filter_interface.Records.TITLES]
- for t in totals:
- columns = []
- try:
- reader = csv.reader(open(t, "rb"))
- for row in reader:
- type = int(row[0])
- style = row[1]
-
- if style == 'time':
- count = float(row[2])
- else:
- count = int(row[2])
-
- if count == 0 or filter_interface.Records.CLASSES[type] == style:
- grandtotal[type] += count
- columns.append((style,count))
- else:
- sys.stderr.write("warning: %s appears to be corrupt or out of date\n" % t)
- except:
- sys.stderr.write("warning: %s could not be read\n" % t)
- if len(columns) == len(filter_interface.Records.TITLES):
- try:
- linktext = os.path.dirname(t)
- linkname = os.path.relpath(os.path.join(linktext, "index.html"), indexdir)
- index.write('<tr><td class="name"><a href="%s">%s</a></td>' % (linkname, linktext))
- for (style, count) in columns:
- if style == 'time':
- n = time.strftime("%H:%M:%S", time.gmtime(count + 0.5))
- else:
- n = str(count)
- index.write('<td class="%s">%s</td>' % (style, n))
- index.write("</tr>")
- except:
- sys.stderr.write("error: cannot write index file %s\n" % indexfile)
- traceback.print_exc()
- sys.exit(1)
-
- # finish off
- try:
- index.write('<tr><td> </td></tr><tr><td class="name">total</td>')
- for i, count in enumerate(grandtotal):
- style = filter_interface.Records.CLASSES[i]
- if style == 'time':
- n = time.strftime("%H:%M:%S", time.gmtime(count + 0.5))
- else:
- n = str(count)
-
- if count == 0:
- index.write('<td class="zero">0</td>')
- else:
- index.write('<td class="%s">%s</td>' % (style, n))
- index.write("</tr></table>")
- index.write("</body></html>\n")
- index.close()
- except:
- sys.stderr.write("error: cannot close index file %s\n" % indexfile)
- traceback.print_exc()
- sys.exit(1)
-
- sys.exit(0)
|