ATLAS Offline Software
download.py
Go to the documentation of this file.
1 from future import standard_library
2 standard_library.install_aliases()
3 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
4 
5 def downloadUsingProxy(url, filename=None):
6  '''Download URL using proxy setup from environment (ATLAS_PROXIES, fallback to FRONTIER_SERVER)'''
7  import os
8  if filename is None:
9  filename = os.path.basename(url)
10  proxyList = []
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) # a last try with no proxy is flagged by None
21  msg = "Found proxy list %s\n" % proxyList
22  for proxy in proxyList:
23  if proxy is not None:
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)
29  import subprocess
30  status, output = subprocess.getstatusoutput(cmd)
31  if status == 0:
32  msg += "Downloaded %s using proxy '%s'\n" % (url, proxy)
33  break
34  else:
35  msg += "Failed to get '%s' via proxy '%s'. exit status=%d, output='%s'\n" % (url, proxy, status, output)
36  if proxy is None:
37  msg += "All download attempts failed"
38  return 1, msg
39  return 0, msg
40 
python.download.downloadUsingProxy
def downloadUsingProxy(url, filename=None)
Definition: download.py:5
Trk::split
@ split
Definition: LayerMaterialProperties.h:38