CMS 3D CMS Logo

Functions
dbs_discovery Namespace Reference

Functions

def search ()
 

Function Documentation

def dbs_discovery.search ( )

Definition at line 10 of file dbs_discovery.py.

10 def search():
11 
12  if os.environ['DBS_LIKE'] == "LOCAL":
13  fileIn = open("Listfiles.txt","r")
14  line = fileIn.readline()
15  result = []
16  while line:
17  for fragment in line.split("\n"):
18  if fragment != "":
19  result.append(fragment)
20  line = fileIn.readline()
21  else:
22  url = "https://cmsweb.cern.ch:443/dbs_discovery/aSearch"
23  input = "find file where release = " + os.environ['DBS_RELEASE']
24  input = input + " and primds = " + os.environ['DBS_SAMPLE']
25  input = input + " and dataset like " + os.environ['DBS_LIKE']
26  final_input = urllib.quote(input) ;
27 
28  agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
29  ctypes = "text/plain"
30  headers = { 'User-Agent':agent, 'Accept':ctypes}
31  params = {'dbsInst':'cms_dbs_prod_global',
32  'html':0,'caseSensitive':'on','_idx':0,'pagerStep':-1,
33  'userInput':final_input,
34  'xml':0,'details':0,'cff':0,'method':'dbsapi'}
35  data = urllib.urlencode(params,doseq=True)
36  req = urllib2.Request(url, data, headers)
37  data = ""
38 
39  try:
40  response = urllib2.urlopen(req)
41  data = response.read()
42  except urllib2.HTTPError as e:
43  if e.code==201:
44  print e.headers
45  print e.msg
46  pass
47  else:
48  raise e
49 
50  result = []
51  for line in data.split("\n"):
52  if line != "" and line[0] =="/":
53  result.append(line)
54 
55  return result
56