aboutsummaryrefslogtreecommitdiffstats
path: root/python/servo
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-04-07 14:06:54 +0530
committerbors-servo <lbergstrom+bors@mozilla.com>2016-04-07 14:06:54 +0530
commite431bda9ea6c8a79c98d98668dd934fafd4f7092 (patch)
tree4762392fde6b96afd9680946f7638416e53c4ba6 /python/servo
parent1a6245828a96e3afda8eb8661df0834fde3dfea6 (diff)
parent78b2c5d3235cbaaed57d7f47e8b3616e6e4cfdbe (diff)
downloadservo-e431bda9ea6c8a79c98d98668dd934fafd4f7092.tar.gz
servo-e431bda9ea6c8a79c98d98668dd934fafd4f7092.zip
Auto merge of #10442 - autrilla:mach-caching, r=Wafflespeanut
Issue #10441: Added caching support to mach bootstrap As suggested on the issue, files are stored as `.part` and moved to the original name when done. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10442) <!-- Reviewable:end -->
Diffstat (limited to 'python/servo')
-rw-r--r--python/servo/bootstrap_commands.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/python/servo/bootstrap_commands.py b/python/servo/bootstrap_commands.py
index edd1e84dde0..f7da1d60318 100644
--- a/python/servo/bootstrap_commands.py
+++ b/python/servo/bootstrap_commands.py
@@ -29,18 +29,23 @@ from mach.decorators import (
from servo.command_base import CommandBase, host_triple, BIN_SUFFIX
-def download(desc, src, writer):
- print("Downloading %s..." % desc)
+def download(desc, src, writer, start_byte=0):
+ if start_byte:
+ print("Resuming download of %s..." % desc)
+ else:
+ print("Downloading %s..." % desc)
dumb = (os.environ.get("TERM") == "dumb") or (not sys.stdout.isatty())
try:
+ if start_byte:
+ src = urllib2.Request(src, headers={'Range': 'bytes={}-'.format(start_byte)})
resp = urllib2.urlopen(src)
fsize = None
if resp.info().getheader('Content-Length'):
- fsize = int(resp.info().getheader('Content-Length').strip())
+ fsize = int(resp.info().getheader('Content-Length').strip()) + start_byte
- recved = 0
+ recved = start_byte
chunk_size = 8192
while True:
@@ -61,11 +66,21 @@ def download(desc, src, writer):
except urllib2.HTTPError, e:
print("Download failed (%d): %s - %s" % (e.code, e.reason, src))
sys.exit(1)
+ except KeyboardInterrupt:
+ writer.flush()
+ raise
def download_file(desc, src, dst):
- with open(dst, 'wb') as fd:
- download(desc, src, fd)
+ tmp_path = dst + ".part"
+ try:
+ start_byte = os.path.getsize(tmp_path)
+ with open(tmp_path, 'ab') as fd:
+ download(desc, src, fd, start_byte=start_byte)
+ except os.error:
+ with open(tmp_path, 'wb') as fd:
+ download(desc, src, fd)
+ os.rename(tmp_path, dst)
def download_bytes(desc, src):