]> code.ossystems Code Review - openembedded-core.git/commitdiff
Add md5_file and sha256_file checksum methods which use the builtin Python checksum...
authorRoss Burton <ross@openedhand.com>
Thu, 1 May 2008 10:59:00 +0000 (10:59 +0000)
committerRoss Burton <ross@openedhand.com>
Thu, 1 May 2008 10:59:00 +0000 (10:59 +0000)
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@4385 311d38ba-8fff-0310-9ca6-ca027cbcb966

bitbake/lib/bb/utils.py

index 9702c8c2042288119b731a7b7556c7b72890affd..19327b7157edfffb68927ac264f712c8c495cdaf 100644 (file)
@@ -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()