Home | History | Annotate | Download | only in tools
      1 #!/usr/bin/env python
      2 #
      3 # Copyright (C) 2009 The Android Open Source Project
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the 'License');
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of the License at
      8 #
      9 #      http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 # Unless required by applicable law or agreed to in writing, software
     12 # distributed under the License is distributed on an 'AS IS' BASIS,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 #
     17 
     18 import cgi, os, string, sys
     19 
     20 def IsDifferent(row):
     21   val = None
     22   for v in row:
     23     if v:
     24       if not val:
     25         val = v
     26       else:
     27         if val != v:
     28           return True
     29   return False
     30 
     31 def main(argv):
     32   inputs = argv[1:]
     33   data = {}
     34   index = 0
     35   for input in inputs:
     36     f = file(input, "r")
     37     lines = f.readlines()
     38     f.close()
     39     lines = map(string.split, lines)
     40     lines = map(lambda (x,y): (y,int(x)), lines)
     41     for fn,sz in lines:
     42       if not data.has_key(fn):
     43         data[fn] = {}
     44       data[fn][index] = sz
     45     index = index + 1
     46   rows = []
     47   for fn,sizes in data.iteritems():
     48     row = [fn]
     49     for i in range(0,index):
     50       if sizes.has_key(i):
     51         row.append(sizes[i])
     52       else:
     53         row.append(None)
     54     rows.append(row)
     55   rows = sorted(rows, key=lambda x: x[0])
     56   print """<html>
     57     <head>
     58       <style type="text/css">
     59         .fn, .sz, .z, .d {
     60           padding-left: 10px;
     61           padding-right: 10px;
     62         }
     63         .sz, .z, .d {
     64           text-align: right;
     65         }
     66         .fn {
     67           background-color: #ffffdd;
     68         }
     69         .sz {
     70           background-color: #ffffcc;
     71         }
     72         .z {
     73           background-color: #ffcccc;
     74         }
     75         .d {
     76           background-color: #99ccff;
     77         }
     78       </style>
     79     </head>
     80     <body>
     81   """
     82   print "<table>"
     83   print "<tr>"
     84   for input in inputs:
     85     combo = input.split(os.path.sep)[1]
     86     print "  <td class='fn'>%s</td>" % cgi.escape(combo)
     87   print "</tr>"
     88 
     89   for row in rows:
     90     print "<tr>"
     91     for sz in row[1:]:
     92       if not sz:
     93         print "  <td class='z'>&nbsp;</td>"
     94       elif IsDifferent(row[1:]):
     95         print "  <td class='d'>%d</td>" % sz
     96       else:
     97         print "  <td class='sz'>%d</td>" % sz
     98     print "  <td class='fn'>%s</td>" % cgi.escape(row[0])
     99     print "</tr>"
    100   print "</table>"
    101   print "</body></html>"
    102 
    103 if __name__ == '__main__':
    104   main(sys.argv)
    105 
    106 
    107