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