diff options
author | Damien <damien@dam.io> | 2015-04-14 10:13:15 +0200 |
---|---|---|
committer | Damien <damien@dam.io> | 2015-04-14 10:13:15 +0200 |
commit | 1ee479707b97b732e3791345df558a8a70201431 (patch) | |
tree | 82c3cbe261d3a1e541ab1d5d9bec811f7550a912 /python | |
parent | b7f59a36461e6c9eb08b8e48760168d3cb26a400 (diff) | |
download | servo-1ee479707b97b732e3791345df558a8a70201431.tar.gz servo-1ee479707b97b732e3791345df558a8a70201431.zip |
Handle proxies in boostrap script
The urllib version used a `FancyURLOpener` which use urllib. But urllib does not not handle proxies with SSL well.
A better solution would be to use `requests` but I prefer to stay with the "no-dependency" approach.
Diffstat (limited to 'python')
-rw-r--r-- | python/servo/bootstrap_commands.py | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/python/servo/bootstrap_commands.py b/python/servo/bootstrap_commands.py index b59b7fed929..afb054ebddc 100644 --- a/python/servo/bootstrap_commands.py +++ b/python/servo/bootstrap_commands.py @@ -6,7 +6,7 @@ import shutil import subprocess import sys import tarfile -import urllib +import urllib2 from mach.decorators import ( CommandArgument, @@ -16,33 +16,40 @@ from mach.decorators import ( from servo.command_base import CommandBase, cd, host_triple -class PanickyUrlOpener(urllib.FancyURLopener): - def http_error_default(self, url, fp, errcode, errmsg, headers): - print("Download failed (%d): %s - %s" % (errcode, errmsg, url)) - - cpu_type = subprocess.check_output(["uname", "-m"]).strip().lower() - if errcode == 404 and cpu_type in ["i386", "i486", "i686", "i768", "x86"]: - # i686 - print("Note: Servo does not currently bootstrap 32bit snapshots of Rust") - print("See https://github.com/servo/servo/issues/3899") - - sys.exit(1) def download(desc, src, dst): - recved = [0] - - def report(count, bsize, fsize): - recved[0] += bsize - pct = recved[0] * 100.0 / fsize - print("\rDownloading %s: %5.1f%%" % (desc, pct), end="") - sys.stdout.flush() - print("Downloading %s..." % desc) dumb = (os.environ.get("TERM") == "dumb") or (not sys.stdout.isatty()) - PanickyUrlOpener().retrieve(src, dst, None if dumb else report) - if not dumb: - print() + try: + resp = urllib2.urlopen(src) + fsize = int(resp.info().getheader('Content-Length').strip()) + recved = 0 + chunk_size = 8192 + + with open(dst, 'wb') as fd: + while True: + chunk = resp.read(chunk_size) + if not chunk: break + recved += len(chunk) + if not dumb: + pct = recved * 100.0 / fsize + print("\rDownloading %s: %5.1f%%" % (desc, pct), end="") + sys.stdout.flush() + fd.write(chunk) + + if not dumb: + print() + except urllib2.HTTPError, e: + print("Download failed (%d): %s - %s" % (e.code, e.reason, src)) + + cpu_type = subprocess.check_output(["uname", "-m"]).strip().lower() + if e.code == 404 and cpu_type in ["i386", "i486", "i686", "i768", "x86"]: + # i686 + print("Note: Servo does not currently bootstrap 32bit snapshots of Rust") + print("See https://github.com/servo/servo/issues/3899") + + sys.exit(1) def extract(src, dst, movedir=None): tarfile.open(src).extractall(dst) |