mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-10 13:33:24 -05:00
fix: build the database without network calls
This commit is contained in:
1 parent
41474596d0
commit
6b0cb815aa
2 files changed
+37
-19
No files matched your search
+12
-19
@@ -461,21 +461,10 @@ def _collect_all_aliases(files: dict) -> dict:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
# core-info is not read here: it was the only network call of a build
|
||||||
sys.path.insert(0, "scripts")
|
# that must give the same database offline, and the one name it added
|
||||||
from scraper.coreinfo_scraper import Scraper as CoreInfoScraper
|
# (gearcoleco's writer.rom) is a profile entry proven by its sha1, which
|
||||||
|
# the profile pass below now registers.
|
||||||
ci_reqs = CoreInfoScraper().fetch_requirements()
|
|
||||||
for r in ci_reqs:
|
|
||||||
basename = r.name
|
|
||||||
# Try to match by MD5 or by known canonical names
|
|
||||||
matched = None
|
|
||||||
if r.md5 and r.md5 in md5_to_sha1:
|
|
||||||
matched = md5_to_sha1[r.md5]
|
|
||||||
if matched:
|
|
||||||
_add_alias(basename, matched)
|
|
||||||
except (ImportError, ConnectionError, OSError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Collect aliases from emulator YAMLs (aliases field on file entries)
|
# Collect aliases from emulator YAMLs (aliases field on file entries)
|
||||||
emulators_dir = Path("emulators")
|
emulators_dir = Path("emulators")
|
||||||
@@ -492,18 +481,22 @@ def _collect_all_aliases(files: dict) -> dict:
|
|||||||
except (yaml.YAMLError, OSError):
|
except (yaml.YAMLError, OSError):
|
||||||
continue
|
continue
|
||||||
for file_entry in emu_config.get("files", []):
|
for file_entry in emu_config.get("files", []):
|
||||||
entry_aliases = file_entry.get("aliases", [])
|
entry_aliases = list(file_entry.get("aliases") or [])
|
||||||
if not entry_aliases:
|
|
||||||
continue
|
|
||||||
entry_name = file_entry.get("name", "")
|
entry_name = file_entry.get("name", "")
|
||||||
sha1 = file_entry.get("sha1", "")
|
sha1 = file_entry.get("sha1", "")
|
||||||
md5 = file_entry.get("md5", "")
|
md5 = file_entry.get("md5", "")
|
||||||
matched = None
|
matched = None
|
||||||
if sha1 and sha1 in files:
|
if sha1 and sha1 in files:
|
||||||
matched = sha1
|
matched = sha1
|
||||||
|
# Proven by content, the profile's own name designates
|
||||||
|
# the file whatever the collection calls it.
|
||||||
|
entry_aliases.insert(0, entry_name)
|
||||||
elif md5 and md5 in md5_to_sha1:
|
elif md5 and md5 in md5_to_sha1:
|
||||||
matched = md5_to_sha1[md5]
|
matched = md5_to_sha1[md5]
|
||||||
elif entry_name and name_count.get(entry_name) == 1:
|
entry_aliases.insert(0, entry_name)
|
||||||
|
if not entry_aliases:
|
||||||
|
continue
|
||||||
|
if not matched and entry_name and name_count.get(entry_name) == 1:
|
||||||
# A name carried by several files names none of them:
|
# A name carried by several files names none of them:
|
||||||
# quasi88's disk.rom aliases went to whichever
|
# quasi88's disk.rom aliases went to whichever
|
||||||
# disk.rom the scan met last, a Tandy CoCo ROM.
|
# disk.rom the scan met last, a Tandy CoCo ROM.
|
||||||
|
|||||||
@@ -63,5 +63,30 @@ class AliasesNeedAnUnambiguousName(unittest.TestCase):
|
|||||||
self.assertEqual([a["name"] for a in aliases.get("a", [])], ["n88sub.rom"])
|
self.assertEqual([a["name"] for a in aliases.get("a", [])], ["n88sub.rom"])
|
||||||
|
|
||||||
|
|
||||||
|
class NoNetworkInTheBuild(unittest.TestCase):
|
||||||
|
def test_generate_db_reads_no_remote_source(self):
|
||||||
|
"""core-info was fetched on every run, offline ones included."""
|
||||||
|
source = (REPO_ROOT / "scripts" / "generate_db.py").read_text(encoding="utf-8")
|
||||||
|
self.assertNotIn("coreinfo_scraper", source)
|
||||||
|
self.assertNotIn("urllib.request", source)
|
||||||
|
|
||||||
|
def test_hash_proven_entry_registers_its_own_name(self):
|
||||||
|
import generate_db
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp:
|
||||||
|
previous = os.getcwd()
|
||||||
|
os.chdir(tmp)
|
||||||
|
try:
|
||||||
|
Path("emulators").mkdir()
|
||||||
|
Path("emulators/g.yml").write_text(
|
||||||
|
'files:\n - name: "writer.rom"\n sha1: "s1"\n'
|
||||||
|
)
|
||||||
|
aliases = generate_db._collect_all_aliases(
|
||||||
|
{"s1": {"name": "WRITER.ROM", "path": "bios/WRITER.ROM", "md5": "m"}}
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
os.chdir(previous)
|
||||||
|
self.assertEqual([a["name"] for a in aliases.get("s1", [])], ["writer.rom"])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user