CMS 3D CMS Logo

dbs_discovery.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 import httplib, urllib, urllib2, types, string, os, sys
5 
6 # return the list of files obtained from the data discovery and based upon environnement variables:
7 # DBS_RELEASE, for example CMSSW_2_2_0_pre1
8 # DBS_SAMPLE, for example RelValSingleElectronPt35
9 # DBS_LIKE , for example *RECO
10 
11 def search():
12 
13  if os.environ['DBS_LIKE'] == "LOCAL":
14  fileIn = open("Listfiles.txt","r")
15  line = fileIn.readline()
16  result = []
17  while line:
18  for fragment in line.split("\n"):
19  if fragment != "":
20  result.append(fragment)
21  line = fileIn.readline()
22  else:
23  url = "https://cmsweb.cern.ch:443/dbs_discovery/aSearch"
24  input = "find file where release = " + os.environ['DBS_RELEASE']
25  input = input + " and primds = " + os.environ['DBS_SAMPLE']
26  input = input + " and dataset like " + os.environ['DBS_LIKE']
27  final_input = urllib.quote(input) ;
28 
29  agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
30  ctypes = "text/plain"
31  headers = { 'User-Agent':agent, 'Accept':ctypes}
32  params = {'dbsInst':'cms_dbs_prod_global',
33  'html':0,'caseSensitive':'on','_idx':0,'pagerStep':-1,
34  'userInput':final_input,
35  'xml':0,'details':0,'cff':0,'method':'dbsapi'}
36  data = urllib.urlencode(params,doseq=True)
37  req = urllib2.Request(url, data, headers)
38  data = ""
39 
40  try:
41  response = urllib2.urlopen(req)
42  data = response.read()
43  except urllib2.HTTPError as e:
44  if e.code==201:
45  print(e.headers)
46  print(e.msg)
47  pass
48  else:
49  raise e
50 
51  result = []
52  for line in data.split("\n"):
53  if line != "" and line[0] =="/":
54  result.append(line)
55 
56  return result
57 
58 if __name__ == "__main__":
59  for file in search():
60  print(file)
61 
62 
63 
64 
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
dbs_discovery.search
def search()
Definition: dbs_discovery.py:11