diff options
author | Ross Burton <ross.burton@intel.com> | 2016-12-14 19:53:46 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-12-16 10:23:24 +0000 |
commit | 573c646d4cc62dcd0c230381df4940bdf314d495 (patch) | |
tree | 0e5e4e1a2fd6c510d1dad49e61a36df56216afb9 /bitbake | |
parent | 2c4e366721a0571a2052a23fb0d7e4bbeae552bc (diff) | |
download | openembedded-core-contrib-573c646d4cc62dcd0c230381df4940bdf314d495.tar.gz |
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>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/BBHandler.py | 22 |
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): 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) |