mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-22 19:59:07 -05:00
chore: regenerate the updated platform files
This commit is contained in:
1 parent
afc2ce3268
commit
a9c175d322
6 files changed
+90
-5
No files matched your search
@@ -339,6 +339,9 @@ def collect_originals(
|
||||
continue
|
||||
if archive:
|
||||
originals.update(_read_archive(unpack, payload))
|
||||
keep = getattr(exporter, "keep_archive", None)
|
||||
if callable(keep):
|
||||
keep(relative, payload)
|
||||
else:
|
||||
originals[relative] = payload.decode("utf-8", errors="replace")
|
||||
# One platform's unreadable file fails that platform: raised, it
|
||||
@@ -760,7 +763,9 @@ def export_platform(
|
||||
return True, messages
|
||||
|
||||
|
||||
def _write_produced(root: Path, produced: dict[str, str], modes: dict[str, int]) -> None:
|
||||
def _write_produced(
|
||||
root: Path, produced: dict[str, str | bytes], modes: dict[str, int]
|
||||
) -> None:
|
||||
"""Write each file as its bytes, whole or not at all, with its mode.
|
||||
|
||||
write_text translated line ends on Windows, so FirmwareDatabase.cs's
|
||||
@@ -771,7 +776,8 @@ def _write_produced(root: Path, produced: dict[str, str], modes: dict[str, int])
|
||||
for relative, content in produced.items():
|
||||
path = root / relative
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
write_bytes_atomic(str(path), content.encode("utf-8"))
|
||||
data = content if isinstance(content, bytes) else content.encode("utf-8")
|
||||
write_bytes_atomic(str(path), data)
|
||||
path.chmod(modes.get(relative, 0o644))
|
||||
|
||||
|
||||
|
||||
@@ -126,6 +126,15 @@ class BaseExporter(ABC):
|
||||
"""
|
||||
return True
|
||||
|
||||
def keep_archive(self, relative: str, payload: bytes) -> None:
|
||||
"""Hold the bytes of an original archive the render may hand back."""
|
||||
if not hasattr(self, "_archives"):
|
||||
self._archives: dict[str, bytes] = {}
|
||||
self._archives[relative] = payload
|
||||
|
||||
def archive(self, relative: str) -> bytes | None:
|
||||
return getattr(self, "_archives", {}).get(relative)
|
||||
|
||||
@staticmethod
|
||||
def file_modes() -> dict[str, int]:
|
||||
"""The mode of each file the platform publishes other than 0644."""
|
||||
|
||||
@@ -21,6 +21,27 @@ SOURCE_URL = (
|
||||
_DB_NAME = "bios_db.json"
|
||||
|
||||
|
||||
_ARCHIVE = "bios_db.json.zip"
|
||||
|
||||
|
||||
def rebuild_archive(original: bytes, member: str, text: str) -> bytes:
|
||||
"""The archive with one member's content replaced, as MiSTer writes it.
|
||||
|
||||
The member keeps its name, date, compression and attributes, so the
|
||||
archive differs from MiSTer's only by the content that changed.
|
||||
"""
|
||||
with zipfile.ZipFile(io.BytesIO(original)) as source:
|
||||
info = source.getinfo(member)
|
||||
rebuilt = zipfile.ZipInfo(info.filename, date_time=info.date_time)
|
||||
rebuilt.compress_type = info.compress_type
|
||||
rebuilt.external_attr = info.external_attr
|
||||
rebuilt.create_system = info.create_system
|
||||
buffer = io.BytesIO()
|
||||
with zipfile.ZipFile(buffer, "w") as target:
|
||||
target.writestr(rebuilt, text.encode("utf-8"))
|
||||
return buffer.getvalue()
|
||||
|
||||
|
||||
class Exporter(BaseExporter):
|
||||
"""Write MiSTer's bios_db.json, corrected."""
|
||||
|
||||
@@ -82,7 +103,7 @@ class Exporter(BaseExporter):
|
||||
report: Report,
|
||||
originals: dict[str, str],
|
||||
scraped: dict | None = None,
|
||||
) -> dict[str, str]:
|
||||
) -> dict[str, str | bytes]:
|
||||
original = originals.get(_DB_NAME) or originals.get("bios_db.json.zip")
|
||||
if not original:
|
||||
raise ValueError(
|
||||
@@ -111,7 +132,16 @@ class Exporter(BaseExporter):
|
||||
|
||||
# MiSTer publishes the database as one line, without a final
|
||||
# newline: written with an indent it came out as 1499 changed lines.
|
||||
return {_DB_NAME: json.dumps(database, ensure_ascii=False)}
|
||||
text = json.dumps(database, ensure_ascii=False)
|
||||
produced: dict[str, str | bytes] = {_DB_NAME: text}
|
||||
# MiSTer's Downloader fetches the archive, not the JSON in it: handed
|
||||
# back as it came when nothing changed, rebuilt around the new
|
||||
# member otherwise.
|
||||
archive = self.archive(_ARCHIVE)
|
||||
if archive is not None:
|
||||
unchanged = text == originals.get(_DB_NAME)
|
||||
produced[_ARCHIVE] = archive if unchanged else rebuild_archive(archive, _DB_NAME, text)
|
||||
return produced
|
||||
|
||||
def validate(
|
||||
self,
|
||||
|
||||
Reference in new issue
Block a user