From 4a081b5a52e3d27da8d4b062f3fda292e8d8fb0a Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Thu, 9 May 2013 21:06:45 +0000 Subject: bitbake: lib: Clean up various file access syntax Python 3 is stricter about how files are accessed. Specficially: * Use open(), not file() * Use binary mode for binary files (when checksumming) * Use with statements to ensure files get closed * Add missing file close statements (Bitbake rev: 9f08b901375ba640f47596f1bcf43f98a931550f) Signed-off-by: Richard Purdie --- bitbake/lib/bb/utils.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'bitbake/lib/bb/utils.py') diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 462eb689b9..2e10fc24dd 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py @@ -414,6 +414,10 @@ def lockfile(name, shared=False, retry=True): return lf lf.close() except Exception: + try: + lf.close() + except Exception: + pass pass if not retry: return None @@ -443,8 +447,9 @@ def md5_file(filename): import md5 m = md5.new() - for line in open(filename): - m.update(line) + with open(filename, "rb") as f: + for line in f: + m.update(line) return m.hexdigest() def sha256_file(filename): @@ -460,8 +465,9 @@ def sha256_file(filename): return None s = hashlib.sha256() - for line in open(filename): - s.update(line) + with open(filename, "rb") as f: + for line in f: + s.update(line) return s.hexdigest() def preserved_envvars_exported(): -- cgit v1.2.3-54-g00ecf