#===================================================== # Copyright (C) 2011-2012 Andrea Arteaga #===================================================== # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # import time from os.path import join as pjoin, basename from xml.sax.saxutils import escape as xmlescape import benchconfig as cfg class HTMLreport: def __init__(self, fname, title="Benchmarks report", \ inputfile=pjoin(cfg.reportdir, basename(cfg.inputfile))): self.fname = fname self.content = """ Benchmarks report

""" self.content += title + "

" date = time.strftime('%Y-%m-%d, %I:%M %p') self.content += '

Generated on ' + date + '

' # Information regarding the CPU cpuinfo = file('/proc/cpuinfo', 'r').readlines() cpu = None for l in cpuinfo: if l[:10] == 'model name': cpu = l.split(':',1)[1].strip() if cpu: self.content += '

CPU: ' + cpu + '

' # Information regarding the memory meminfo = file('/proc/meminfo', 'r').readlines() mem = None for l in meminfo: if l[:8] == 'MemTotal': mem = l.split(':',1)[1].strip() if mem: self.content += '

Total memory: ' + mem + '

' # Input file self.content += '
Input file: ' + \ '%s' % (basename(inputfile), cfg.inputfile) + \ '
%s
' % xmlescape(file(cfg.inputfile, 'r').read()) self.content += '
Logs: %s
' \ % cfg.logdir def addFig(self, title, image, descr='', alt='', width=None): self.content += '
' self.content += '

' + title + '

' if descr.strip() != '': self.content += '

' + descr + '

' self.content += '
' self.content += '' self.content += '