utils/check-package: cleanup line reading

Cleanup the implementation for reading lines by having files processed
in context managers and utilizing the iterable file object for line
reading (instead of needing to call `readlines()`).

Signed-off-by: James Knight <james.d.knight@live.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
James Knight 2023-09-02 08:47:49 -04:00 committed by Thomas Petazzoni
parent 464ff28b7a
commit 2be2ccb487

View File

@ -233,16 +233,18 @@ def check_file_using_lib(fname):
nwarnings += warn
lastline = ""
for lineno, text in enumerate(open(fname, "r", errors="surrogateescape").readlines()):
nlines += 1
for name, cf in objects:
if cf.disable.search(lastline):
continue
warn, fail = print_warnings(cf.check_line(lineno + 1, text), name in xfail)
if fail > 0:
failed.add(name)
nwarnings += warn
lastline = text
with open(fname, "r", errors="surrogateescape") as f:
for lineno, text in enumerate(f):
nlines += 1
for name, cf in objects:
if cf.disable.search(lastline):
continue
line_sts = cf.check_line(lineno + 1, text)
warn, fail = print_warnings(line_sts, name in xfail)
if fail > 0:
failed.add(name)
nwarnings += warn
lastline = text
for name, cf in objects:
warn, fail = print_warnings(cf.after(), name in xfail)