mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-23 20:29:06 -05:00
fix: patch batocera entries past commented items
_patched_entry read '#{ ... }' lines as live items, found no match in the model and gave up, so atarist was written again whole (52 lines changed for 3 additions). A commented item is now left as written.
This commit is contained in:
1 parent
5ec1208a83
commit
f7b758a41d
2 files changed
+34
-2
No files matched your search
@@ -26,6 +26,15 @@ _ITEM = re.compile(r"\{[^{}\n]*\}")
|
||||
_MD5_VALUE = re.compile(r'("md5"\s*:\s*")[^"]*(")')
|
||||
|
||||
|
||||
_STRING = re.compile(r'"(?:[^"\\\n]|\\.)*"')
|
||||
|
||||
|
||||
def _commented(text: str, position: int) -> bool:
|
||||
"""Whether a '#' outside a string precedes `position` on its line."""
|
||||
line_start = text.rfind("\n", 0, position) + 1
|
||||
return "#" in _STRING.sub("", text[line_start:position])
|
||||
|
||||
|
||||
def _note_key(text: str) -> tuple[str, str]:
|
||||
"""(file, zippedFile) of the item a line holds, ("", "") for none."""
|
||||
path = re.search(r'"file"\s*:\s*"([^"]+)"', text)
|
||||
@@ -316,6 +325,10 @@ class Exporter(BaseExporter):
|
||||
last: re.Match[str] | None = None
|
||||
consumed: dict[tuple, int] = {}
|
||||
for match in _ITEM.finditer(joined):
|
||||
if _commented(joined, match.start()):
|
||||
# '#{ "md5": ..., "file": "bios/tos102us.img"},' is a note
|
||||
# Python never reads, and it stays as written.
|
||||
continue
|
||||
try:
|
||||
theirs = ast.literal_eval(match.group(0))
|
||||
except (SyntaxError, ValueError):
|
||||
|
||||
Reference in new issue
Block a user