CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
relmon_rootfiles_spy.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 ################################################################################
3 # RelMon: a tool for automatic Release Comparison
4 # https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
5 #
6 #
7 #
8 # Danilo Piparo CERN - danilo.piparo@cern.ch
9 #
10 ################################################################################
11 
12 """
13 Just a draft of the real program...It is very ugly still.
14 """
15 
16 
17 from os.path import basename
18 from optparse import OptionParser
19 from re import search
20 from sys import exit
21 from urllib2 import Request,build_opener,urlopen
22 
23 import os
24 if os.environ.has_key("RELMON_SA"):
25  from authentication import X509CertOpen
26  from definitions import server
27  from utils import wget
28 else:
29  from Utilities.RelMon.authentication import X509CertOpen
30  from Utilities.RelMon.definitions import server
31  from Utilities.RelMon.utils import wget
32 
33 def extract_list(page_html,the_server,display_url):
34  contents=[]
35  for line in page_html.split("<tr><td>")[1:]:
36  name=""
37  #link
38  link_start=line.find("href='")+6
39  link_end=line.find("'>")
40  #name
41  name_start=link_end+2
42  name_end=line.find("</a>")
43  if display_url:
44  contents.append(the_server+line[link_start:link_end])
45  else:
46  contents.append(line[name_start:name_end])
47  return contents
48 
49 def get_page(url):
50  """ Get the web page listing the rootfiles. Use the X509 auth.
51  """
52  opener=build_opener(X509CertOpen())
53  datareq = Request(url)
54  datareq.add_header('authenticated_wget', "The ultimate wgetter")
55  filename=basename(url)
56  return opener.open(datareq).read()
57 
58 if __name__=="__main__":
59 
60  parser = OptionParser(usage="usage: %prog [options] dirtolist")
61 
62  parser.add_option("-d","--dev",
63  action="store_true",
64  dest="development",
65  default=False,
66  help="Select the development GUI instance.")
67 
68  parser.add_option("--offline",
69  action="store_true",
70  dest="offline",
71  default=False,
72  help="Select the Offline GUI instance.")
73 
74  parser.add_option("-o","--online",
75  action="store_true",
76  dest="online",
77  default=False,
78  help="Select the Online GUI instance.")
79 
80  parser.add_option("-r","--relval",
81  action="store_true",
82  dest="relval",
83  default=True,
84  help="Select the RelVal GUI instance.")
85 
86  parser.add_option("-u","--show_url",
87  action="store_true",
88  dest="show_url",
89  default=False,
90  help="Show the full URL of the file.")
91 
92  parser.add_option("-g","--get",
93  action="store_true",
94  dest="get",
95  default=False,
96  help="Get the files.")
97 
98  parser.add_option("-p","--path",
99  action="store",
100  dest="path",
101  default="",
102  help="The path to be matched before getting.")
103 
104  (options, args) = parser.parse_args()
105 
106  if not(options.development or options.offline or options.online or options.relval):
107  print "Select development or online instance!"
108  exit(-1)
109 
110  lenargs=len(args)
111  if lenargs>1:
112  print "Please specify only one directory to list!"
113  exit(-1)
114 
115  dirtolist=""
116  if lenargs==1:
117  dirtolist=args[0]
118 
119  mode="relval"
120  if options.online:
121  mode="online"
122  if options.development:
123  mode="dev"
124 
125 
126  directory="%s/dqm/%s/data/browse/%s" %(server,mode,dirtolist)
127  print "peeping ",directory
128  contents=extract_list(get_page(directory),server,options.show_url)
129 
130  if len(contents)==0:
131  print "No contents found!"
132 
133  for content in contents:
134  if not options.get and search(options.path,content):
135  print content
136  if options.get and options.show_url and len(options.path)>0 and search(options.path,content):
137  if not search('pre',options.path) and search('pre',content):
138  continue
139  bcontent=basename(content)
140  print "Getting %s" %bcontent
141  wget(content)
142  print "Got %s!!" %bcontent
143 
144 
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:224
def wget
Definition: utils.py:448