ATLAS Offline Software
download.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2 
3 def downloadUsingProxy(url, filename=None):
4  '''Download URL using proxy setup from environment (ATLAS_PROXIES, fallback to FRONTIER_SERVER)'''
5  import os
6  if filename is None:
7  filename = os.path.basename(url)
8  proxyList = []
9  if 'http_proxy' in os.environ:
10  proxyList.append( os.environ['http_proxy'] )
11  elif 'ATLAS_PROXIES' in os.environ:
12  proxyList.extend( os.environ['ATLAS_PROXIES'].split(',') )
13  elif 'FRONTIER_SERVER' in os.environ:
14  frontierConfig = [ conf.lstrip('(') for conf in os.environ['FRONTIER_SERVER'].split(')') ]
15  for conf in frontierConfig:
16  if conf.startswith('proxyurl=http://'):
17  proxyList.append(conf.split('proxyurl=http://')[1])
18  proxyList.append(None) # a last try with no proxy is flagged by None
19  msg = "Found proxy list %s\n" % proxyList
20  for proxy in proxyList:
21  if proxy is not None:
22  os.environ['http_proxy'] = proxy
23  elif 'http_proxy' in os.environ:
24  del os.environ['http_proxy']
25  cmd = "wget --waitretry=5 --tries=3 --connect-timeout=20 --read-timeout=120 -O %s %s" % (filename, url)
26  msg += "Trying to retrieve '%s' using proxy '%s' via: %s\n" % (url, proxy, cmd)
27  import subprocess
28  status, output = subprocess.getstatusoutput(cmd)
29  if status == 0:
30  msg += "Downloaded %s using proxy '%s'\n" % (url, proxy)
31  break
32  else:
33  msg += "Failed to get '%s' via proxy '%s'. exit status=%d, output='%s'\n" % (url, proxy, status, output)
34  if proxy is None:
35  msg += "All download attempts failed"
36  return 1, msg
37  return 0, msg
38 
python.download.downloadUsingProxy
def downloadUsingProxy(url, filename=None)
Definition: download.py:3
Trk::split
@ split
Definition: LayerMaterialProperties.h:38