Commit 2c5978d3 authored by PJ Eby's avatar PJ Eby

Fixed SF downloads aborting when a SF mirror returns an HTML page when it

should've returned a 404.  Fall back to ``sf-mirrors.telecommunity.com``
round-robin address for SF mirrors if ``dl.sourceforge.net`` doesn't work.
(backport from trunk)

--HG--
branch : setuptools-0.6
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4052004
parent 168a7c6e
...@@ -355,6 +355,14 @@ The above example would then allow downloads only from hosts in the ...@@ -355,6 +355,14 @@ The above example would then allow downloads only from hosts in the
``python.org`` and ``myintranet.example.com`` domains, unless overridden on the ``python.org`` and ``myintranet.example.com`` domains, unless overridden on the
command line. command line.
Note that if you want to allow downloads from Sourceforge, you need to enable
the ``dl.sourceforge.net`` host. All Sourceforge mirror downloads are treated
as if they had this hostname. (If a download attempt from
``dl.sourceforge.net`` fails, it is automatically retried using a randomly
selected mirror IP drawn from the ``sf-mirrors.telecommunity.com`` round-robin
addres. The IP's, however, are not checked against the ``--allow-hosts``
mask.)
Installing on Un-networked Machines Installing on Un-networked Machines
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...@@ -1198,6 +1206,10 @@ Release Notes/Change History ...@@ -1198,6 +1206,10 @@ Release Notes/Change History
* Fixed not recogninzing ``win32.exe`` installers that included a custom * Fixed not recogninzing ``win32.exe`` installers that included a custom
bitmap. bitmap.
* Fixed SF downloads aborting when a SF mirror returns an HTML page when it
should've returned a 404. Fall back to ``sf-mirrors.telecommunity.com``
round-robin address for SF mirrors if ``dl.sourceforge.net`` doesn't work.
0.6c3 0.6c3
* You once again use "python -m easy_install" with Python 2.4 and above. * You once again use "python -m easy_install" with Python 2.4 and above.
......
...@@ -533,7 +533,6 @@ class PackageIndex(Environment): ...@@ -533,7 +533,6 @@ class PackageIndex(Environment):
dl_blocksize = 8192 dl_blocksize = 8192
def _download_to(self, url, filename): def _download_to(self, url, filename):
self.url_ok(url,True) # raises error if not allowed
self.info("Downloading %s", url) self.info("Downloading %s", url)
# Download the file # Download the file
fp, tfp, info = None, None, None fp, tfp, info = None, None, None
...@@ -572,9 +571,18 @@ class PackageIndex(Environment): ...@@ -572,9 +571,18 @@ class PackageIndex(Environment):
def reporthook(self, url, filename, blocknum, blksize, size): def reporthook(self, url, filename, blocknum, blksize, size):
pass # no-op pass # no-op
def retry_sf_download(self, url, filename):
def _attempt_download(self, url, filename):
headers = self._download_to(url, filename)
if 'html' in headers['content-type'].lower():
return self._download_html(url, headers, filename)
else:
return filename
def _retry_sf_download(self, url, filename):
self.url_ok(url, True) # raises error if not allowed
try: try:
return self._download_to(url, filename) return self._attempt_download(url, filename)
except (KeyboardInterrupt,SystemExit): except (KeyboardInterrupt,SystemExit):
raise raise
except: except:
...@@ -588,7 +596,9 @@ class PackageIndex(Environment): ...@@ -588,7 +596,9 @@ class PackageIndex(Environment):
self.warn("Download failed: %s", sys.exc_info()[1]) self.warn("Download failed: %s", sys.exc_info()[1])
url = urlparse.urlunparse((scheme, mirror, path, param, '', frag)) url = urlparse.urlunparse((scheme, mirror, path, param, '', frag))
try: try:
return self._download_to(url, filename) return self._attempt_download(url, filename)
except (KeyboardInterrupt,SystemExit):
raise
except: except:
_sf_mirrors.remove(mirror) # don't retry the same mirror _sf_mirrors.remove(mirror) # don't retry the same mirror
mirror = get_sf_ip() mirror = get_sf_ip()
...@@ -603,16 +613,6 @@ class PackageIndex(Environment): ...@@ -603,16 +613,6 @@ class PackageIndex(Environment):
def open_url(self, url): def open_url(self, url):
if url.startswith('file:'): if url.startswith('file:'):
return local_open(url) return local_open(url)
...@@ -648,16 +648,16 @@ class PackageIndex(Environment): ...@@ -648,16 +648,16 @@ class PackageIndex(Environment):
elif scheme=='file': elif scheme=='file':
return urllib2.url2pathname(urlparse.urlparse(url)[2]) return urllib2.url2pathname(urlparse.urlparse(url)[2])
else: else:
headers = self.retry_sf_download(url, filename) return self._retry_sf_download(url, filename)
if 'html' in headers['content-type'].lower():
return self._download_html(url, headers, filename, tmpdir)
else:
return filename
def scan_url(self, url): def scan_url(self, url):
self.process_url(url, True) self.process_url(url, True)
def _download_html(self, url, headers, filename, tmpdir): def _download_html(self, url, headers, filename):
file = open(filename) file = open(filename)
for line in file: for line in file:
if line.strip(): if line.strip():
...@@ -700,7 +700,8 @@ _sf_mirrors = [] ...@@ -700,7 +700,8 @@ _sf_mirrors = []
def get_sf_ip(): def get_sf_ip():
if not _sf_mirrors: if not _sf_mirrors:
try: try:
_sf_mirrors[:] = socket.gethostbyname_ex('dl.sourceforge.net')[-1] _sf_mirrors[:] = socket.gethostbyname_ex(
'sf-mirrors.telecommunity.com')[-1]
except socket.error: except socket.error:
# DNS-bl0ck1n9 f1r3w4llz sUx0rs! # DNS-bl0ck1n9 f1r3w4llz sUx0rs!
_sf_mirrors[:] = ['dl.sourceforge.net'] _sf_mirrors[:] = ['dl.sourceforge.net']
...@@ -734,5 +735,4 @@ def local_open(url): ...@@ -734,5 +735,4 @@ def local_open(url):
# this line is a kludge to keep the trailing blank lines for pje's editor # this line is a kludge to keep the trailing blank lines for pje's editor
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment