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