Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:49

0001 #! /usr/bin/env python3
0002 ################################################################################
0003 # RelMon: a tool for automatic Release Comparison                              
0004 # https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
0005 #
0006 #
0007 #                                                                              
0008 # Danilo Piparo CERN - danilo.piparo@cern.ch                                   
0009 #                                                                              
0010 ################################################################################
0011 
0012 """
0013 Just a draft of the real program...It is very ugly still.
0014 """
0015 from __future__ import print_function
0016 
0017 
0018 from os.path import basename
0019 from optparse import OptionParser
0020 from re import search
0021 from sys import exit
0022 from urllib2  import Request,build_opener,urlopen
0023 
0024 import os
0025 if "RELMON_SA" in os.environ:
0026   from authentication import X509CertOpen
0027   from definitions import server
0028   from utils import wget  
0029 else:  
0030   from Utilities.RelMon.authentication import X509CertOpen
0031   from Utilities.RelMon.definitions import server
0032   from Utilities.RelMon.utils import wget
0033 
0034 def extract_list(page_html,the_server,display_url):
0035   contents=[]  
0036   for line in page_html.split("<tr><td>")[1:]:
0037     name=""
0038     #link
0039     link_start=line.find("href='")+6
0040     link_end=line.find("'>")    
0041     #name
0042     name_start=link_end+2
0043     name_end=line.find("</a>")
0044     if display_url:
0045       contents.append(the_server+line[link_start:link_end])
0046     else:
0047       contents.append(line[name_start:name_end])
0048   return contents
0049     
0050 def get_page(url):
0051   """ Get the web page listing the rootfiles. Use the X509 auth.
0052   """  
0053   opener=build_opener(X509CertOpen())  
0054   datareq = Request(url)
0055   datareq.add_header('authenticated_wget', "The ultimate wgetter")    
0056   filename=basename(url)  
0057   return opener.open(datareq).read()
0058 
0059 if __name__=="__main__":
0060 
0061   parser = OptionParser(usage="usage: %prog [options] dirtolist")
0062 
0063   parser.add_option("-d","--dev",
0064                   action="store_true",
0065                   dest="development",
0066                   default=False,
0067                   help="Select the development GUI instance.")
0068 
0069   parser.add_option("--offline",
0070                   action="store_true",
0071                   dest="offline",
0072                   default=False,
0073                   help="Select the Offline GUI instance.")
0074                   
0075   parser.add_option("-o","--online",
0076                   action="store_true",
0077                   dest="online",
0078                   default=False,
0079                   help="Select the Online GUI instance.")
0080 
0081   parser.add_option("-r","--relval",
0082                   action="store_true",
0083                   dest="relval",
0084                   default=True,
0085                   help="Select the RelVal GUI instance.")
0086 
0087   parser.add_option("-u","--show_url",
0088                   action="store_true",
0089                   dest="show_url",
0090                   default=False,
0091                   help="Show the full URL of the file.")
0092 
0093   parser.add_option("-g","--get",
0094                   action="store_true",
0095                   dest="get",
0096                   default=False,
0097                   help="Get the files.")
0098 
0099   parser.add_option("-p","--path",
0100                   action="store",
0101                   dest="path",
0102                   default="",
0103                   help="The path to be matched before getting.")
0104 
0105   (options, args) = parser.parse_args()
0106 
0107   if not(options.development or options.offline or options.online or options.relval):
0108     print("Select development or online instance!")
0109     exit(-1)
0110 
0111   lenargs=len(args)
0112   if lenargs>1:
0113     print("Please specify only one directory to list!")
0114     exit(-1)
0115 
0116   dirtolist=""
0117   if lenargs==1:
0118     dirtolist=args[0]
0119   
0120   mode="relval"
0121   if options.online:
0122     mode="online"
0123   if options.development:
0124     mode="dev"
0125   
0126     
0127   directory="%s/dqm/%s/data/browse/%s" %(server,mode,dirtolist)
0128   print("peeping ",directory)  
0129   contents=extract_list(get_page(directory),server,options.show_url)
0130   
0131   if len(contents)==0:
0132     print("No contents found!")
0133   
0134   for content in contents:
0135     if not options.get and search(options.path,content):
0136       print(content)
0137     if options.get and options.show_url and len(options.path)>0 and search(options.path,content):
0138       if not search('pre',options.path) and search('pre',content):
0139         continue
0140       bcontent=basename(content)
0141       print("Getting %s" %bcontent)
0142       wget(content)
0143       print("Got %s!!" %bcontent)
0144   
0145