mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
refactor: list the copies of an entry in one place
Nine places listed an entry with its alternatives and slot choices by hand. The known core names read only the alternatives, so a core named by a slot choice alone would have counted as unknown.
This commit is contained in:
1 parent
7b89a558ff
commit
ee2e6e80ce
12 files changed
+55
-45
No files matched your search
+1
-1
@@ -16,7 +16,7 @@
|
||||
# and Invoke-WebRequest throws on a cut transfer before the hash is read:
|
||||
# the site's build rewrites this line there (scripts/sitebootstrap.py).
|
||||
$mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
|
||||
$defaultInstallSha256 = "c11a387a05a77fd98ad147971abf8ab12bb3caff592f8c28e894adaf57fefa39"
|
||||
$defaultInstallSha256 = "24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812"
|
||||
# The pin above refuses any changed byte: this cap only stops a body that
|
||||
# cannot be the installer (a sign-in portal's page) before it is hashed.
|
||||
$maximumInstallerBytes = 8MB
|
||||
|
||||
+16
-15
@@ -3077,6 +3077,11 @@ SELECTION_FIELDS = ("systems", "regions", "region_groups", "region_system_groups
|
||||
OTHER_SYSTEMS = "other"
|
||||
|
||||
|
||||
def entry_copies(entry: dict) -> list[dict]:
|
||||
"""An entry and every copy another core reads at its place."""
|
||||
return [entry, *(entry.get("alternatives") or []), *(entry.get("slot_choices") or [])]
|
||||
|
||||
|
||||
def _check_root(entry: dict, dest: str, omitted: bool = False) -> None:
|
||||
"""root is absent or save, emulator only on a file left out (a path in
|
||||
the emulator's own folder, outside the BIOS tree), and core_folder one
|
||||
@@ -3469,7 +3474,7 @@ def _check_standalone_layouts(data: object, manifest: dict, plat: str) -> dict:
|
||||
sizes = {
|
||||
copy["sha1"]: copy.get("size", 0)
|
||||
for entry in [*manifest.get("files", []), *(manifest.get("truth_files") or [])]
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]
|
||||
for copy in entry_copies(entry)
|
||||
if isinstance(copy, dict) and copy.get("sha1")
|
||||
and (copy.get("repo_path") or copy.get("release_asset"))
|
||||
}
|
||||
@@ -6665,9 +6670,8 @@ def known_core_names(manifest: dict) -> set[str]:
|
||||
for cores in (manifest.get("system_cores") or {}).values():
|
||||
names.update(cores)
|
||||
for entry in [*manifest.get("files", []), *manifest.get("omitted_files", [])]:
|
||||
names.update(entry.get("cores") or [])
|
||||
for alternative in entry.get("alternatives", []):
|
||||
names.update(alternative.get("cores") or [])
|
||||
for copy in entry_copies(entry):
|
||||
names.update(copy.get("cores") or [])
|
||||
return names
|
||||
|
||||
|
||||
@@ -7211,7 +7215,7 @@ def standalone_entries(manifest: dict, layouts: dict, profile: str) -> list[dict
|
||||
copies = {
|
||||
copy["sha1"]: copy
|
||||
for entry in [*manifest.get("files", []), *(manifest.get("truth_files") or [])]
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]
|
||||
for copy in entry_copies(entry)
|
||||
if copy.get("sha1") and (copy.get("repo_path") or copy.get("release_asset"))
|
||||
}
|
||||
result: list[dict] = []
|
||||
@@ -7257,7 +7261,7 @@ def find_by_hash(files: list[dict], value: str) -> tuple[str, list[dict], bool]:
|
||||
recorded = False
|
||||
seen: set[tuple[str, str]] = set()
|
||||
for entry in files:
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]:
|
||||
for copy in entry_copies(entry):
|
||||
if kind in copy:
|
||||
recorded = True
|
||||
if str(copy.get(kind, "")).lower() != value:
|
||||
@@ -10299,7 +10303,7 @@ def recorded_axes(files: list[dict], omitted: Iterable[dict] = ()) -> frozenset:
|
||||
# pack built with it does.
|
||||
axes = {"regions", *(["systems"] if systems else [])}
|
||||
if any(copy.get("cores") for entry in files
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]):
|
||||
for copy in entry_copies(entry)):
|
||||
axes.add("cores")
|
||||
return frozenset(axes)
|
||||
|
||||
@@ -10317,7 +10321,7 @@ def available_choices(files: list[dict], omitted: list[dict]) -> dict[str, list[
|
||||
ordered.append(OTHER_SYSTEMS)
|
||||
cores = {
|
||||
c for f in files
|
||||
for copy in [f, *f.get("alternatives", []), *f.get("slot_choices", [])]
|
||||
for copy in entry_copies(f)
|
||||
for c in (copy.get("cores") or [])
|
||||
}
|
||||
regions = {
|
||||
@@ -12354,8 +12358,7 @@ def _read_from_folder(label: str) -> FolderIndex:
|
||||
def _copies(entry: dict) -> list[dict]:
|
||||
"""Every copy the list knows for an entry: its own, other cores', the
|
||||
platform's declared one."""
|
||||
return [entry, *entry.get("alternatives", []), *entry.get("slot_choices", []),
|
||||
*entry.get("declared_choices", [])]
|
||||
return [*entry_copies(entry), *entry.get("declared_choices", [])]
|
||||
|
||||
|
||||
# id(manifest) -> (manifest, the cores its entries name), read once per list.
|
||||
@@ -20510,8 +20513,7 @@ class Removal(NamedTuple):
|
||||
|
||||
|
||||
def _entry_sha1s(entry: dict) -> set[str]:
|
||||
return {str(copy.get("sha1")) for copy in [entry, *(entry.get("alternatives") or []),
|
||||
*(entry.get("slot_choices") or [])]
|
||||
return {str(copy.get("sha1")) for copy in entry_copies(entry)
|
||||
if copy.get("sha1")}
|
||||
|
||||
|
||||
@@ -20519,8 +20521,7 @@ def _entry_readers(entry: dict) -> set[str] | None:
|
||||
"""The cores that read an entry, None for a file of the platform's own list."""
|
||||
if entry.get("cores") is None:
|
||||
return None
|
||||
return {core for copy in [entry, *(entry.get("alternatives") or []),
|
||||
*(entry.get("slot_choices") or [])]
|
||||
return {core for copy in entry_copies(entry)
|
||||
for core in copy.get("cores") or ()}
|
||||
|
||||
|
||||
@@ -24027,7 +24028,7 @@ def tui_core_sizes(state: TuiState) -> dict[str, str]:
|
||||
extra = [entry for entry in kept if entry.get("cores") is not None]
|
||||
by_core: dict[str, list[dict]] = {}
|
||||
for entry in extra:
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]:
|
||||
for copy in entry_copies(entry):
|
||||
for core in copy.get("cores") or []:
|
||||
listed = by_core.setdefault(core, [])
|
||||
if not listed or listed[-1] is not entry:
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins
|
||||
# curl or wget stop on a cut transfer before the hash is read: the site's
|
||||
# build rewrites this line there (scripts/sitebootstrap.py).
|
||||
MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
|
||||
DEFAULT_INSTALL_SHA256="c11a387a05a77fd98ad147971abf8ab12bb3caff592f8c28e894adaf57fefa39"
|
||||
DEFAULT_INSTALL_SHA256="24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812"
|
||||
# The pin above refuses any changed byte: this cap only stops a body that
|
||||
# cannot be the installer (a sign-in portal's page) before it is hashed.
|
||||
MAX_INSTALLER_BYTES=8388608
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
{
|
||||
"dest": "roms/ports/retrobios/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1450086,
|
||||
"sha256": "c11a387a05a77fd98ad147971abf8ab12bb3caff592f8c28e894adaf57fefa39",
|
||||
"size": 1449658,
|
||||
"sha256": "24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -71,8 +71,8 @@
|
||||
"muos": {
|
||||
"archive": {
|
||||
"dest": "ARCHIVE/RetroBIOS.muxapp",
|
||||
"size": 1503711,
|
||||
"sha256": "c489888589339375e3c62dec4bad0a5a36ab4c8a33c21725b15344099129e709"
|
||||
"size": 1503283,
|
||||
"sha256": "5e53ba1ca6d7fe47789b84fe1aaaba50e3752454ffc182389bd83e1f905baca1"
|
||||
},
|
||||
"members": [
|
||||
{
|
||||
@@ -92,8 +92,8 @@
|
||||
{
|
||||
"name": "RetroBIOS/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1450086,
|
||||
"sha256": "c11a387a05a77fd98ad147971abf8ab12bb3caff592f8c28e894adaf57fefa39",
|
||||
"size": 1449658,
|
||||
"sha256": "24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -166,8 +166,8 @@
|
||||
{
|
||||
"dest": ".config/modules/retrobios/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1450086,
|
||||
"sha256": "c11a387a05a77fd98ad147971abf8ab12bb3caff592f8c28e894adaf57fefa39",
|
||||
"size": 1449658,
|
||||
"sha256": "24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from installer.console import detail
|
||||
from installer.install_record import drop_recorded
|
||||
from installer.manifest import OTHER_SYSTEMS
|
||||
from installer.manifest import OTHER_SYSTEMS, entry_copies
|
||||
from installer.narrowing import _filter_by_target, designated_cores, narrow, narrow_to_cores, standalone_layout
|
||||
from installer.network import _pack_alone, fetch_standalone
|
||||
from installer.offline import LOCAL
|
||||
@@ -46,7 +46,7 @@ def recorded_axes(files: list[dict], omitted: Iterable[dict] = ()) -> frozenset:
|
||||
# pack built with it does.
|
||||
axes = {"regions", *(["systems"] if systems else [])}
|
||||
if any(copy.get("cores") for entry in files
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]):
|
||||
for copy in entry_copies(entry)):
|
||||
axes.add("cores")
|
||||
return frozenset(axes)
|
||||
|
||||
@@ -64,7 +64,7 @@ def available_choices(files: list[dict], omitted: list[dict]) -> dict[str, list[
|
||||
ordered.append(OTHER_SYSTEMS)
|
||||
cores = {
|
||||
c for f in files
|
||||
for copy in [f, *f.get("alternatives", []), *f.get("slot_choices", [])]
|
||||
for copy in entry_copies(f)
|
||||
for c in (copy.get("cores") or [])
|
||||
}
|
||||
regions = {
|
||||
|
||||
+3
-3
@@ -12,6 +12,7 @@ from installer.frontend_folders import _retroarch_config_for
|
||||
from installer.host_fs import _is_file, closed_folder
|
||||
from installer.invocation import _INVOCATION
|
||||
from installer.local_check import closed_folder_words
|
||||
from installer.manifest import entry_copies
|
||||
from installer.platforms import display_name
|
||||
from installer.text import _plural, screen_text
|
||||
|
||||
@@ -133,9 +134,8 @@ def known_core_names(manifest: dict) -> set[str]:
|
||||
for cores in (manifest.get("system_cores") or {}).values():
|
||||
names.update(cores)
|
||||
for entry in [*manifest.get("files", []), *manifest.get("omitted_files", [])]:
|
||||
names.update(entry.get("cores") or [])
|
||||
for alternative in entry.get("alternatives", []):
|
||||
names.update(alternative.get("cores") or [])
|
||||
for copy in entry_copies(entry):
|
||||
names.update(copy.get("cores") or [])
|
||||
return names
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from installer.from_folders import (
|
||||
_place_reason,
|
||||
)
|
||||
from installer.host_fs import _is_file
|
||||
from installer.manifest import GAME_DATA
|
||||
from installer.manifest import GAME_DATA, entry_copies
|
||||
from installer.paths import _entry_path, shown_path
|
||||
from installer.platforms import entry_systems
|
||||
from installer.regions import WORLD_REGION
|
||||
@@ -29,8 +29,7 @@ if TYPE_CHECKING:
|
||||
def _copies(entry: dict) -> list[dict]:
|
||||
"""Every copy the list knows for an entry: its own, other cores', the
|
||||
platform's declared one."""
|
||||
return [entry, *entry.get("alternatives", []), *entry.get("slot_choices", []),
|
||||
*entry.get("declared_choices", [])]
|
||||
return [*entry_copies(entry), *entry.get("declared_choices", [])]
|
||||
|
||||
|
||||
# id(manifest) -> (manifest, the cores its entries name), read once per list.
|
||||
|
||||
@@ -46,6 +46,11 @@ SELECTION_FIELDS = ("systems", "regions", "region_groups", "region_system_groups
|
||||
OTHER_SYSTEMS = "other"
|
||||
|
||||
|
||||
def entry_copies(entry: dict) -> list[dict]:
|
||||
"""An entry and every copy another core reads at its place."""
|
||||
return [entry, *(entry.get("alternatives") or []), *(entry.get("slot_choices") or [])]
|
||||
|
||||
|
||||
def _check_root(entry: dict, dest: str, omitted: bool = False) -> None:
|
||||
"""root is absent or save, emulator only on a file left out (a path in
|
||||
the emulator's own folder, outside the BIOS tree), and core_folder one
|
||||
@@ -438,7 +443,7 @@ def _check_standalone_layouts(data: object, manifest: dict, plat: str) -> dict:
|
||||
sizes = {
|
||||
copy["sha1"]: copy.get("size", 0)
|
||||
for entry in [*manifest.get("files", []), *(manifest.get("truth_files") or [])]
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]
|
||||
for copy in entry_copies(entry)
|
||||
if isinstance(copy, dict) and copy.get("sha1")
|
||||
and (copy.get("repo_path") or copy.get("release_asset"))
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Collection
|
||||
|
||||
from installer.manifest import FILE_GROUP, OTHER_SYSTEMS, _COPY_FIELDS
|
||||
from installer.manifest import FILE_GROUP, OTHER_SYSTEMS, _COPY_FIELDS, entry_copies
|
||||
from installer.paths import _entry_key
|
||||
from installer.platforms import entry_systems
|
||||
from installer.regions import WORLD_REGION, _region_rank
|
||||
@@ -467,7 +467,7 @@ def standalone_entries(manifest: dict, layouts: dict, profile: str) -> list[dict
|
||||
copies = {
|
||||
copy["sha1"]: copy
|
||||
for entry in [*manifest.get("files", []), *(manifest.get("truth_files") or [])]
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]
|
||||
for copy in entry_copies(entry)
|
||||
if copy.get("sha1") and (copy.get("repo_path") or copy.get("release_asset"))
|
||||
}
|
||||
result: list[dict] = []
|
||||
@@ -513,7 +513,7 @@ def find_by_hash(files: list[dict], value: str) -> tuple[str, list[dict], bool]:
|
||||
recorded = False
|
||||
seen: set[tuple[str, str]] = set()
|
||||
for entry in files:
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]:
|
||||
for copy in entry_copies(entry):
|
||||
if kind in copy:
|
||||
recorded = True
|
||||
if str(copy.get(kind, "")).lower() != value:
|
||||
|
||||
@@ -36,7 +36,7 @@ from installer.install_record import (
|
||||
)
|
||||
from installer.invocation import _INVOCATION, offline_requested
|
||||
from installer.local_check import _digest_file
|
||||
from installer.manifest import OTHER_SYSTEMS, _validate_manifest
|
||||
from installer.manifest import OTHER_SYSTEMS, _validate_manifest, entry_copies
|
||||
from installer.narrowing import designated_cores
|
||||
from installer.network import _fetch_json, fetch_manifest
|
||||
from installer.paths import shown_path, spelled
|
||||
@@ -89,8 +89,7 @@ class Removal(NamedTuple):
|
||||
|
||||
|
||||
def _entry_sha1s(entry: dict) -> set[str]:
|
||||
return {str(copy.get("sha1")) for copy in [entry, *(entry.get("alternatives") or []),
|
||||
*(entry.get("slot_choices") or [])]
|
||||
return {str(copy.get("sha1")) for copy in entry_copies(entry)
|
||||
if copy.get("sha1")}
|
||||
|
||||
|
||||
@@ -98,8 +97,7 @@ def _entry_readers(entry: dict) -> set[str] | None:
|
||||
"""The cores that read an entry, None for a file of the platform's own list."""
|
||||
if entry.get("cores") is None:
|
||||
return None
|
||||
return {core for copy in [entry, *(entry.get("alternatives") or []),
|
||||
*(entry.get("slot_choices") or [])]
|
||||
return {core for copy in entry_copies(entry)
|
||||
for core in copy.get("cores") or ()}
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ from installer.destination import dest_drive, on_its_card, shown_bios_folder
|
||||
from installer.embedded import CARD_PLATFORMS
|
||||
from installer.frontend_folders import save_directory_for, save_where_words
|
||||
from installer.games import GAMES_REASONS
|
||||
from installer.manifest import OTHER_SYSTEMS
|
||||
from installer.manifest import OTHER_SYSTEMS, entry_copies
|
||||
from installer.narrowing import narrow
|
||||
from installer.offline import LOCAL, _offline_only
|
||||
from installer.pack_source import pack_holds_trees, pack_lacks
|
||||
@@ -92,7 +92,7 @@ def tui_core_sizes(state: TuiState) -> dict[str, str]:
|
||||
extra = [entry for entry in kept if entry.get("cores") is not None]
|
||||
by_core: dict[str, list[dict]] = {}
|
||||
for entry in extra:
|
||||
for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]:
|
||||
for copy in entry_copies(entry):
|
||||
for core in copy.get("cores") or []:
|
||||
listed = by_core.setdefault(core, [])
|
||||
if not listed or listed[-1] is not entry:
|
||||
|
||||
@@ -203,6 +203,13 @@ class ACoreTheListDoesNotKnow(unittest.TestCase):
|
||||
["parallel_dc"],
|
||||
)
|
||||
|
||||
def test_a_core_named_by_a_slot_choice_is_known(self):
|
||||
listing = {**MANIFEST, "files": [*MANIFEST["files"], {
|
||||
"dest": "dc/dc_boot.bin", "cores": None, "systems": ["sega-dreamcast"],
|
||||
"slot_choices": [{"sha1": "0" * 40, "cores": ["flycast"]}]}]}
|
||||
self.assertEqual(install.unknown_cores(listing, ["flycast", "parallel_dc"]),
|
||||
["parallel_dc"])
|
||||
|
||||
def test_the_info_paths_retroarch_reads(self):
|
||||
(self.tmp / "parallel_dc_libretro.info").write_text(
|
||||
'firmware_count = 3\n'
|
||||
|
||||
Reference in new issue
Block a user