File indexing completed on 2024-04-06 12:24:50
0001
0002
0003 from __future__ import print_function
0004 import httplib, urllib, urllib2, types, string, os, sys
0005
0006
0007
0008
0009
0010
0011
0012 def search():
0013
0014 if os.environ['DBS_RELEASE'] == "LOCAL":
0015 result = []
0016 for line in open('dbs_discovery.txt').readlines():
0017 line = line.strip()
0018 if line == "": continue
0019 if line.find(os.environ['DBS_SAMPLE'])== -1: continue
0020 if line.find(os.environ['DBS_COND'])== -1: continue
0021 if line.find(os.environ['DBS_TIER'])== -1: continue
0022 result.append('file:'+line)
0023 else:
0024 url = "https://cmsweb.cern.ch:443/dbs_discovery/aSearch"
0025 if os.environ['DBS_RELEASE'] != "Any":
0026 input = "find file where release = " + os.environ['DBS_RELEASE']
0027 if os.environ['DBS_SAMPLE'] != "Any":
0028 input = input + " and primds = " + os.environ['DBS_SAMPLE']
0029 input = input + " and dataset like *" + os.environ['DBS_COND'] + "*" + os.environ['DBS_TIER'] + "*"
0030 final_input = urllib.quote(input) ;
0031
0032 agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
0033 ctypes = "text/plain"
0034 headers = { 'User-Agent':agent, 'Accept':ctypes}
0035 params = {'dbsInst':'cms_dbs_prod_global',
0036 'html':0,'caseSensitive':'on','_idx':0,'pagerStep':-1,
0037 'userInput':final_input,
0038 'xml':0,'details':0,'cff':0,'method':'dbsapi'}
0039 data = urllib.urlencode(params,doseq=True)
0040 req = urllib2.Request(url, data, headers)
0041 data = ""
0042
0043 try:
0044 response = urllib2.urlopen(req)
0045 data = response.read()
0046 except urllib2.HTTPError as e:
0047 if e.code==201:
0048 print(e.headers)
0049 print(e.msg)
0050 pass
0051 else:
0052 raise e
0053
0054 result = []
0055 for line in data.split("\n"):
0056 if line != "" and line[0] =="/":
0057 result.append(line)
0058
0059 return result
0060
0061 if __name__ == "__main__":
0062 for file in search():
0063 print(file)
0064
0065
0066
0067