casa
$Rev:20696$
|
00001 import os 00002 #from math import * 00003 00004 #directions for htmlPub() with python interpreter 00005 #>>>a=htmlPub(filename,title), where filename is output html page 00006 #>>>header=text for header of the page section 00007 #>>>text1=[list of string statements for above image] 00008 #>>>text2=[list of string statements for below image] 00009 #>>>a.doBlk(text1,text2,imagePath,header=''), repeat this for all images 00010 #>>>a.doFooter(), to close out the htmlfile and terminate file stream 00011 00012 class htmlPub: 00013 def __init__(self,file,title='Performance tests'): 00014 self.fd=os.open(file,os.O_CREAT|os.O_WRONLY,0644) 00015 self.title = title 00016 self.doTitle() 00017 00018 def doTitle(self): 00019 s='<html>\n<head><title>' 00020 s+=self.title+'</title>\n' 00021 os.write(self.fd,s) 00022 os.write(self.fd,'<body>\n') 00023 00024 def doHeader(self,header,mode): 00025 if mode==0: 00026 s='Performance test from' 00027 ss=os.path.basename(header) 00028 os.write(self.fd,'<h2>%s %s</h2>'%(s,ss[:-4])) 00029 elif mode==1: 00030 os.write(self.fd,'<h2>%s</h2>'%(header)) 00031 00032 def doBlk(self, body1, body2, image_path,header=''): 00033 if header=='': self.doHeader(image_path,0) 00034 else: self.doHeader(header,1) 00035 00036 for x in body1: 00037 os.write(self.fd,'<p>\n'+x+'\n') 00038 self.doImage(image_path) 00039 for x in body2: 00040 os.write(self.fd,'<p>\n'+x+'\n') 00041 00042 def doImage(self,image_path): 00043 s='<IMG src=\"'+image_path+'\" alt=\"image\" width=\"900\" height=\"600\">\n' 00044 os.write(self.fd,s) 00045 00046 def doFooter(self): 00047 os.write(self.fd,'</body>\n') 00048 s='</html>\n' 00049 os.write(self.fd,s) 00050 self.closeFD() 00051 00052 def doPage(self,body1,body2,image_path): #deprecated 00053 self.doBlk(body1,body2,image_path) 00054 self.doFooter() 00055 00056 def closeFD(self): 00057 os.close(self.fd)