Go to the documentation of this file.00001 import os
00002 import glob
00003 from string import Template
00004
00005
00006 validationToolsDir = os.environ['VALTOOLS']
00007 validationTestDir = os.environ['VALTEST']
00008
00009 indexhtml = os.path.join(validationToolsDir, "templates", "index.html")
00010
00011 def CheckFile(myFile):
00012 if not os.path.isfile(myFile):
00013 raise IOError, "Error! Can't stat %s!" % myFile
00014 else:
00015 return myFile
00016
00017
00018
00019 currentpath = os.path.abspath(os.getcwd())
00020 title = currentpath.replace(os.path.abspath(validationTestDir), '')
00021
00022
00023 cmssw = os.environ['CMSSW_VERSION']
00024
00025
00026 date = os.popen( 'date' ).read()
00027
00028
00029 showTags = os.popen("cat %s" % CheckFile('Config/showtags.txt')).read()
00030
00031
00032 difftoreleaselink = CheckFile('Config/diffToVanillaRelease.patch')
00033 difftorelease = "cvs diff -r %s" % cmssw
00034
00035 difftotagslink = CheckFile('Config/diffToTags.patch')
00036 difftotags = 'cvs diff'
00037
00038 cfgdumplink = 'Config/cfgDump.py'
00039 cfgdump = 'cfgDump.py'
00040 if not os.path.isfile(cfgdumplink):
00041 cfgdumplink = 'Config/cfgDump_0.py'
00042 cfgdump = 'cfgDump_0.py (batch job)'
00043
00044 CheckFile(cfgdumplink)
00045
00046 if title.find('fastsim') != -1:
00047 genConfigLink = cfgdumplink
00048 genConfig = "fastsim (see cfgDump)"
00049
00050 elif title.find('fullsim') != -1:
00051 genConfigLink = cfgdumplink
00052 genConfig = "fullsim (see cfgDump)"
00053 else:
00054 genConfigLink = "Config/DataSource_cff.py"
00055 genConfig = "DataSource_cff.py"
00056
00057 rootFiles = glob.glob("*root")
00058 if len(rootFiles) != 1:
00059 print "There must be one, and only one root file in the directory to correctly build the webpage!"
00060 sys.exit()
00061
00062 rootFileLink = os.path.basename(rootFiles[0])
00063 rootFile=rootFileLink
00064
00065
00066 imgTemplate = '<IMG src="%s" width="500" align="left" border="0">'
00067 fourImages = '<table style="text-align: left; " border="1" cellpadding="2" cellspacing="0">\n\
00068 <tbody>\n\
00069 <tr>\n\
00070 <td style="width: 350px;"><IMG src="%s" width="350" align="left" border="0"></td>\
00071 <td style="width: 350px;"><IMG src="%s" width="350" align="left" border="0"></td>\
00072 <td style="width: 350px;"><IMG src="%s" width="350" align="left" border="0"></td>\
00073 <td style="width: 350px;"><IMG src="%s" width="350" align="left" border="0"></td>\
00074 </tr></tbody></table>\n\
00075 '
00076
00077 images = ''
00078
00079
00080 StepByStepPlotDirectories = filter(os.path.isdir, glob.glob("SummaryPlots/*"))
00081 StepByStepPlots = []
00082 for aDir in StepByStepPlotDirectories:
00083 producerName = os.path.basename(aDir)
00084 images += "<hr><h3>" + producerName + "</h3>\n"
00085
00086 getByVar = lambda x: glob.glob(os.path.join(aDir, '*%s.png' % x))[0]
00087 images += fourImages % (getByVar("pt"), getByVar("eta"), getByVar("energy"), getByVar("phi"))
00088
00089
00090 captionsContents = ""
00091 for line in captionsContents:
00092 try:
00093 (picfile, caption) = readCaption( line )
00094 img = imgTemplate % os.path.basename(picfile)
00095 images = "%s<h3>%s:</h3>\n%s\n" % (images, caption, img)
00096
00097
00098 shutil.copy(picfile, outputDir)
00099 except Exception:
00100 raise
00101
00102 comments = ""
00103
00104 ComparisionDirectories = filter(os.path.isdir, glob.glob("ComparedTo*"))
00105 comparisonlinks = ""
00106 for aComp in ComparisionDirectories:
00107 comparisonlinks += '<h3>%s <a href="%s">(config)</a></h3>\n\n' % (aComp.replace('ComparedTo', 'Compared to '), os.path.join(aComp, "ReferenceData"))
00108 comparisonlinks += "<ul>\n"
00109 for anHtmlFile in filter(os.path.isfile, glob.glob(os.path.join(aComp, "Plots/*.html"))):
00110 comparisonlinks += '<li> <a href="%s">%s</a> </li>' % (anHtmlFile, os.path.basename(anHtmlFile).replace(".html",""))
00111 comparisonlinks += "</ul>\n"
00112
00113 ifile = open( indexhtml )
00114 indexTemplate = ifile.read()
00115
00116 s = Template(indexTemplate)
00117 subst = s.substitute(title = title,
00118 difftotagslink=difftotagslink,
00119 difftotags=difftotags,
00120 difftoreleaselink=difftoreleaselink,
00121 difftorelease=difftorelease,
00122 cfgdumplink=cfgdumplink,
00123 cfgdump=cfgdump,
00124 comparisonlinks=comparisonlinks,
00125 genConfig = os.path.basename(genConfig),
00126 genConfigLink = genConfigLink,
00127 rootFile = os.path.basename(rootFile),
00128 rootFileLink = rootFileLink,
00129 comments = comments,
00130 cmssw = cmssw,
00131 showTags = showTags,
00132 images = images,
00133 username = os.environ['USER'],
00134 date = date
00135 )
00136 ofile = open( 'index.html', 'w' )
00137 ofile.write( subst )