diff options
author | Ross Burton <ross@openedhand.com> | 2008-05-01 10:59:00 +0000 |
---|---|---|
committer | Ross Burton <ross@openedhand.com> | 2008-05-01 10:59:00 +0000 |
commit | a74658d4ed04f39208ebb965fdb8d298b150ef82 (patch) | |
tree | b940e7f261b99455857e53fcbb0cfaf7c4456f80 | |
parent | d85e5ffbbd3c5150bc838b36724ff05672570991 (diff) | |
download | poky-a74658d4ed04f39208ebb965fdb8d298b150ef82.tar.gz |
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
-rw-r--r-- | bitbake/lib/bb/utils.py | 31 |
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): | |||
237 | fcntl.flock(lf.fileno(), fcntl.LOCK_UN) | 237 | fcntl.flock(lf.fileno(), fcntl.LOCK_UN) |
238 | lf.close | 238 | lf.close |
239 | 239 | ||
240 | def md5_file(filename): | ||
241 | """ | ||
242 | Return the hex string representation of the MD5 checksum of filename. | ||
243 | """ | ||
244 | try: | ||
245 | import hashlib | ||
246 | m = hashlib.md5() | ||
247 | except ImportError: | ||
248 | import md5 | ||
249 | m = md5.new() | ||
250 | |||
251 | for line in open(filename): | ||
252 | m.update(line) | ||
253 | return m.hexdigest() | ||
254 | |||
255 | def sha256_file(filename): | ||
256 | """ | ||
257 | Return the hex string representation of the 256-bit SHA checksum of | ||
258 | filename. On Python 2.4 this will return None, so callers will need to | ||
259 | handle that by either skipping SHA checks, or running a standalone sha256sum | ||
260 | binary. | ||
261 | """ | ||
262 | try: | ||
263 | import hashlib | ||
264 | except ImportError: | ||
265 | return None | ||
266 | |||
267 | s = hashlib.sha256() | ||
268 | for line in open(filename): | ||
269 | s.update(line) | ||
270 | return s.hexdigest() | ||