aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--lib/bb/fetch/__init__.py9
-rw-r--r--lib/bb/utils.py31
3 files changed, 33 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 1f89f90fd..1ee7fd363 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -136,6 +136,7 @@ Changes in Bitbake 1.9.x:
- Add bb.runqueue.check_stamp_fn() for use by packaged-staging
- Add PERSISTENT_DIR to store the PersistData in a persistent
directory != the cache dir.
+ - Add md5 and sha256 checksum generation functions to utils.py
Changes in Bitbake 1.8.0:
- Release 1.7.x as a stable series
diff --git a/lib/bb/fetch/__init__.py b/lib/bb/fetch/__init__.py
index c697f4744..c3bea447c 100644
--- a/lib/bb/fetch/__init__.py
+++ b/lib/bb/fetch/__init__.py
@@ -479,14 +479,7 @@ class Fetch(object):
verify_md5sum = staticmethod(verify_md5sum)
def write_md5sum(url, ud, d):
- if bb.which(data.getVar('PATH', d), 'md5sum'):
- try:
- md5pipe = os.popen('md5sum ' + ud.localpath)
- md5data = (md5pipe.readline().split() or [ "" ])[0]
- md5pipe.close()
- except OSError:
- md5data = ""
-
+ md5data = bb.utils.md5_file(ud.localpath)
# verify the md5sum
if not Fetch.verify_md5sum(ud, md5data):
raise MD5SumError(url)
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index c303352c6..17e22e389 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -237,3 +237,34 @@ def unlockfile(lf):
fcntl.flock(lf.fileno(), fcntl.LOCK_UN)
lf.close
+def md5_file(filename):
+ """
+ Return the hex string representation of the MD5 checksum of filename.
+ """
+ try:
+ import hashlib
+ m = hashlib.md5()
+ except ImportError:
+ import md5
+ m = md5.new()
+
+ for line in open(filename):
+ m.update(line)
+ return m.hexdigest()
+
+def sha256_file(filename):
+ """
+ Return the hex string representation of the 256-bit SHA checksum of
+ filename. On Python 2.4 this will return None, so callers will need to
+ handle that by either skipping SHA checks, or running a standalone sha256sum
+ binary.
+ """
+ try:
+ import hashlib
+ except ImportError:
+ return None
+
+ s = hashlib.sha256()
+ for line in open(filename):
+ s.update(line)
+ return s.hexdigest()