test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
dbs_discovery Namespace Reference

Functions

def search
 

Function Documentation

def dbs_discovery.search ( )

Definition at line 10 of file dbs_discovery.py.

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