From a43e0a8ecd0441131e929daf998c3cd454d9c8f3 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Thu, 9 May 2013 17:05:58 +0100 Subject: class/lib: Fix up various file access methods There are various bits of cruft that have built up around our file accesses. This patch cleans some of them up, specifically: * Remove pointless "from __builtin__ import file" * Use open(), not file() * Wrap file usage in a with container to ensure files are closed * Add missing .close() calls in some cases Signed-off-by: Richard Purdie --- meta/lib/oe/packagedata.py | 2 +- meta/lib/oe/utils.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'meta/lib') diff --git a/meta/lib/oe/packagedata.py b/meta/lib/oe/packagedata.py index 62fd71898e..14c38bdc0f 100644 --- a/meta/lib/oe/packagedata.py +++ b/meta/lib/oe/packagedata.py @@ -12,7 +12,7 @@ def read_pkgdatafile(fn): if os.access(fn, os.R_OK): import re - f = file(fn, 'r') + f = open(fn, 'r') lines = f.readlines() f.close() r = re.compile("([^:]+):\s*(.*)") diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py index ec8260d9bd..0a2092b24b 100644 --- a/meta/lib/oe/utils.py +++ b/meta/lib/oe/utils.py @@ -7,11 +7,13 @@ except ImportError: def read_file(filename): try: - f = file( filename, "r" ) + f = open( filename, "r" ) except IOError as reason: return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M: else: - return f.read().strip() + data = f.read().strip() + f.close() + return data return None def ifelse(condition, iftrue = True, iffalse = False): -- cgit 1.2.3-korg