feat: add --source and --all-variants flags

This commit is contained in:
Abdessamad Derraz
2026-04-01 14:50:33 +02:00
parent 5f579d1851
commit 47a68c1a11

View File

@@ -2275,47 +2275,66 @@ def _run_manifest_mode(
if os.path.exists(registry_path): if os.path.exists(registry_path):
with open(registry_path) as _rf: with open(registry_path) as _rf:
registry = yaml.safe_load(_rf) or {} registry = yaml.safe_load(_rf) or {}
for group_platforms, representative in groups:
print(f"\nGenerating manifest for {representative}...") if args.all_variants:
try: variants = [
tc = target_cores_cache.get(representative) if args.target else None ("full", False), ("full", True),
manifest = generate_manifest( ("platform", False), ("platform", True),
representative, ("truth", False), ("truth", True),
args.platforms_dir, ]
db, else:
args.bios_dir, variants = [(args.source, args.required_only)]
registry_path,
emulators_dir=args.emulators_dir, for source, required_only in variants:
zip_contents=zip_contents, for group_platforms, representative in groups:
emu_profiles=emu_profiles, print(f"\nGenerating manifest for {representative} [source={source}]...")
target_cores=tc, try:
) tc = target_cores_cache.get(representative) if args.target else None
out_path = os.path.join(args.output_dir, f"{representative}.json") manifest = generate_manifest(
_write_manifest_if_changed(out_path, manifest) representative,
print( args.platforms_dir,
f" {out_path}: {manifest['total_files']} files, " db,
f"{manifest['total_size']} bytes" args.bios_dir,
) registry_path,
# Create aliases for grouped platforms (e.g., lakka -> retroarch) emulators_dir=args.emulators_dir,
for alias_plat in group_platforms: zip_contents=zip_contents,
if alias_plat != representative: emu_profiles=emu_profiles,
alias_path = os.path.join(args.output_dir, f"{alias_plat}.json") target_cores=tc,
alias_manifest = dict(manifest) source=source,
alias_manifest["platform"] = alias_plat )
alias_cfg = load_platform_config(alias_plat, args.platforms_dir) source_suffix = {"platform": "_platform", "truth": "_truth"}.get(source, "")
alias_manifest["display_name"] = alias_cfg.get( req_suffix = "_required" if required_only else ""
"platform", alias_plat out_path = os.path.join(
) args.output_dir, f"{representative}{source_suffix}{req_suffix}.json"
alias_registry = registry.get("platforms", {}).get(alias_plat, {}) )
alias_install = alias_registry.get("install", {}) _write_manifest_if_changed(out_path, manifest)
alias_manifest["detect"] = alias_install.get("detect", []) print(
alias_manifest["standalone_copies"] = alias_install.get( f" {out_path}: {manifest['total_files']} files, "
"standalone_copies", [] f"{manifest['total_size']} bytes"
) )
_write_manifest_if_changed(alias_path, alias_manifest) # Create aliases for grouped platforms (e.g., lakka -> retroarch)
print(f" {alias_path}: alias of {representative}") for alias_plat in group_platforms:
except (FileNotFoundError, OSError, yaml.YAMLError) as e: if alias_plat != representative:
print(f" ERROR: {e}") alias_path = os.path.join(
args.output_dir,
f"{alias_plat}{source_suffix}{req_suffix}.json",
)
alias_manifest = dict(manifest)
alias_manifest["platform"] = alias_plat
alias_cfg = load_platform_config(alias_plat, args.platforms_dir)
alias_manifest["display_name"] = alias_cfg.get(
"platform", alias_plat
)
alias_registry = registry.get("platforms", {}).get(alias_plat, {})
alias_install = alias_registry.get("install", {})
alias_manifest["detect"] = alias_install.get("detect", [])
alias_manifest["standalone_copies"] = alias_install.get(
"standalone_copies", []
)
_write_manifest_if_changed(alias_path, alias_manifest)
print(f" {alias_path}: alias of {representative}")
except (FileNotFoundError, OSError, yaml.YAMLError) as e:
print(f" ERROR: {e}")
def _run_verify_packs(args): def _run_verify_packs(args):
@@ -2470,70 +2489,82 @@ def _run_platform_packs(
system_filter, system_filter,
): ):
"""Generate ZIP packs for platform groups and verify.""" """Generate ZIP packs for platform groups and verify."""
for group_platforms, representative in groups: if args.all_variants:
variants = [p for p in group_platforms if p != representative] variants = [
if variants: ("full", False), ("full", True),
all_names = [ ("platform", False), ("platform", True),
load_platform_config(p, args.platforms_dir).get("platform", p) ("truth", False), ("truth", True),
for p in group_platforms ]
] else:
label = " / ".join(all_names) variants = [(args.source, args.required_only)]
print(f"\nGenerating pack for {label}...")
else:
print(f"\nGenerating pack for {representative}...")
try: for source, required_only in variants:
tc = target_cores_cache.get(representative) if args.target else None for group_platforms, representative in groups:
if args.split: aliases = [p for p in group_platforms if p != representative]
zip_paths = generate_split_packs( if aliases:
representative,
args.platforms_dir,
db,
args.bios_dir,
args.output_dir,
group_by=args.group_by,
emulators_dir=args.emulators_dir,
zip_contents=zip_contents,
data_registry=data_registry,
emu_profiles=emu_profiles,
target_cores=tc,
required_only=args.required_only,
)
print(f" Split into {len(zip_paths)} packs")
else:
zip_path = generate_pack(
representative,
args.platforms_dir,
db,
args.bios_dir,
args.output_dir,
include_extras=args.include_extras,
emulators_dir=args.emulators_dir,
zip_contents=zip_contents,
data_registry=data_registry,
emu_profiles=emu_profiles,
target_cores=tc,
required_only=args.required_only,
system_filter=system_filter,
)
if not args.split and zip_path and variants:
rep_cfg = load_platform_config(representative, args.platforms_dir)
ver = rep_cfg.get("version", rep_cfg.get("dat_version", ""))
ver_tag = f"_{ver.replace(' ', '')}" if ver else ""
all_names = [ all_names = [
load_platform_config(p, args.platforms_dir).get("platform", p) load_platform_config(p, args.platforms_dir).get("platform", p)
for p in group_platforms for p in group_platforms
] ]
combined = ( label = " / ".join(all_names)
"_".join(n.replace(" ", "") for n in all_names) print(f"\nGenerating pack for {label} [source={source}]...")
+ f"{ver_tag}_BIOS_Pack.zip" else:
) print(f"\nGenerating pack for {representative} [source={source}]...")
new_path = os.path.join(os.path.dirname(zip_path), combined)
if new_path != zip_path: try:
os.rename(zip_path, new_path) tc = target_cores_cache.get(representative) if args.target else None
print(f" Renamed -> {os.path.basename(new_path)}") if args.split:
except (FileNotFoundError, OSError, yaml.YAMLError) as e: zip_paths = generate_split_packs(
print(f" ERROR: {e}") representative,
args.platforms_dir,
db,
args.bios_dir,
args.output_dir,
group_by=args.group_by,
emulators_dir=args.emulators_dir,
zip_contents=zip_contents,
data_registry=data_registry,
emu_profiles=emu_profiles,
target_cores=tc,
required_only=required_only,
source=source,
)
print(f" Split into {len(zip_paths)} packs")
else:
zip_path = generate_pack(
representative,
args.platforms_dir,
db,
args.bios_dir,
args.output_dir,
include_extras=args.include_extras,
emulators_dir=args.emulators_dir,
zip_contents=zip_contents,
data_registry=data_registry,
emu_profiles=emu_profiles,
target_cores=tc,
required_only=required_only,
system_filter=system_filter,
source=source,
)
if not args.split and zip_path and aliases:
rep_cfg = load_platform_config(representative, args.platforms_dir)
ver = rep_cfg.get("version", rep_cfg.get("dat_version", ""))
ver_tag = f"_{ver.replace(' ', '')}" if ver else ""
all_names = [
load_platform_config(p, args.platforms_dir).get("platform", p)
for p in group_platforms
]
combined = (
"_".join(n.replace(" ", "") for n in all_names)
+ f"{ver_tag}_BIOS_Pack.zip"
)
new_path = os.path.join(os.path.dirname(zip_path), combined)
if new_path != zip_path:
os.rename(zip_path, new_path)
print(f" Renamed -> {os.path.basename(new_path)}")
except (FileNotFoundError, OSError, yaml.YAMLError) as e:
print(f" ERROR: {e}")
print("\nVerifying packs and generating manifests...") print("\nVerifying packs and generating manifests...")
skip_conf = bool(system_filter or args.split) skip_conf = bool(system_filter or args.split)
@@ -2599,6 +2630,17 @@ def main():
action="store_true", action="store_true",
help="Only include required files, skip optional", help="Only include required files, skip optional",
) )
parser.add_argument(
"--source",
choices=["platform", "truth", "full"],
default="full",
help="File source: platform (YAML only), truth (emulator profiles), full (both)",
)
parser.add_argument(
"--all-variants",
action="store_true",
help="Generate all 6 source x required combinations",
)
parser.add_argument( parser.add_argument(
"--split", action="store_true", help="Generate one ZIP per system/manufacturer" "--split", action="store_true", help="Generate one ZIP per system/manufacturer"
) )