diff options
author | Ola x Nilsson <ola.x.nilsson@axis.com> | 2019-10-21 11:07:05 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-10-23 22:58:10 +0100 |
commit | 459ad524756a3f9b50feeedf31e33502dceae8d5 (patch) | |
tree | b4ed8e506990738009ad15b082f0d9a023eafa53 | |
parent | 405a9068ce5072050b9878f7cec15b2c2592bc4e (diff) | |
download | bitbake-contrib-459ad524756a3f9b50feeedf31e33502dceae8d5.tar.gz |
bitbake: ConfHandler: Use with to manage filehandle lifetime
Signed-off-by: Ola x Nilsson <olani@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | lib/bb/parse/parse_py/ConfHandler.py | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/lib/bb/parse/parse_py/ConfHandler.py b/lib/bb/parse/parse_py/ConfHandler.py index 2e84b913d..af64d3446 100644 --- a/lib/bb/parse/parse_py/ConfHandler.py +++ b/lib/bb/parse/parse_py/ConfHandler.py @@ -119,30 +119,30 @@ def handle(fn, data, include): oldfile = data.getVar('FILE', False) abs_fn = resolve_file(fn, data) - f = open(abs_fn, 'r') - - statements = ast.StatementGroup() - lineno = 0 - while True: - lineno = lineno + 1 - s = f.readline() - if not s: - break - w = s.strip() - # skip empty lines - if not w: - continue - s = s.rstrip() - while s[-1] == '\\': - s2 = f.readline().rstrip() + with open(abs_fn, 'r') as f: + + statements = ast.StatementGroup() + lineno = 0 + while True: lineno = lineno + 1 - if (not s2 or s2 and s2[0] != "#") and s[0] == "#" : - bb.fatal("There is a confusing multiline, partially commented expression on line %s of file %s (%s).\nPlease clarify whether this is all a comment or should be parsed." % (lineno, fn, s)) - s = s[:-1] + s2 - # skip comments - if s[0] == '#': - continue - feeder(lineno, s, abs_fn, statements) + s = f.readline() + if not s: + break + w = s.strip() + # skip empty lines + if not w: + continue + s = s.rstrip() + while s[-1] == '\\': + s2 = f.readline().rstrip() + lineno = lineno + 1 + if (not s2 or s2 and s2[0] != "#") and s[0] == "#" : + bb.fatal("There is a confusing multiline, partially commented expression on line %s of file %s (%s).\nPlease clarify whether this is all a comment or should be parsed." % (lineno, fn, s)) + s = s[:-1] + s2 + # skip comments + if s[0] == '#': + continue + feeder(lineno, s, abs_fn, statements) # DONE WITH PARSING... time to evaluate data.setVar('FILE', abs_fn) |