Skip to content

Commit 9ace082

Browse files
dcpleungnashif
authored andcommitted
coredump: fix ruff warnings on parser scripts
This fixes ruff warnings on coredump parser scripts. Note SIM115 is not fixed yet as it requires more intrusive changes to handle opened file with context manager. Signed-off-by: Daniel Leung <[email protected]>
1 parent 79a5783 commit 9ace082

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

.ruff-excludes.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,10 @@
129129
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
130130
]
131131
"./scripts/coredump/coredump_parser/elf_parser.py" = [
132-
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
133-
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
134132
"SIM115", # https://docs.astral.sh/ruff/rules/open-file-with-context-handler
135-
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
136-
"UP039", # https://docs.astral.sh/ruff/rules/unnecessary-class-parentheses
137133
]
138134
"./scripts/coredump/coredump_parser/log_parser.py" = [
139-
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
140135
"SIM115", # https://docs.astral.sh/ruff/rules/open-file-with-context-handler
141-
"UP030", # https://docs.astral.sh/ruff/rules/format-literals
142-
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
143-
"UP032", # https://docs.astral.sh/ruff/rules/f-string
144136
]
145137
"./scripts/coredump/coredump_serial_log_parser.py" = [
146138
"SIM115", # https://docs.astral.sh/ruff/rules/open-file-with-context-handler

scripts/coredump/coredump_parser/elf_parser.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
import logging
88
import struct
9+
from enum import IntEnum
910

1011
import elftools
1112
from elftools.elf.elffile import ELFFile
12-
from enum import IntEnum
13-
1413

1514
# ELF section flags
1615
SHF_WRITE = 0x1
@@ -144,8 +143,8 @@ def parse(self):
144143
if store:
145144
mem_region = {"start": sec_start, "end": sec_end, "data": section.data()}
146145
logger.info(
147-
"ELF Section: 0x%x to 0x%x of size %d (%s)"
148-
% (mem_region["start"], mem_region["end"], len(mem_region["data"]), sect_desc)
146+
f'ELF Section: 0x{mem_region["start"]:x} to 0x{mem_region["end"]:x} '
147+
f'of size {mem_region["data"]:d} ({sect_desc:s})'
149148
)
150149

151150
self.memory_regions.append(mem_region)

scripts/coredump/coredump_parser/log_parser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import logging
88
import struct
99

10-
1110
# Note: keep sync with C code
1211
COREDUMP_HDR_ID = b'ZE'
1312
COREDUMP_HDR_VER = 2
@@ -126,7 +125,7 @@ def parse_memory_section(self):
126125
mem = {"start": saddr, "end": eaddr, "data": data}
127126
self.memory_regions.append(mem)
128127

129-
logger.info("Memory: 0x%x to 0x%x of size %d" % (saddr, eaddr, size))
128+
logger.info(f"Memory: 0x{saddr:x} to 0x{eaddr:x} of size {size:d}")
130129

131130
return True
132131

@@ -156,7 +155,7 @@ def parse(self):
156155
"reason": reason,
157156
}
158157

159-
logger.info("Reason: {0}".format(reason_string(reason)))
158+
logger.info(f"Reason: {reason_string(reason)}")
160159
logger.info(f"Pointer size {ptr_size}")
161160

162161
del id1, id2, hdr_ver, tgt_code, ptr_size, flags, reason

0 commit comments

Comments
 (0)