Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-13 23:27:45

0001 #!/usr/bin/env python3
0002 
0003 from __future__ import print_function
0004 import os, sys, string
0005 
0006 from xml.parsers import expat
0007 
0008 # ================================================================================
0009 
0010 class SimpleAsciiFormatter :
0011 
0012     def __init__(self, title="CMS SDT pages", style=None, outFile=sys.stdout) :
0013         self.format = ""
0014         self.title = title
0015         return
0016     
0017     def showLine(self) :
0018         print("\n================================================================================\n")
0019         return
0020     
0021     def write(self, arg="") :
0022         print(arg)
0023         return
0024 
0025     def writeB(self, arg="") :
0026         print(arg)
0027         return
0028 
0029     def writeBr(self) :
0030         print() 
0031         return
0032 
0033     def writeH1(self, arg="") :
0034         print(arg)
0035         return
0036     
0037     def writeH2(self, arg="") :
0038         print(arg)
0039         return
0040 
0041     def writeH3(self, arg="") :
0042         print(arg)
0043         return
0044     
0045     def startTable(self, colSizes, colLabels) :
0046         self.cols = colSizes
0047         self.format = ""
0048         for fmt in self.cols :
0049             self.format += "%"+str(fmt)+"s "
0050         print(self.format % tuple(colLabels))
0051 
0052         return
0053 
0054     def writeRow(self, args) :
0055         print(self.format % tuple(args))
0056 
0057         return
0058 
0059     def endTable(self) :
0060         self.format = None
0061         self.cols   = None
0062         
0063     
0064 # ================================================================================
0065 
0066 class SimpleHTMLFormatter :
0067 
0068     def __init__(self, title="CMS SDT pages ", style=None, outFile=sys.stdout, scriptCode='') :
0069         import time
0070 
0071         self.headersDone = False
0072         self.title=title
0073         self.style = style
0074         self.scriptCode = scriptCode
0075         self.outFile = outFile
0076         self.format = ""
0077 
0078         return
0079 
0080     def addScriptCode(self, scriptCode):
0081         self.scriptCode += scriptCode
0082 
0083     def __del__(self) :
0084         if self.headersDone :
0085             self.trailers()
0086         else: # in case nothing has been written yet, output an empty page ...
0087             self.outFile.write( "Content-Type: text/html" + '\n')     # HTML is following
0088             self.outFile.write( '\n')   # blank line, end of headers
0089             self.outFile.write( "<html> " + '\n')
0090             self.outFile.write( "</html> " + '\n')
0091         
0092         return
0093 
0094     def showLine(self) :
0095         self.headers()
0096         self.outFile.write( "<hr />" + '\n')
0097         return
0098     
0099     def write(self, arg="", bold=False) :
0100         self.headers()
0101         if bold:
0102             self.writeB(arg)
0103         else:
0104             self.outFile.write( arg + '\n')
0105         return
0106 
0107     def writeBr(self) :
0108         self.headers()
0109         self.outFile.write( "<br /> <br /> " + '\n')
0110         return
0111     
0112     def writeB(self, arg="") :
0113         self.headers()
0114         self.outFile.write( "<b> " + arg + " </b>" + '\n')
0115         return
0116     
0117     def writeH1(self, arg="") :
0118         self.headers()
0119         self.outFile.write( "<h1> " + arg + " </h1>" + '\n')
0120         return
0121     
0122     def writeH2(self, arg="") :
0123         self.headers()
0124         self.outFile.write( "<h2> " + arg + " </h2>" + '\n')
0125         return
0126 
0127     def writeH3(self, arg="") :
0128         self.headers()
0129         self.outFile.write( "<h3> " + arg + " </h3>" + '\n')
0130         return
0131     
0132     def writeAnchor(self, ref="") :
0133         self.headers()
0134         self.outFile.write( '<a name="' + ref + '">&nbsp;</a>')
0135         return
0136     
0137     def startTable(self, colSizes, colLabels, id=None, cls=None, tableAttr=None) :
0138         # we assume that html headers are done by now !!
0139         tableString = '<table '
0140         if tableAttr:
0141             tableString += tableAttr
0142         if id:
0143             tableString += ' id="'+id+'" '
0144         if cls:
0145             tableString += ' class="'+cls+'" '
0146         tableString += '>'
0147         self.outFile.write( tableString + '\n')
0148 
0149         self.outFile.write( " <thead>\n  <tr>"  + '\n')
0150         for col in colLabels :
0151             self.outFile.write( "   <th> <b>" + col + "</b> </th>" + '\n')
0152         self.outFile.write( "  </tr>\n</thead>" + '\n')
0153         self.outFile.write( "  <tbody>" + '\n')
0154         return
0155 
0156     def writeRow(self, args, bold=False, cls=None) :
0157         # we assume that headers are done by now !!
0158 
0159         if cls:
0160             self.outFile.write( ' <tr class="'+cls+'"> \n')
0161         else:
0162             self.outFile.write( " <tr>" + '\n')
0163         for arg in args:
0164             if str(arg).strip() == "" : arg = "&nbsp;"
0165             if bold: self.outFile.write( '<td class=cellbold> ' )
0166             else:    self.outFile.write( "  <td> " )
0167             self.outFile.write( arg )
0168             
0169             self.outFile.write( " </td>" + '\n')
0170         self.outFile.write( " </tr> " + '\n')
0171 
0172         return
0173 
0174     def writeStyledRow(self, args, styles) :
0175         # we assume that headers are done by now !!
0176         self.outFile.write( " <tr>" + '\n')
0177         for arg, cellStyle in zip(args, styles):
0178             if str(arg).strip() == "" : arg = "&nbsp;"
0179             cellStyle = cellStyle.strip()
0180             if cellStyle != '' : self.outFile.write( '<td class='+cellStyle+'> ' )
0181             else:    self.outFile.write( "  <td> " )
0182             self.outFile.write( arg )
0183             self.outFile.write( " </td>" + '\n')
0184         self.outFile.write( " </tr> " + '\n')
0185 
0186         return
0187 
0188     def endTable(self) :
0189         # we assume that headers are done by now !!
0190         self.outFile.write( "</tbody>" + '\n')
0191         self.outFile.write( "</table>" + '\n')
0192         
0193     # --------------------------------------------------------------------------------
0194     def headers(self) :
0195         # make sure to write the headers only once ...
0196         if not self.headersDone :
0197         
0198             self.outFile.write( "<html> " + '\n')
0199 
0200             self.outFile.write( "<head> " + '\n')
0201 
0202             if self.style:
0203                 self.outFile.write( self.style + '\n')
0204             
0205             self.outFile.write( "<TITLE>" + self.title + "</TITLE>" + '\n')
0206             if self.scriptCode:
0207                 self.outFile.write( self.scriptCode + '\n' )
0208             self.outFile.write( "</head> " + '\n')
0209             self.outFile.write( "<body>" + '\n')
0210         self.headersDone = True
0211 
0212         return
0213 
0214     # --------------------------------------------------------------------------------
0215     def trailers(self) :
0216         # write only if headers have been written ...
0217         if self.headersDone :
0218             self.outFile.write( "</body>" + '\n')
0219             self.outFile.write( "</html> " + '\n')
0220             pass
0221         return
0222 
0223