CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BuildWebpage.py
Go to the documentation of this file.
1 import os
2 import glob
3 from string import Template
4 
5 
6 validationToolsDir = os.environ['VALTOOLS']
7 validationTestDir = os.environ['VALTEST']
8 
9 indexhtml = os.path.join(validationToolsDir, "templates", "index.html")
10 
11 def CheckFile(myFile):
12  if not os.path.isfile(myFile):
13  raise IOError, "Error! Can't stat %s!" % myFile
14  else:
15  return myFile
16 
17 # Get our path relative to the Validation/RecoTau/test directory
18 #title = os.path.relpath(os.cwd(), validationTestDir) python > 2.6
19 currentpath = os.path.abspath(os.getcwd())
20 title = currentpath.replace(os.path.abspath(validationTestDir), '')
21 
22 #Get our current release
23 cmssw = os.environ['CMSSW_VERSION']
24 
25 #Get current date
26 date = os.popen( 'date' ).read()
27 
28 #Our showtags
29 showTags = os.popen("cat %s" % CheckFile('Config/showtags.txt')).read()
30 
31 #Get the diffs to the release
32 difftoreleaselink = CheckFile('Config/diffToVanillaRelease.patch')
33 difftorelease = "cvs diff -r %s" % cmssw
34 
35 difftotagslink = CheckFile('Config/diffToTags.patch')
36 difftotags = 'cvs diff'
37 
38 cfgdumplink = 'Config/cfgDump.py'
39 cfgdump = 'cfgDump.py'
40 if not os.path.isfile(cfgdumplink):
41  cfgdumplink = 'Config/cfgDump_0.py'
42  cfgdump = 'cfgDump_0.py (batch job)'
43 
44 CheckFile(cfgdumplink)
45 
46 if title.find('fastsim') != -1:
47  genConfigLink = cfgdumplink
48  genConfig = "fastsim (see cfgDump)"
49 
50 elif title.find('fullsim') != -1:
51  genConfigLink = cfgdumplink
52  genConfig = "fullsim (see cfgDump)"
53 else:
54  genConfigLink = "Config/DataSource_cff.py"
55  genConfig = "DataSource_cff.py"
56 
57 rootFiles = glob.glob("*root")
58 if len(rootFiles) != 1:
59  print "There must be one, and only one root file in the directory to correctly build the webpage!"
60  sys.exit()
61 
62 rootFileLink = os.path.basename(rootFiles[0])
63 rootFile=rootFileLink
64 
65 #imgTemplate = '<IMG src="%s" width="500" align="left" border="0"><br clear="ALL">'
66 imgTemplate = '<IMG src="%s" width="500" align="left" border="0">'
67 fourImages = '<table style="text-align: left; " border="1" cellpadding="2" cellspacing="0">\n\
68  <tbody>\n\
69  <tr>\n\
70  <td style="width: 350px;"><IMG src="%s" width="350" align="left" border="0"></td>\
71  <td style="width: 350px;"><IMG src="%s" width="350" align="left" border="0"></td>\
72  <td style="width: 350px;"><IMG src="%s" width="350" align="left" border="0"></td>\
73  <td style="width: 350px;"><IMG src="%s" width="350" align="left" border="0"></td>\
74  </tr></tbody></table>\n\
75  '
76 
77 images = ''
78 
79 # Get summary plots
80 StepByStepPlotDirectories = filter(os.path.isdir, glob.glob("SummaryPlots/*"))
81 StepByStepPlots = []
82 for aDir in StepByStepPlotDirectories:
83  producerName = os.path.basename(aDir)
84  images += "<hr><h3>" + producerName + "</h3>\n"
85  # get the plots
86  getByVar = lambda x: glob.glob(os.path.join(aDir, '*%s.png' % x))[0]
87  images += fourImages % (getByVar("pt"), getByVar("eta"), getByVar("energy"), getByVar("phi"))
88 
89 # open legend file
90 captionsContents = ""
91 for line in captionsContents:
92  try:
93  (picfile, caption) = readCaption( line )
94  img = imgTemplate % os.path.basename(picfile)
95  images = "%s<h3>%s:</h3>\n%s\n" % (images, caption, img)
96  # what to do if the file's not there?
97  # : print a warning
98  shutil.copy(picfile, outputDir)
99  except Exception:
100  raise
101 
102 comments = ""
103 
104 ComparisionDirectories = filter(os.path.isdir, glob.glob("ComparedTo*"))
105 comparisonlinks = ""
106 for aComp in ComparisionDirectories:
107  comparisonlinks += '<h3>%s <a href="%s">(config)</a></h3>\n\n' % (aComp.replace('ComparedTo', 'Compared to '), os.path.join(aComp, "ReferenceData"))
108  comparisonlinks += "<ul>\n"
109  for anHtmlFile in filter(os.path.isfile, glob.glob(os.path.join(aComp, "Plots/*.html"))):
110  comparisonlinks += '<li> <a href="%s">%s</a> </li>' % (anHtmlFile, os.path.basename(anHtmlFile).replace(".html",""))
111  comparisonlinks += "</ul>\n"
112 
113 ifile = open( indexhtml )
114 indexTemplate = ifile.read()
115 
116 s = Template(indexTemplate)
117 subst = s.substitute(title = title,
118  difftotagslink=difftotagslink,
119  difftotags=difftotags,
120  difftoreleaselink=difftoreleaselink,
121  difftorelease=difftorelease,
122  cfgdumplink=cfgdumplink,
123  cfgdump=cfgdump,
124  comparisonlinks=comparisonlinks,
125  genConfig = os.path.basename(genConfig),
126  genConfigLink = genConfigLink,
127  rootFile = os.path.basename(rootFile),
128  rootFileLink = rootFileLink,
129  comments = comments,
130  cmssw = cmssw,
131  showTags = showTags,
132  images = images,
133  username = os.environ['USER'],
134  date = date
135  )
136 ofile = open( 'index.html', 'w' )
137 ofile.write( subst )
def replace
Definition: linker.py:10
tuple getByVar
Definition: BuildWebpage.py:86
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
Definition: align_tpl.py:86