diff --git a/scripts/packs/emulatorpack.py b/scripts/packs/emulatorpack.py index d9680ca63..186012d05 100644 --- a/scripts/packs/emulatorpack.py +++ b/scripts/packs/emulatorpack.py @@ -26,7 +26,6 @@ from model.profiles import ( select_emulator_profiles, ) from model.registry import load_data_dir_registry -from model.systems import MANUFACTURER_PREFIXES from packs.archive import ( PackRecord, Placed, @@ -38,7 +37,9 @@ from packs.archive import ( ) from packs.datatrees import MISSING_DATA_DIRS, pack_data_tree from packs.extras import emulator_region_drops, emulator_required_spares, expand_agnostic_entries -from packs.naming import bounded_join, bounded_pack_name, file_name_part, pack_narrowings +from packs.naming import ( + bounded_join, bounded_pack_name, file_name_part, pack_narrowings, system_display_name, +) from packs.paths import archive_destination, resolve_destination from resolve import packfiles as packresolve from resolve.archives import archive_entry, archive_is_optional @@ -617,12 +618,3 @@ def generate_system_pack( shutil.rmtree(scratch, ignore_errors=True) -def system_display_name(system_id: str) -> str: - """Convert system ID to display name for ZIP naming.""" - s = system_id.lower().replace("_", "-") - for prefix in MANUFACTURER_PREFIXES: - if s.startswith(prefix): - s = s[len(prefix) :] - break - parts = s.split("-") - return "_".join(p.title() for p in parts if p) diff --git a/scripts/packs/naming.py b/scripts/packs/naming.py index 5faaa056d..da6891363 100644 --- a/scripts/packs/naming.py +++ b/scripts/packs/naming.py @@ -86,18 +86,21 @@ def platform_target( return canonical_target_name([platform_name], target, platforms_dir) +def system_display_name(system_id: str) -> str: + """A system id as a pack file name writes it, its maker prefix dropped.""" + s = system_id.lower().replace("_", "-") + for prefix in MANUFACTURER_PREFIXES: + if s.startswith(prefix): + s = s[len(prefix) :] + break + return "_".join(p.title() for p in s.split("-") if p) + + def system_tag(system_filter: list[str] | None) -> str: """Filename tag for a pack limited to some systems, empty for all.""" if not system_filter: return "" - display_parts = [] - for sid in system_filter: - s = sid.lower().replace("_", "-") - for prefix in MANUFACTURER_PREFIXES: - if s.startswith(prefix): - s = s[len(prefix) :] - break - display_parts.append("_".join(p.title() for p in s.split("-") if p)) + display_parts = [system_display_name(sid) for sid in system_filter] return "_" + bounded_join(display_parts, system_filter) diff --git a/scripts/packs/platformpack.py b/scripts/packs/platformpack.py index 88eafc0dc..8eaba39d1 100644 --- a/scripts/packs/platformpack.py +++ b/scripts/packs/platformpack.py @@ -32,7 +32,7 @@ from packs.archive import ( writing_pack, ) from packs.datatrees import data_directory_members, core_data_trees, pack_markers -from packs.emulatorpack import system_display_name +from packs.naming import system_display_name from packs.extras import ( ExtraResolver, collect_emulator_extras, diff --git a/scripts/resolve/identity.py b/scripts/resolve/identity.py index 2a65842ae..dad2b9659 100644 --- a/scripts/resolve/identity.py +++ b/scripts/resolve/identity.py @@ -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]: diff --git a/scripts/resolve/ownership.py b/scripts/resolve/ownership.py index 0aea02b5c..35cca5a71 100644 --- a/scripts/resolve/ownership.py +++ b/scripts/resolve/ownership.py @@ -4,6 +4,8 @@ from __future__ import annotations import re +from model.collection import manufacturer_slug + # bios/Other/ and bios/Arcade/ 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