Commit f36d8db4 authored by Jérome Perrin's avatar Jérome Perrin

Support new integrity option to replace md5sum

parent 6d809e51
...@@ -27,11 +27,11 @@ Example that installs software:: ...@@ -27,11 +27,11 @@ Example that installs software::
statlib:lib/libfoo.a statlib:lib/libfoo.a
statlib:lib/libfoo.la statlib:lib/libfoo.la
dynlib:bin/foo linked:libbar.so.1,libc.so.6,libfoo.so.1 rpath:${bar:location}/lib,!/lib dynlib:bin/foo linked:libbar.so.1,libc.so.6,libfoo.so.1 rpath:${bar:location}/lib,!/lib
x86 = http://host/path/x86.zip [md5sum] x86 = http://host/path/x86.zip [hashes]
x86-64 = http://host/path/x64.zip [md5sum] x86-64 = http://host/path/x64.zip [hashes]
install = install =
url, md5sum = options[guessPlatform()].split() url, hashes = options[guessPlatform()].split()
extract_dir = self.extract(self.download(url, md5sum)) extract_dir = self.extract(self.download(url, hashes=hashes))
self.copyTree(guessworkdir(extract_dir), location) self.copyTree(guessworkdir(extract_dir), location)
${:update} ${:update}
update = update =
...@@ -134,7 +134,11 @@ filename parameter can be used to change destination named filename. ...@@ -134,7 +134,11 @@ filename parameter can be used to change destination named filename.
destination parameter allows to put explicit destination. destination parameter allows to put explicit destination.
md5sum parameter allows pass md5sum. integrity parameter allow to specify the expected hashes for the downloaded
file, in a format ``algorithm:hash``
md5sum parameter allows pass md5sum. This is deprecated, integrity is
recommended instead.
mode (octal, so for rw-r--r-- use 0644) allows to set mode mode (octal, so for rw-r--r-- use 0644) allows to set mode
......
...@@ -40,6 +40,7 @@ class Recipe(object): ...@@ -40,6 +40,7 @@ class Recipe(object):
self._downloader = zc.buildout.download.Download(buildout_section, self._downloader = zc.buildout.download.Download(buildout_section,
hash_name=True) hash_name=True)
self._url = options['url'] self._url = options['url']
self._integrity = options.get('integrity')
self._md5sum = options.get('md5sum') self._md5sum = options.get('md5sum')
self._name = name self._name = name
mode = options.get('mode') mode = options.get('mode')
...@@ -92,6 +93,9 @@ class Recipe(object): ...@@ -92,6 +93,9 @@ class Recipe(object):
if parts is not None and not os.path.isdir(parts): if parts is not None and not os.path.isdir(parts):
os.mkdir(parts) os.mkdir(parts)
result.append(parts) result.append(parts)
if self._integrity:
path, is_temp = self._downloader(self._url, hashes=self._integrity)
else:
path, is_temp = self._downloader(self._url, md5sum=self._md5sum) path, is_temp = self._downloader(self._url, md5sum=self._md5sum)
with open(path, 'rb') as fsrc: with open(path, 'rb') as fsrc:
if is_temp: if is_temp:
...@@ -112,5 +116,5 @@ class Recipe(object): ...@@ -112,5 +116,5 @@ class Recipe(object):
return result return result
def update(self): def update(self):
if not self._md5sum: if not (self._md5sum or self._integrity):
self.install() self.install()
...@@ -108,6 +108,10 @@ class Recipe: ...@@ -108,6 +108,10 @@ class Recipe:
extract_dir = tempfile.mkdtemp(self.name) extract_dir = tempfile.mkdtemp(self.name)
try: try:
self.logger.debug('Created working directory %r', extract_dir) self.logger.debug('Created working directory %r', extract_dir)
if self.options.get('integrity'):
path, is_temp = download(self.options['url'],
hashes=self.options['integrity'])
else:
path, is_temp = download(self.options['url'], path, is_temp = download(self.options['url'],
md5sum=self.options.get('md5sum')) md5sum=self.options.get('md5sum'))
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment