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