6 '''Download URL using proxy setup from environment (ATLAS_PROXIES, fallback to FRONTIER_SERVER)'''
9 filename = os.path.basename(url)
11 if 'http_proxy' in os.environ:
12 proxyList.append( os.environ[
'http_proxy'] )
13 elif 'ATLAS_PROXIES' in os.environ:
14 proxyList.extend( os.environ[
'ATLAS_PROXIES'].
split(
',') )
15 elif 'FRONTIER_SERVER' in os.environ:
16 frontierConfig = [ conf.lstrip(
'(')
for conf
in os.environ[
'FRONTIER_SERVER'].
split(
')') ]
17 for conf
in frontierConfig:
18 if conf.startswith(
'proxyurl=http://'):
19 proxyList.append(conf.split(
'proxyurl=http://')[1])
20 proxyList.append(
None)
21 msg =
"Found proxy list %s\n" % proxyList
22 for proxy
in proxyList:
24 os.environ[
'http_proxy'] = proxy
25 elif 'http_proxy' in os.environ:
26 del os.environ[
'http_proxy']
27 cmd =
"wget --waitretry=5 --tries=3 --connect-timeout=20 --read-timeout=120 -O %s %s" % (filename, url)
28 msg +=
"Trying to retrieve '%s' using proxy '%s' via: %s\n" % (url, proxy, cmd)
30 status, output = subprocess.getstatusoutput(cmd)
32 msg +=
"Downloaded %s using proxy '%s'\n" % (url, proxy)
35 msg +=
"Failed to get '%s' via proxy '%s'. exit status=%d, output='%s'\n" % (url, proxy, status, output)
37 msg +=
"All download attempts failed"