refactor: extract _norm_system_id, apply to resolve_platform_cores fallback

This commit is contained in:
Abdessamad Derraz
2026-03-27 12:23:18 +01:00
parent 79f2d82072
commit 106130ca52

View File

@@ -623,10 +623,11 @@ def resolve_platform_cores(
if c in core_to_profile if c in core_to_profile
} }
else: else:
platform_systems = set(config.get("systems", {}).keys()) # Fallback: system ID intersection with normalization
norm_plat_systems = {_norm_system_id(s) for s in config.get("systems", {})}
result = { result = {
name for name, p in profiles.items() name for name, p in profiles.items()
if set(p.get("systems", [])) & platform_systems if {_norm_system_id(s) for s in p.get("systems", [])} & norm_plat_systems
and p.get("type") != "alias" and p.get("type") != "alias"
} }
@@ -646,6 +647,25 @@ def resolve_platform_cores(
return result return result
def _norm_system_id(sid: str) -> str:
"""Normalize system ID for cross-platform matching.
Strips manufacturer prefixes and separators so that platform-specific
IDs (e.g., "xbox", "nintendo-wiiu") match profile IDs
(e.g., "microsoft-xbox", "nintendo-wii-u").
"""
s = sid.lower().replace("_", "-")
for prefix in ("microsoft-", "nintendo-", "sony-", "sega-",
"snk-", "panasonic-", "nec-", "epoch-", "mattel-",
"fairchild-", "hartung-", "tiger-", "magnavox-",
"philips-", "bandai-", "casio-", "coleco-",
"commodore-", "sharp-", "sinclair-"):
if s.startswith(prefix):
s = s[len(prefix):]
break
return s.replace("-", "")
def filter_systems_by_target( def filter_systems_by_target(
systems: dict[str, dict], systems: dict[str, dict],
profiles: dict[str, dict], profiles: dict[str, dict],
@@ -672,21 +692,7 @@ def filter_systems_by_target(
upstream_to_profile[str(alias)] = name upstream_to_profile[str(alias)] = name
expanded_target = {upstream_to_profile.get(c, c) for c in target_cores} expanded_target = {upstream_to_profile.get(c, c) for c in target_cores}
# Build normalized system ID index for fuzzy matching. _norm_sid = _norm_system_id
# Platforms and profiles may use different IDs for the same system
# (e.g., "xbox" vs "microsoft-xbox-360"). Normalize by stripping
# manufacturer prefixes and separators to group them.
def _norm_sid(sid: str) -> str:
s = sid.lower().replace("_", "-")
for prefix in ("microsoft-", "nintendo-", "sony-", "sega-",
"snk-", "panasonic-", "nec-", "epoch-", "mattel-",
"fairchild-", "hartung-", "tiger-", "magnavox-",
"philips-", "bandai-", "casio-", "coleco-",
"commodore-", "sharp-", "sinclair-"):
if s.startswith(prefix):
s = s[len(prefix):]
break
return s.replace("-", "")
# Build normalized system -> cores from ALL profiles # Build normalized system -> cores from ALL profiles
norm_system_cores: dict[str, set[str]] = {} norm_system_cores: dict[str, set[str]] = {}