[jhbuild] use md5sum when available and Python doesn't have hashlib
- From: Frederic Peters <fpeters src gnome org>
- To: svn-commits-list gnome org
- Subject: [jhbuild] use md5sum when available and Python doesn't have hashlib
- Date: Wed, 15 Jul 2009 17:48:11 +0000 (UTC)
commit 5ee3512f5f9724e5f0fd15e2b03ff82b07f45fcc
Author: Frédéric Péters <fpeters 0d be>
Date: Wed Jul 15 19:46:08 2009 +0200
use md5sum when available and Python doesn't have hashlib
jhbuild/modtypes/tarball.py | 7 ++++++-
jhbuild/versioncontrol/tarball.py | 27 +++++++++++++++++----------
2 files changed, 23 insertions(+), 11 deletions(-)
---
diff --git a/jhbuild/modtypes/tarball.py b/jhbuild/modtypes/tarball.py
index 47eabf5..70d797a 100644
--- a/jhbuild/modtypes/tarball.py
+++ b/jhbuild/modtypes/tarball.py
@@ -22,6 +22,11 @@ __metaclass__ = type
import sys
import logging
+try:
+ import hashlib
+except ImportError:
+ hashlib = None
+
from jhbuild.modtypes import register_module_type, get_dependencies
def parse_tarball(node, config, uri, repositories, default_repo):
@@ -64,7 +69,7 @@ def parse_tarball(node, config, uri, repositories, default_repo):
'module': name, 'size': childnode.getAttribute('size')})
if childnode.hasAttribute('md5sum'):
source_hash = 'md5:' + childnode.getAttribute('md5sum')
- if childnode.hasAttribute('hash'):
+ if childnode.hasAttribute('hash') and hashlib:
source_hash = childnode.getAttribute('hash')
elif childnode.nodeName == 'patches':
for patch in childnode.childNodes:
diff --git a/jhbuild/versioncontrol/tarball.py b/jhbuild/versioncontrol/tarball.py
index 0bb3cce..3ca89c9 100644
--- a/jhbuild/versioncontrol/tarball.py
+++ b/jhbuild/versioncontrol/tarball.py
@@ -21,12 +21,14 @@ __all__ = []
__metaclass__ = type
import os
+import md5
try:
import hashlib
except ImportError:
import md5 as hashlib
import urlparse
import urllib2
+import logging
from jhbuild.errors import FatalError, CommandError, BuildStateError
from jhbuild.versioncontrol import Repository, Branch, register_repo_type
@@ -70,7 +72,7 @@ class TarballRepository(Repository):
module = urlparse.urljoin(self.href, module)
if size is not None:
size = int(size)
- if md5sum:
+ if md5sum and (not hash or hashlib is md5):
hash = 'md5:' + md5sum
return TarballBranch(self, module=module, version=version,
checkoutdir=checkoutdir,
@@ -167,16 +169,21 @@ class TarballBranch(Branch):
% {'size1':self.source_size, 'size2':local_size})
if self.source_hash is not None:
algo, hash = self.source_hash.split(':')
- local_hash = getattr(hashlib, algo)()
- fp = open(localfile, 'rb')
- data = fp.read(32768)
- while data:
- local_hash.update(data)
+ if hasattr(hashlib, algo):
+ local_hash = getattr(hashlib, algo)()
+
+ fp = open(localfile, 'rb')
data = fp.read(32768)
- fp.close()
- if local_hash.hexdigest() != hash:
- raise BuildStateError(_('file hash is incorrect (expected %(sum1)s, got %(sum2)s)')
- % {'sum1':hash, 'sum2':local_hash.hexdigest()})
+ while data:
+ local_hash.update(data)
+ data = fp.read(32768)
+ fp.close()
+ if local_hash.hexdigest() != hash:
+ raise BuildStateError(
+ _('file hash is incorrect (expected %(sum1)s, got %(sum2)s)')
+ % {'sum1':hash, 'sum2':local_hash.hexdigest()})
+ else:
+ logging.warning(_('skipped hash check (missing support for %s)') % algo)
def _download_and_unpack(self, buildscript):
localfile = self._local_tarball
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]