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:23:24 +0000
commit573c646d4cc62dcd0c230381df4940bdf314d495 (patch)
tree0e5e4e1a2fd6c510d1dad49e61a36df56216afb9
parent2c4e366721a0571a2052a23fb0d7e4bbeae552bc (diff)
downloadpoky-573c646d4cc62dcd0c230381df4940bdf314d495.tar.gz
bitbake: BBHandler: use with instead of open/close2.3_M1
This is more pythonic and can handle unclosed file warnings better than the previous code structure. (Bitbake rev: 50633012a64a3b5f0662145e29ff426374fb7683) Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/parse/parse_py/BBHandler.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py
index f2a215105b..fe918a41f3 100644
--- a/bitbake/lib/bb/parse/parse_py/BBHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py
@@ -87,17 +87,17 @@ def get_statements(filename, absolute_filename, base_name):
87 try: 87 try:
88 return cached_statements[absolute_filename] 88 return cached_statements[absolute_filename]
89 except KeyError: 89 except KeyError:
90 file = open(absolute_filename, 'r') 90 with open(absolute_filename, 'r') as f:
91 statements = ast.StatementGroup() 91 statements = ast.StatementGroup()
92 92
93 lineno = 0 93 lineno = 0
94 while True: 94 while True:
95 lineno = lineno + 1 95 lineno = lineno + 1
96 s = file.readline() 96 s = f.readline()
97 if not s: break 97 if not s: break
98 s = s.rstrip() 98 s = s.rstrip()
99 feeder(lineno, s, filename, base_name, statements) 99 feeder(lineno, s, filename, base_name, statements)
100 file.close() 100
101 if __inpython__: 101 if __inpython__:
102 # add a blank line to close out any python definition 102 # add a blank line to close out any python definition
103 feeder(lineno, "", filename, base_name, statements, eof=True) 103 feeder(lineno, "", filename, base_name, statements, eof=True)