summaryrefslogtreecommitdiff
path: root/bitbake
diff options
context:
space:
mode:
authorRoss Burton <ross@openedhand.com>2008-05-01 10:59:00 +0000
committerRoss Burton <ross@openedhand.com>2008-05-01 10:59:00 +0000
commita74658d4ed04f39208ebb965fdb8d298b150ef82 (patch)
treeb940e7f261b99455857e53fcbb0cfaf7c4456f80 /bitbake
parentd85e5ffbbd3c5150bc838b36724ff05672570991 (diff)
downloadopenembedded-core-a74658d4ed04f39208ebb965fdb8d298b150ef82.tar.gz
openembedded-core-a74658d4ed04f39208ebb965fdb8d298b150ef82.tar.bz2
openembedded-core-a74658d4ed04f39208ebb965fdb8d298b150ef82.zip
Add md5_file and sha256_file checksum methods which use the builtin Python checksum code
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@4385 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/utils.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 9702c8c204..19327b7157 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/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()