summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@intel.com>2016-12-14 19:53:46 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-12-16 10:04:18 +0000
commit50633012a64a3b5f0662145e29ff426374fb7683 (patch)
tree161abda67f12b1957e3aa313296708b62125cabb
parente3694e738e98f26f413ada6860ca7d829d3662f0 (diff)
downloadbitbake-contrib-50633012a64a3b5f0662145e29ff426374fb7683.tar.gz
BBHandler: use with instead of open/close
This is more pythonic and can handle unclosed file warnings better than the previous code structure. Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/bb/parse/parse_py/BBHandler.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/bb/parse/parse_py/BBHandler.py b/lib/bb/parse/parse_py/BBHandler.py
index f2a215105..fe918a41f 100644
--- a/lib/bb/parse/parse_py/BBHandler.py
+++ b/lib/bb/parse/parse_py/BBHandler.py
@@ -87,17 +87,17 @@ def get_statements(filename, absolute_filename, base_name):
try:
return cached_statements[absolute_filename]
except KeyError:
- file = open(absolute_filename, 'r')
- statements = ast.StatementGroup()
-
- lineno = 0
- while True:
- lineno = lineno + 1
- s = file.readline()
- if not s: break
- s = s.rstrip()
- feeder(lineno, s, filename, base_name, statements)
- file.close()
+ with open(absolute_filename, 'r') as f:
+ statements = ast.StatementGroup()
+
+ lineno = 0
+ while True:
+ lineno = lineno + 1
+ s = f.readline()
+ if not s: break
+ s = s.rstrip()
+ feeder(lineno, s, filename, base_name, statements)
+
if __inpython__:
# add a blank line to close out any python definition
feeder(lineno, "", filename, base_name, statements, eof=True)