Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go back to using curl to download snapshots #1347

Merged
merged 3 commits into from
Feb 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ need_cmd sed
need_cmd file
need_cmd cmake
need_cmd pkg-config
need_cmd curl

CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
CFG_BUILD_DIR="$(pwd)/"
Expand Down
22 changes: 7 additions & 15 deletions src/etc/dl-snapshot.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import distutils.spawn
import hashlib
import os
import subprocess
import sys
import tarfile
import shutil

try:
from urllib.request import urlopen
except ImportError:
# We are in python2
from urllib2 import urlopen as urlopen2
from contextlib import closing
urlopen = lambda url: closing(urlopen2(url))

with open('src/snapshots.txt') as f:
lines = f.readlines()

Expand Down Expand Up @@ -77,13 +70,12 @@
if os.path.isdir(dst):
shutil.rmtree(dst)

with urlopen(url) as in_file:
data = in_file.read()
h = hashlib.sha1(data).hexdigest()
if h != hash:
raise Exception("failed to verify the checksum of the snapshot")
with open(dl_path, 'wb') as out_file:
out_file.write(data)
ret = subprocess.call(["curl", "-o", dl_path, url])
if ret != 0:
raise Exception("failed to fetch url")
h = hashlib.sha1(open(dl_path, 'rb').read()).hexdigest()
if h != hash:
raise Exception("failed to verify the checksum of the snapshot")

with tarfile.open(dl_path) as tar:
for p in tar.getnames():
Expand Down