CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefreshWebPage.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 import glob
5 import sys
6 import re
7 import web_templates as templates
8 from optparse import OptionParser
9 from Validation.RecoTau.ValidationOptions_cff import allowedOptions
10 
11 __author__ = "Mauro Verzetti (mauro.verzetti@cern.ch)"
12 __doc__ = """Script to update the web-page to show newly updated results. First upload the TauID directory in the proper location in $PastResults"""
13 
14 parser = OptionParser(description=__doc__)
15 parser.add_option('--test',action="store_true", dest="test", default=False, help="used to test/debug the script. The html file are written locally")
16 (options,crap) = parser.parse_args()
17 
18 def unpackRelease(relName):
19  m = re.match(r'^CMSSW_(?P<one>[0-9]+)_(?P<two>[0-9]+)_(?P<three>[0-9]+)(?:_pre(?P<four>[0-9]+))?',relName)
20  if m:
21  prev = int(m.group('four')) if m.group('four') else 1000000
22  return (m.group('one'),m.group('two'),m.group('three'),prev)
23  return (0,0)
24 
25 try:
26  webDir = os.environ['PastResults']
27 except:
28  print 'Run cmsenv and source UtilityCommands.(c)sh first!'
29  sys.exit(0)
30 
31 webDir += '/'
32 webDir_subdirs = filter( lambda x: os.path.isdir(webDir+x), os.listdir( webDir ) )
33 official_releases = sorted( filter( lambda x: re.findall(r'^CMSSW_[0-9]+_[0-9]+_[0-9]+(?:_pre[0-9]+)?$',x), webDir_subdirs), key=unpackRelease)
34 special_releases = sorted( filter( lambda x: re.findall(r'^CMSSW_[0-9]+_[0-9]+_[0-9]+',x) and not x in official_releases, webDir_subdirs), key=unpackRelease)
35 custom_made = [d for d in webDir_subdirs if not d in official_releases and not d in special_releases]
36 
37 
38 official_releases_links = ''.join([templates.create_main_list_element(d) for d in official_releases])
39 special_releases_links = ''.join([templates.create_main_list_element(d) for d in special_releases])
40 custom_made_links = ''.join([templates.create_main_list_element(d) for d in custom_made])
41 main_web_page = templates.main_page_template % (official_releases_links, special_releases_links, custom_made_links)
42 main_web_page_path = webDir+'index.html' if not options.test else 'index.html'
43 main_web_page_html = open(main_web_page_path,'w')
44 main_web_page_html.write(main_web_page)
45 main_web_page_html.close()
46 
47 for rel in official_releases+special_releases:
48  tauid_dir = webDir+rel+'/TauID/'
49  reldir = webDir+rel+'/'
50  datasets = filter(lambda x: os.path.isdir(tauid_dir+x) and not x == 'Reference', os.listdir(tauid_dir))
51  cfg_file = glob.glob(tauid_dir+'*/Config/showtags.txt')[0] if glob.glob(tauid_dir+'*/Config/showtags.txt') else None
52  config = open(cfg_file).read() if cfg_file else 'NO CONFIGURATION AVAILABLE!'
53  data_html = []
54  for dataset in datasets:
55  dname = dataset.split('_')[0]
56  if not dname in allowedOptions['eventType']:
57  continue
58  pics = [path.split(rel+'/')[1] for path in glob.glob(tauid_dir+dataset+'/*.png')]
59  roots = glob.glob(tauid_dir+dataset+'/*.root')[0]
60  rootf = (roots).split(rel+'/')[1]
61  ref_file = (glob.glob(tauid_dir+'Reference/*'+dname+'.root')[0]).split(rel+'/')[1] if glob.glob(tauid_dir+'Reference/*'+dname+'.root') else None
62  source = 'TauID/'+dataset+'/Config/DataSource_cff.py' if os.path.isfile(tauid_dir+dataset+'/Config/DataSource_cff.py') else None
63  dir_link = 'TauID/'+dataset+'/'
64  data_html.append(templates.usual_validation_dataset_template(dname, rootf, ref_file, dir_link, pics, source) )
65  release_html_page = templates.usual_validation_template.substitute(THIS_RELEASE=rel,CONFIG=config,DATASETS=''.join(data_html) )
66  release_web_page_path = reldir+'index.html' if not options.test else 'index.html'
67  release_page_html = open(release_web_page_path,'w')
68  release_page_html.write(release_html_page)
69  release_page_html.close()
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
double split
Definition: MVATrainer.cc:139