bitbake: BBHandler: use with instead of open/close
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>
This commit is contained in:
parent
2c4e366721
commit
573c646d4c
|
@ -87,17 +87,17 @@ def get_statements(filename, absolute_filename, base_name):
|
||||||
try:
|
try:
|
||||||
return cached_statements[absolute_filename]
|
return cached_statements[absolute_filename]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
file = open(absolute_filename, 'r')
|
with open(absolute_filename, 'r') as f:
|
||||||
statements = ast.StatementGroup()
|
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)
|
||||||
|
|
||||||
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()
|
|
||||||
if __inpython__:
|
if __inpython__:
|
||||||
# add a blank line to close out any python definition
|
# add a blank line to close out any python definition
|
||||||
feeder(lineno, "", filename, base_name, statements, eof=True)
|
feeder(lineno, "", filename, base_name, statements, eof=True)
|
||||||
|
|
Loading…
Reference in New Issue