diff options
Diffstat (limited to 'bitbake')
-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() | ||