File indexing completed on 2024-04-06 12:09:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 from __future__ import print_function
0026 import httplib, urllib, urllib2, types, string, os, sys
0027
0028 if 'DBS_RELEASE' not in os.environ:
0029 os.environ['DBS_RELEASE'] = "Any"
0030 if 'DBS_SAMPLE' not in os.environ:
0031 os.environ['DBS_SAMPLE'] = "Any"
0032 if 'DBS_RUN' not in os.environ:
0033 os.environ['DBS_RUN'] = "Any"
0034
0035 def common_search(dbs_tier):
0036
0037 if os.environ['DBS_RELEASE'] == "LOCAL":
0038 result = []
0039 for line in open('dbs_discovery.txt').readlines():
0040 line = line.strip()
0041 if line == "": continue
0042 if os.environ['DBS_SAMPLE'] != "Any" and line.find(os.environ['DBS_SAMPLE'])== -1: continue
0043 if line.find(os.environ['DBS_COND'])== -1: continue
0044 if line.find(dbs_tier)== -1: continue
0045 result.append('file:'+line)
0046 else:
0047 input = "find file"
0048 separator = " where "
0049 if os.environ['DBS_RELEASE'] != "Any":
0050 input = input + separator + "release = " + os.environ['DBS_RELEASE']
0051 separator = " and "
0052 if os.environ['DBS_SAMPLE'] != "Any":
0053 input = input + separator + "primds = " + os.environ['DBS_SAMPLE']
0054 separator = " and "
0055 if os.environ['DBS_RUN'] != "Any":
0056 input = input + separator + "run = " + os.environ['DBS_RUN']
0057 separator = " and "
0058 input = input + separator + "dataset like *" + os.environ['DBS_COND'] + "*" + dbs_tier + "*"
0059
0060 url = "https://cmsweb.cern.ch:443/dbs_discovery/aSearch"
0061 final_input = urllib.quote(input) ;
0062
0063 agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
0064 ctypes = "text/plain"
0065 headers = { 'User-Agent':agent, 'Accept':ctypes}
0066 params = {'dbsInst':'cms_dbs_prod_global',
0067 'html':0,'caseSensitive':'on','_idx':0,'pagerStep':-1,
0068 'userInput':final_input,
0069 'xml':0,'details':0,'cff':0,'method':'dbsapi'}
0070 data = urllib.urlencode(params,doseq=True)
0071 req = urllib2.Request(url, data, headers)
0072 data = ""
0073
0074 try:
0075 response = urllib2.urlopen(req)
0076 data = response.read()
0077 except urllib2.HTTPError as e:
0078 if e.code==201:
0079 print(e.headers)
0080 print(e.msg)
0081 pass
0082 else:
0083 raise e
0084
0085 result = []
0086 for line in data.split("\n"):
0087 if line != "" and line[0] =="/":
0088 result.append(line)
0089
0090 return result
0091
0092 def search():
0093 return common_search(os.environ['DBS_TIER'])
0094
0095 def search2():
0096 return common_search(os.environ['DBS_TIER_SECONDARY'])
0097
0098 if __name__ == "__main__":
0099 if 'DBS_TIER_SECONDARY' not in os.environ:
0100 os.environ['DBS_TIER_SECONDARY'] = ""
0101 if os.environ['DBS_TIER_SECONDARY'] == "":
0102 for file in search():
0103 print(file)
0104 else:
0105 for file in search():
0106 print("primary:"+file)
0107 for file in search2():
0108 print("secondary:"+file)
0109
0110
0111
0112