CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/Validation/RecoTau/Tools/RefreshWebPage.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import os
00004 import glob
00005 import sys
00006 import re
00007 import web_templates as templates
00008 from optparse import OptionParser
00009 from Validation.RecoTau.ValidationOptions_cff import allowedOptions
00010 
00011 __author__  = "Mauro Verzetti (mauro.verzetti@cern.ch)"
00012 __doc__ = """Script to update the web-page to show newly updated results. First upload the TauID directory in the proper location in $PastResults"""
00013 
00014 parser = OptionParser(description=__doc__)
00015 parser.add_option('--test',action="store_true", dest="test", default=False, help="used to test/debug the script. The html file are written locally")
00016 (options,crap) = parser.parse_args()
00017 
00018 def unpackRelease(relName):
00019     m = re.match(r'^CMSSW_(?P<one>[0-9]+)_(?P<two>[0-9]+)_(?P<three>[0-9]+)(?:_pre(?P<four>[0-9]+))?',relName)
00020     if m:
00021         prev = int(m.group('four')) if m.group('four') else 1000000
00022         return (m.group('one'),m.group('two'),m.group('three'),prev)
00023     return (0,0)
00024 
00025 try:
00026     webDir = os.environ['PastResults']
00027 except:
00028     print 'Run cmsenv and source UtilityCommands.(c)sh first!'
00029     sys.exit(0)
00030 
00031 webDir           += '/'
00032 webDir_subdirs    = filter( lambda x: os.path.isdir(webDir+x), os.listdir( webDir ) )
00033 official_releases = sorted( filter( lambda x: re.findall(r'^CMSSW_[0-9]+_[0-9]+_[0-9]+(?:_pre[0-9]+)?$',x), webDir_subdirs), key=unpackRelease)
00034 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)
00035 custom_made       = [d for d in webDir_subdirs if not d in official_releases and not d in special_releases]
00036 
00037 
00038 official_releases_links = ''.join([templates.create_main_list_element(d) for d in official_releases])
00039 special_releases_links  = ''.join([templates.create_main_list_element(d) for d in special_releases])
00040 custom_made_links       = ''.join([templates.create_main_list_element(d) for d in custom_made])
00041 main_web_page           = templates.main_page_template % (official_releases_links, special_releases_links, custom_made_links)
00042 main_web_page_path      = webDir+'index.html' if not options.test else 'index.html'
00043 main_web_page_html      = open(main_web_page_path,'w')
00044 main_web_page_html.write(main_web_page)
00045 main_web_page_html.close()
00046 
00047 for rel in official_releases+special_releases:
00048     tauid_dir = webDir+rel+'/TauID/'
00049     reldir    = webDir+rel+'/'
00050     datasets  = filter(lambda x: os.path.isdir(tauid_dir+x) and not x == 'Reference', os.listdir(tauid_dir))
00051     cfg_file  = glob.glob(tauid_dir+'*/Config/showtags.txt')[0] if glob.glob(tauid_dir+'*/Config/showtags.txt') else None
00052     config    = open(cfg_file).read() if cfg_file else 'NO CONFIGURATION AVAILABLE!'
00053     data_html = []
00054     for dataset in datasets:
00055         dname    = dataset.split('_')[0]
00056         if not dname in allowedOptions['eventType']:
00057             continue
00058         pics     = [path.split(rel+'/')[1] for path in glob.glob(tauid_dir+dataset+'/*.png')]
00059         roots    = glob.glob(tauid_dir+dataset+'/*.root')[0]
00060         rootf    = (roots).split(rel+'/')[1]
00061         ref_file = (glob.glob(tauid_dir+'Reference/*'+dname+'.root')[0]).split(rel+'/')[1] if glob.glob(tauid_dir+'Reference/*'+dname+'.root') else None
00062         source   = 'TauID/'+dataset+'/Config/DataSource_cff.py' if os.path.isfile(tauid_dir+dataset+'/Config/DataSource_cff.py') else None
00063         dir_link = 'TauID/'+dataset+'/'
00064         data_html.append(templates.usual_validation_dataset_template(dname, rootf, ref_file, dir_link, pics, source) )
00065     release_html_page     = templates.usual_validation_template.substitute(THIS_RELEASE=rel,CONFIG=config,DATASETS=''.join(data_html) )
00066     release_web_page_path = reldir+'index.html' if not options.test else 'index.html'
00067     release_page_html     = open(release_web_page_path,'w')
00068     release_page_html.write(release_html_page)
00069     release_page_html.close()