mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 18:47:53 -06:00
fix: stop the emudeck scrape on an unread sheet
This commit is contained in:
1 parent
79c3c02885
commit
2665e30bdf
2 files changed
+22
-18
No files matched your search
@@ -21,7 +21,7 @@ from .base_scraper import (
|
||||
BiosRequirement,
|
||||
fetch_branch_head,
|
||||
fetch_github_latest_version,
|
||||
fetch_text,
|
||||
fetch_present,
|
||||
github_json,
|
||||
systems_from_requirements,
|
||||
)
|
||||
@@ -235,25 +235,14 @@ class Scraper(BaseScraper):
|
||||
super().__init__(url=checkbios_url)
|
||||
self.checkbios_url = checkbios_url
|
||||
self.csv_base_url = csv_base_url
|
||||
self._raw_script: str | None = None
|
||||
self._csv_cache: dict[str, str] = {}
|
||||
|
||||
def _fetch_script(self) -> str:
|
||||
if self._raw_script is not None:
|
||||
return self._raw_script
|
||||
self._raw_script = fetch_text(self.checkbios_url)
|
||||
return self._raw_script
|
||||
|
||||
def _fetch_csv(self, sheet: str) -> str:
|
||||
if sheet in self._csv_cache:
|
||||
return self._csv_cache[sheet]
|
||||
url = f"{self.csv_base_url}/{sheet}"
|
||||
try:
|
||||
data = fetch_text(url)
|
||||
except ConnectionError:
|
||||
data = ""
|
||||
self._csv_cache[sheet] = data
|
||||
return data
|
||||
"""A cheat sheet's text, empty only when the server says it is gone:
|
||||
an unreadable sheet stops the scrape instead of dropping its systems."""
|
||||
if sheet not in self._csv_cache:
|
||||
self._csv_cache[sheet] = fetch_present(f"{self.csv_base_url}/{sheet}") or ""
|
||||
return self._csv_cache[sheet]
|
||||
|
||||
def _parse_hash_arrays(self, script: str) -> dict[str, list[str]]:
|
||||
"""Extract named MD5 hash arrays from bash script."""
|
||||
@@ -355,7 +344,7 @@ class Scraper(BaseScraper):
|
||||
return results
|
||||
|
||||
def fetch_requirements(self) -> list[BiosRequirement]:
|
||||
script = self._fetch_script()
|
||||
script = self._fetch_raw()
|
||||
if not self.validate_format(script):
|
||||
raise ValueError("checkBIOS.sh format validation failed")
|
||||
|
||||
|
||||
@@ -805,6 +805,21 @@ class UnreadableReleaseStopsTheScrape(unittest.TestCase):
|
||||
):
|
||||
emudeck_scraper.Scraper(checkbios_url="pinned")._fetch_installed_emulators("0" * 40)
|
||||
|
||||
def test_emudeck_cheat_sheet_raises(self):
|
||||
"""A refused cheat sheet was read as empty and its systems left
|
||||
emudeck.yml; only a 404 says the sheet is gone."""
|
||||
scraper = emudeck_scraper.Scraper(checkbios_url="pinned", csv_base_url="https://x")
|
||||
with mock.patch("urllib.request.urlopen", self._refuse), self.assertRaises(
|
||||
ConnectionError
|
||||
):
|
||||
scraper._fetch_csv("sony-cheat-sheet.csv")
|
||||
|
||||
def gone(*_args, **_kwargs):
|
||||
raise urllib.error.HTTPError("https://x/a.csv", 404, "not found", {}, None)
|
||||
|
||||
with mock.patch("urllib.request.urlopen", gone):
|
||||
self.assertEqual(scraper._fetch_csv("a.csv"), "")
|
||||
|
||||
def test_libretro_core_metadata_raises(self):
|
||||
"""libretro dropped every system name and manufacturer when the
|
||||
core-info listing was refused."""
|
||||
|
||||
Reference in new issue
Block a user