CMS 3D CMS Logo

indexGen.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
4 import shutil, sys, os, re, valtools
5 
6 from string import Template
7 
8 from optparse import OptionParser
9 
10 
11 
12 webpage = valtools.webpage()
13 
14 webpage.parser_.usage = "usage: %prog. Run from your Benchmark directory"
15 webpage.parser_.add_option("-r", "--recipe", dest="recipe",
16  help="url pointing to a recipe",
17  default="None")
18 webpage.parser_.add_option("-t", "--title", dest="title",
19  help="Benchmark title",
20  default="")
21 webpage.parser_.add_option("-g", "--gensource", dest="pyGenSource",
22  help="python file for the CMSSW source of the generated events, which is used in input to your simulation and reconstruction process",
23  default="None")
24 webpage.parser_.add_option("-s", "--simulation", dest="pySim",
25  help="python file for your CMSSW simulation and/or reconstruction process.",
26  default="None")
27 webpage.parseArgs()
28 
29 
30 if len(webpage.args_)!=0:
31  webpage.parser_.print_help()
32  sys.exit(1)
33 
34 benchmark = valtools.benchmark()
35 
36 webpage.setOutputDir( benchmark.fullName() )
37 
38 macro = 'plot.C'
39 recipe = webpage.options_.recipe
40 genConfig = webpage.options_.pyGenSource
41 simConfig = webpage.options_.pySim
42 benchmarkConfig = 'benchmark_cfg.py'
43 
44 # information about CMSSW
45 cmssw = os.environ['CMSSW_VERSION']
46 showTags = os.popen( 'showtags -t -r -u').read()
47 
48 title = webpage.benchmarkName_
49 
50 templateFile = 'index.html'
51 
52 outputDir = webpage.outputDir_
53 indexhtml = "%s/%s" % (webpage.templates_,templateFile)
54 
55 
56 valtools.testFileType(genConfig, ".py")
57 valtools.testFileType(simConfig, ".py")
58 valtools.testFileType(benchmarkConfig, ".py")
59 valtools.testFileType(macro, ".C")
60 
61 valtools.testFileType(indexhtml, ".html")
62 infonotfoundhtml = "%s/%s" % (webpage.templates_,"infoNotFound.html")
63 valtools.testFileType(infonotfoundhtml, ".html")
64 
65 
66 recipeLink = valtools.processFile( recipe, webpage.outputDir_ )
67 genConfigLink = valtools.processFile(genConfig, webpage.outputDir_ )
68 simConfigLink = valtools.processFile( simConfig, webpage.outputDir_ )
69 benchmarkConfigLink = valtools.processFile( benchmarkConfig,
70  webpage.outputDir_ )
71 macroLink = valtools.processFile(macro, webpage.outputDir_ )
72 rootFileLink = valtools.processFile(webpage.rootFile_, webpage.outputDir_ )
73 
74 comments = webpage.options_.comments
75 images = webpage.readCaptions('captions.txt')
76 
77 ifile = open( indexhtml )
78 indexTemplate = ifile.read()
79 s = Template(indexTemplate)
80 subst = s.substitute(title = title,
81  recipe = recipe,
82  recipeLink = recipeLink,
83  genConfig = os.path.basename(genConfig),
84  genConfigLink = genConfigLink,
85  simConfig = os.path.basename(simConfig),
86  simConfigLink = simConfigLink,
87  benchmarkConfig = os.path.basename(benchmarkConfig),
88  benchmarkConfigLink = benchmarkConfigLink,
89  macro = os.path.basename(macro),
90  macroLink = macroLink,
91  rootFile = os.path.basename(webpage.rootFile_),
92  rootFileLink = rootFileLink,
93  comments = comments,
94  cmssw = cmssw,
95  showTags = showTags,
96  images = images,
97  username = os.environ['USER'],
98  date = webpage.date_
99  )
100 
101 ofile = open( '%s/index.html' % outputDir, 'w' )
102 ofile.write( subst )
103 
104 ifile = open( infonotfoundhtml )
105 infoNotFoundTemplate = ifile.read()
106 s2 = Template(infoNotFoundTemplate)
107 subst2 = s2.substitute( username = os.environ['USER'] )
108 ofile2 = open( '%s/infoNotFound.html' % outputDir, 'w' )
109 ofile2.write( subst2 )
110 
111 print 'webpage directory successfully created in', outputDir
112 
def processFile(file, outputDir)
Definition: valtools.py:304
def testFileType(file, ext)
Definition: valtools.py:286