Skip to content

Commit ffeca16

Browse files
pdgendtkartben
authored andcommitted
scripts: logging: dictionary: log_parser: Fix linter issues
Fix issues reported by ruff. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent 3a8106b commit ffeca16

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

.ruff-excludes.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,6 @@
568568
"UP036", # https://docs.astral.sh/ruff/rules/outdated-version-block
569569
"UP038", # https://docs.astral.sh/ruff/rules/non-pep604-isinstance
570570
]
571-
"./scripts/logging/dictionary/log_parser.py" = [
572-
"SIM115", # https://docs.astral.sh/ruff/rules/open-file-with-context-handler
573-
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
574-
]
575571
"./scripts/make_bugs_pickle.py" = [
576572
"UP006", # https://docs.astral.sh/ruff/rules/non-pep585-annotation
577573
"UP035", # https://docs.astral.sh/ruff/rules/deprecated-import

scripts/logging/dictionary/log_parser.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def read_log_file(args):
5757
else:
5858
hexdata = ''
5959

60-
with open(args.logfile, "r", encoding="iso-8859-1") as hexfile:
60+
with open(args.logfile, encoding="iso-8859-1") as hexfile:
6161
for line in hexfile.readlines():
6262
hexdata += line.strip()
6363

@@ -90,14 +90,11 @@ def read_log_file(args):
9090

9191
logdata = binascii.unhexlify(hexdata[:idx])
9292
else:
93-
logfile = open(args.logfile, "rb")
94-
if not logfile:
95-
logger.error("ERROR: Cannot open binary log data file: %s, exiting...", args.logfile)
96-
sys.exit(1)
97-
98-
logdata = logfile.read()
99-
100-
logfile.close()
93+
with open(args.logfile, "rb") as logfile:
94+
if not logfile:
95+
logger.error(f"ERROR: Cannot open binary log data file: {args.logfile}, exiting...")
96+
sys.exit(1)
97+
logdata = logfile.read()
10198

10299
return logdata
103100

0 commit comments

Comments
 (0)