Detect corrupt downloads

This commit is contained in:
Tom Payne
2012-11-09 11:23:51 +01:00
parent bf4e7bcb70
commit df8685638c
2 changed files with 8 additions and 2 deletions

View File

@@ -62,6 +62,7 @@ SRC = [path
if path.endswith('.js')]
PLOVR_JAR = 'bin/plovr-eba786b34df9.jar'
PLOVR_JAR_MD5 = '20eac8ccc4578676511cf7ccbfc65100'
def report_sizes(t):
@@ -205,7 +206,7 @@ pake.virtual('plovr', PLOVR_JAR)
@pake.target(PLOVR_JAR, clean=False)
def plovr_jar(t):
t.download('https://plovr.googlecode.com/files/' + os.path.basename(PLOVR_JAR))
t.download('https://plovr.googlecode.com/files/' + os.path.basename(PLOVR_JAR), md5=PLOVR_JAR_MD5)
@pake.target('gh-pages', 'hostexamples', 'doc', phony=True)

View File

@@ -2,6 +2,7 @@
import collections
import contextlib
import hashlib
import logging
import optparse
import os
@@ -126,8 +127,12 @@ class Target(object):
def debug(self, *args, **kwargs):
self.logger.debug(*args, **kwargs)
def download(self, url):
def download(self, url, md5=None):
content = urllib2.urlopen(url).read()
if md5 and hashlib.md5(content).hexdigest() != md5:
raise pake.BuildError(t, 'corrupt download')
# FIXME Python on Windoze corrupts the content when writing it
# FIXME probably something to do with encodings
with open(self.name, 'w') as f:
f.write(content)