Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
68 lines (60 sloc) 3.41 KB
# This file allows developers working in the git repository to fetch
# binary files from SVN (or other site) so that the git repository
# doesn't have to track large files.
import os.path
import hashlib
import urllib2
import shutil
import sys
# The list of files (relative path) to fetch, their SHA1, and their source URL.
files = [
[['bioformats', 'loci_tools.jar'], 'a1d08a9dfb648eb86290a036fe0b5a4e47f2c44a', '!svn/bc/11312/trunk/CellProfiler/bioformats/loci_tools.jar'],
[['imagej', 'ij.jar'], 'f675dc28e38a9a2612e55db049f4d4bb47d774b1', '!svn/bc/11073/trunk/CellProfiler/imagej/ij.jar'],
[['imagej', 'imglib.jar'], '7e0e68aa371706012e224df0b31925317a3dc284', '!svn/bc/11073/trunk/CellProfiler/imagej/imglib.jar'],
[['imagej', 'javacl-1.0-beta-4-shaded.jar'], '62b3b41c4759652595070534d79d1294eeba8139', '!svn/bc/11073/trunk/CellProfiler/imagej/javacl-1.0-beta-4-shaded.jar'],
[['imagej', 'junit-4.5.jar'], '41eb8ac5586d163d61518be18a13626983f9ece6', '!svn/bc/11073/trunk/CellProfiler/imagej/junit-4.5.jar'],
[['imagej', 'precompiled_headless.jar'], '39ef36e6cfbd7f48e8c0e3033b30b0e3f5b5d24e', '!svn/bc/11073/trunk/CellProfiler/imagej/precompiled_headless.jar'],
[['imagej', 'imagej-2.0-SNAPSHOT-all.jar'], '78de1c8c2fc32a4ea17998cb7c2e56f0d1a7f241', '!svn/bc/11495/trunk/CellProfiler/imagej/imagej-2.0-SNAPSHOT-all.jar']
def filehash(filename):
sha1 = hashlib.sha1()
f = open(filename, 'rb')
for chunk in iter(lambda:, ''):
return sha1.hexdigest()
return ''
def fetchfile(filename, url):
print "fetching %s to %s"%(url, filename)
# no try/except, it's wrapped below, and we just fail and whine to the user.
src = urllib2.urlopen(url)
dest = open(filename, 'wb')
shutil.copyfileobj(src, dest)
def fetch_external_dependencies(overwrite=False):
# look for each file, check its hash, download if missing, or out
# of date if overwrite==True, complain if it fails. If overwrite
# is 'fail', die on mismatches hashes.
root = os.path.split(__file__)[0]
for path, hash, url in files:
path = os.path.join(root, *path)
assert os.path.isfile(path)
if overwrite == True:
assert filehash(path) == hash
if filehash(path) != hash:
sys.stderr.write("Warning: hash of depenency %s does not match expected value.\n"%(path))
if overwrite == 'fail':
raise RuntimeError('Mismatched hash for %s'%(path))
except AssertionError, e:
# fetch the file
fetchfile(path, url)
assert os.path.isfile(path)
assert filehash(path) == hash, 'Hashes do not match!'
import traceback
sys.stderr.write("Could not fetch external binary dependency %s from %s. Some functionality may be missing. You might try installing it by hand.\n"%(path, url))
Something went wrong with that request. Please try again.