sbs_index.py 4.2 KB

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