diff options
author | Richard Purdie <rpurdie@linux.intel.com> | 2008-05-12 14:21:36 +0000 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2008-05-12 14:21:36 +0000 |
commit | 4c0b17f16b58b3fad56bc6c3857c411ce58992e4 (patch) | |
tree | 8b6519ba1bc7de0477d3dd39ea1b275b52849492 | |
parent | 35c3263578d2120d534444fa5e81d845ad9208cb (diff) | |
download | bitbake-4c0b17f16b58b3fad56bc6c3857c411ce58992e4.tar.gz |
utils.py: Add md5 and sha256 checksum generation functions from Ross Burton (via Poky)
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | lib/bb/fetch/__init__.py | 9 | ||||
-rw-r--r-- | lib/bb/utils.py | 31 |
3 files changed, 33 insertions, 8 deletions
@@ -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() |