mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-10 21:43:23 -05:00
fix: refuse an emudeck scrape with no cores
This commit is contained in:
1 parent
0eecb23724
commit
1e61b749cf
2 files changed
+21
-8
No files matched your search
@@ -22,6 +22,7 @@ try:
|
||||
BaseScraper,
|
||||
BiosRequirement,
|
||||
fetch_github_latest_version,
|
||||
github_headers,
|
||||
requirement_entry,
|
||||
)
|
||||
except ImportError:
|
||||
@@ -29,6 +30,7 @@ except ImportError:
|
||||
BaseScraper,
|
||||
BiosRequirement,
|
||||
fetch_github_latest_version,
|
||||
github_headers,
|
||||
requirement_entry,
|
||||
)
|
||||
|
||||
@@ -462,17 +464,15 @@ class Scraper(BaseScraper):
|
||||
skip = {"retroarch_maincfg", "retroarch"}
|
||||
|
||||
try:
|
||||
req = urllib.request.Request(
|
||||
api_url,
|
||||
headers={"User-Agent": "retrobios-scraper/1.0"},
|
||||
)
|
||||
data = json.loads(urllib.request.urlopen(req, timeout=30).read())
|
||||
except (urllib.error.URLError, OSError):
|
||||
return []
|
||||
req = urllib.request.Request(api_url, headers=github_headers())
|
||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||
data = json.loads(resp.read())
|
||||
except (urllib.error.URLError, json.JSONDecodeError) as e:
|
||||
raise RuntimeError(f"cannot list EmuDeck EmuScripts: {e}") from e
|
||||
|
||||
cores: list[str] = []
|
||||
seen: set[str] = set()
|
||||
for entry in data:
|
||||
for entry in data if isinstance(data, list) else []:
|
||||
name = entry.get("name", "")
|
||||
if not name.endswith(".sh"):
|
||||
continue
|
||||
@@ -487,6 +487,8 @@ class Scraper(BaseScraper):
|
||||
if core not in seen:
|
||||
seen.add(core)
|
||||
cores.append(core)
|
||||
if not cores:
|
||||
raise RuntimeError(f"no emulator script in {api_url}")
|
||||
return sorted(cores)
|
||||
|
||||
|
||||
|
||||
@@ -278,3 +278,14 @@ class UnreadableReleaseStopsTheScrape(unittest.TestCase):
|
||||
|
||||
with mock.patch.dict("os.environ", {"GITHUB_TOKEN": "t0k"}):
|
||||
self.assertEqual(github_headers()["Authorization"], "Bearer t0k")
|
||||
|
||||
def test_emudeck_cores_raise(self):
|
||||
"""EmuDeck wrote cores: [] when the GitHub listing was refused."""
|
||||
from unittest import mock
|
||||
|
||||
from scraper.emudeck_scraper import Scraper
|
||||
|
||||
with mock.patch("urllib.request.urlopen", self._refuse), self.assertRaises(
|
||||
RuntimeError
|
||||
):
|
||||
Scraper()._fetch_installed_emulators()
|
||||
Reference in new issue
Block a user