casa
$Rev:20696$
|
00001 #a class for making html tables of results 00002 import os 00003 import time 00004 import string 00005 import shutil 00006 import inspect 00007 import sys 00008 00009 import socket 00010 00011 class tableMaker: 00012 def __init__(self, thedir, testname, header='', footer=''): 00013 00014 a=inspect.stack() 00015 stacklevel=0 00016 for k in range(len(a)): 00017 if (string.find(a[k][1], 'ipython console') > 0): 00018 stacklevel=k 00019 myf=sys._getframe(stacklevel).f_globals 00020 self.header=header 00021 self.footer=footer 00022 self.thedir=thedir 00023 self.pagename=thedir+'/result-'+time.strftime('%Y_%m_%d_%H_%M.html') 00024 00025 #self.pagename='result-test.html' 00026 #if access(self.pagename,F_OK): 00027 # remove(self.pagename) 00028 # print 'removing old junk' 00029 self.oldarchive(thedir) 00030 if self.header != '' and os.path.isfile(self.header): 00031 shutil.copy(self.header, self.pagename) 00032 self.fd=os.open(self.pagename,os.O_APPEND|os.O_WRONLY,0644) 00033 s='<title>' 00034 s+='Test results for '+time.strftime('%Y_%m_%d') +'</title>\n' 00035 os.write(self.fd,s) 00036 os.write(self.fd,'<body>\n') 00037 os.write(self.fd, '<p><A HREF="%s">%s</A>\n<p>'%('archive.html','ARCHIVE OF PREVIOUS RUNS')) 00038 os.write(self.fd, '<CENTER><TABLE border="1" cellpadding=5 summary="Quick view over tests."><CAPTION><EM>Summary of Tests on %s -- %s -- %s</EM></CAPTION>\n'%(os.uname()[0],os.uname()[1], myf['casalog'].version()) ) 00039 os.write(self.fd, '<TR><TH align=middle>Test Name<TH align=middle>Image Name<TH align=middle>Quick Result<TH align=middle> Status <TH align=middle> Link to results\n') 00040 00041 def addRows(self,stuff): #values has two components, number+status 00042 #print stuff 00043 00044 for i in stuff: 00045 if(i[2]==1): status='<font color="green">Passed</font>' 00046 elif (i[2]==2): status='<font color="blue">Unknown</font>' 00047 else: status='<font color="red">Failed</font>' 00048 # link='<A HREF="file:///%s">%s</A>\n'%(i[3],i[3]) 00049 link='<A HREF="%s">%s</A>\n'%(i[3],i[3]) 00050 s='<TR><TD>%s<TD>%s<TD>%s<TD>%s<TD>%s\n'%(i[0],i[4],i[1],status,link) 00051 os.write(self.fd,s) 00052 00053 def done(self): 00054 os.write(self.fd, '</CENTER></TABLE>\n') 00055 os.write(self.fd,'</body>\n') 00056 s='</html>\n' 00057 os.write(self.fd,s) 00058 os.close(self.fd) 00059 if self.footer != '' and os.path.isfile(self.footer): 00060 os.system('cat '+self.footer+' >> '+self.pagename) 00061 print 'table written to %s\n'%self.pagename 00062 return self.pagename 00063 00064 def oldarchive(self, result_dir): 00065 #RESULT_DIR='/home/ballista3/Regression/Result' 00066 00067 ##remove archive file 00068 os.system('rm -f '+result_dir+'/archive.html') 00069 a=os.listdir(result_dir) 00070 b=os.listdir(result_dir) 00071 for k in range(len(b)) : 00072 if(string.count(b[k], '.html') < 1): 00073 a.remove(b[k]) 00074 00075 a.sort(reverse=True) 00076 00077 fd=os.open(result_dir+'/archive.html', os.O_CREAT|os.O_WRONLY,0644) 00078 s='<title>' 00079 s+='Archive of test results '+time.strftime('%Y_%m_%d') +'</title>\n' 00080 os.write(fd,s) 00081 os.write(fd,'<body>\n') 00082 for k in range(len(a)): 00083 os.write(fd, '<p><A HREF="%s">%s</A>\n<p>'%(a[k],a[k])) 00084 00085 os.write(fd,'</body>\n') 00086 s='</html>\n' 00087 os.write(fd,s) 00088 os.close(fd)