mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 14:28:54 -06:00
The comma-joined emulator field of a launcher record was written in eleven places and read in nine, four of them splitting on ", " with no strip. model.launcherrecords joins and splits it, and every scraper, resolve and packs reader goes through it.
26 lines
829 B
Python
26 lines
829 B
Python
"""The emulator field of a platform launcher record: one name, or several joined."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Iterable, Mapping
|
|
from typing import Any
|
|
|
|
# A record written once for several emulators names them all in one field
|
|
# (schemas/platform.schema.json, launchers[].emulator).
|
|
SEPARATOR = ", "
|
|
|
|
|
|
def join_emulators(names: Iterable[str]) -> str:
|
|
"""The emulator field of a record written for `names`."""
|
|
return SEPARATOR.join(names)
|
|
|
|
|
|
def emulator_names(field: str) -> list[str]:
|
|
"""The names an emulator field joins, in their order."""
|
|
return [name.strip() for name in field.split(",")]
|
|
|
|
|
|
def record_emulators(record: Mapping[str, Any]) -> list[str]:
|
|
"""The emulators a launcher record is written for."""
|
|
return emulator_names(str(record.get("emulator", "")))
|