refactor: one rule for system and maker names

packs.naming.system_display_name names a system in a pack file name,
read by system_tag in place of its copy of the loop. names_manufacturer
spells a maker through model.collection.manufacturer_slug, and
resolve.identity reads the maker folder with ownership.maker_of_relative,
the rule maker_folder applies. No behavior change.
This commit is contained in:
Abdessamad Derraz committed 2026-11-20 20:03:26 +01:00
1 parent 6b3a588231
commit b679edb133
5 files changed
+27 -24

No files matched your search

+2 -2
View File
@@ -20,6 +20,7 @@ from pathlib import Path
from core.paths import BIOS_DIR
from core.hashing import file_digest
from resolve.ownership import maker_of_relative
# A manufacturer directory holding files that genuinely belong to several
@@ -60,8 +61,7 @@ class Duplicate:
def _manufacturer(path: Path, root: Path) -> str:
"""The vendor directory a path sits under, relative to the scanned root."""
parts = path.relative_to(root).parts
return parts[0] if len(parts) > 1 else ""
return maker_of_relative(path.relative_to(root).as_posix()) or ""
def scan(bios_dir: str = BIOS_DIR) -> list[Duplicate]:
+10 -2
View File
@@ -4,6 +4,8 @@ from __future__ import annotations
import re
from model.collection import manufacturer_slug
# bios/Other/<emulator> and bios/Arcade/<emulator or board> file a copy by
# who loads it, not by machine.
@@ -12,7 +14,7 @@ BUCKET_FOLDERS = frozenset({"Other", "Arcade"})
def names_manufacturer(sys_id: str, manufacturer: str) -> bool:
"""Whether a system id names a maker folder: nec-pc-88 names NEC."""
slug = manufacturer.lower().replace(" ", "-")
slug = manufacturer_slug(manufacturer)
return sys_id == slug or sys_id.startswith(f"{slug}-")
@@ -21,7 +23,13 @@ def maker_folder(path: str, bios_dir: str) -> str | None:
prefix = f"{bios_dir.rstrip('/')}/"
if not path.startswith(prefix):
return None
parts = path[len(prefix):].split("/")
return maker_of_relative(path[len(prefix):])
def maker_of_relative(relative: str) -> str | None:
"""The maker folder of a path relative to the BIOS directory, None for a
file sitting at its root."""
parts = relative.split("/")
return parts[0] if len(parts) >= 2 else None