mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 01:57:48 -06:00
fix: report only recorded names as mame clones
This commit is contained in:
1 parent
a0579c687e
commit
f77caa1885
2 files changed
+53
-6
No files matched your search
@@ -33,8 +33,16 @@ def _remove_copies(canonical: str, true_dupes_to_remove: list[str], dry_run: boo
|
||||
return removed
|
||||
|
||||
|
||||
def _settle_group(paths: list[str], true_dupes_to_remove: list[str], dry_run: bool) -> dict:
|
||||
"""Keep the best copy of one content and remove the others."""
|
||||
def _settle_group(
|
||||
paths: list[str], true_dupes_to_remove: list[str], clone_names: list[str], dry_run: bool
|
||||
) -> dict:
|
||||
"""Keep the best copy of one content and remove the others.
|
||||
|
||||
Only the names the clone map records are MAME clones. A removed variant
|
||||
is one of the copies, and another name kept beside the canonical file
|
||||
is one an emulator looks for: printing either as a MAME clone named a
|
||||
file that stays, or a clone map entry that does not exist.
|
||||
"""
|
||||
# Find the best canonical across all paths
|
||||
all_paths = [p for p in paths if p not in true_dupes_to_remove]
|
||||
if not all_paths:
|
||||
@@ -58,8 +66,14 @@ def _settle_group(paths: list[str], true_dupes_to_remove: list[str], dry_run: bo
|
||||
print(f" {dn} (keep: {canonical})")
|
||||
if true_dupes_to_remove:
|
||||
print(f" {action} {len(true_dupes_to_remove)} copies")
|
||||
if alias_names:
|
||||
print(f" MAME clones: {alias_names}")
|
||||
if clone_names:
|
||||
print(f" MAME clones: {clone_names}")
|
||||
kept_names = sorted(
|
||||
{os.path.basename(p) for p in paths if p not in true_dupes_to_remove}
|
||||
- {canonical_name}
|
||||
)
|
||||
if kept_names:
|
||||
print(f" Kept under other names: {kept_names}")
|
||||
return {
|
||||
"canonical": canonical,
|
||||
"removed": removed,
|
||||
@@ -99,12 +113,15 @@ def deduplicate(bios_dir: str, dry_run: bool = False) -> dict:
|
||||
if len(paths) <= 1:
|
||||
continue
|
||||
|
||||
true_dupes_to_remove = plan_group_removals(sha1, paths, mame_clones)
|
||||
group_clones: dict[str, dict] = {}
|
||||
true_dupes_to_remove = plan_group_removals(sha1, paths, group_clones)
|
||||
mame_clones.update(group_clones)
|
||||
|
||||
if not true_dupes_to_remove:
|
||||
continue
|
||||
|
||||
settled = _settle_group(paths, true_dupes_to_remove, dry_run)
|
||||
clone_names = [name for entry in group_clones.values() for name in entry["clones"]]
|
||||
settled = _settle_group(paths, true_dupes_to_remove, clone_names, dry_run)
|
||||
total_removed += len(settled["removed"])
|
||||
total_saved += settled.pop("saved")
|
||||
results[sha1] = settled
|
||||
|
||||
@@ -125,6 +125,36 @@ class TrueDuplicates(_Bios):
|
||||
self.run_dedup()
|
||||
self.assertEqual(len(self.existing()), 2)
|
||||
|
||||
def report(self) -> str:
|
||||
out = io.StringIO()
|
||||
with contextlib.redirect_stdout(out):
|
||||
dedup.deduplicate(str(self.bios), dry_run=True)
|
||||
return out.getvalue()
|
||||
|
||||
def test_a_removed_variant_is_not_reported_as_a_mame_clone(self):
|
||||
# The run printed "MAME clones: ['x.bin.1234']" for a variant copy,
|
||||
# a name the clone map never records.
|
||||
self.write("Sony/PS/x.bin")
|
||||
self.write("Sony/PS/.variants/x.bin.1234")
|
||||
report = self.report()
|
||||
self.assertNotIn("MAME clones", report)
|
||||
self.assertIn("Would remove 1 copies", report)
|
||||
|
||||
def test_another_name_kept_beside_the_canonical_is_named_as_kept(self):
|
||||
self.write("Nintendo/N64DD/64DD_IPL_US.n64")
|
||||
self.write("Nintendo/N64DD/x/64DD_IPL_US.n64")
|
||||
self.write("Nintendo/N64DD/IPL_USA.n64")
|
||||
report = self.report()
|
||||
self.assertNotIn("MAME clones", report)
|
||||
self.assertIn("Kept under other names: ['IPL_USA.n64']", report)
|
||||
|
||||
def test_a_device_clone_is_still_reported_as_one(self):
|
||||
self.write("Arcade/MAME/a.zip")
|
||||
self.write("Arcade/MAME/abc.zip")
|
||||
report = self.report()
|
||||
self.assertIn("MAME clones: ['abc.zip']", report)
|
||||
self.assertNotIn("Kept under other names", report)
|
||||
|
||||
def test_a_lone_file_is_left_alone(self):
|
||||
self.write("Sony/PS/only.bin")
|
||||
self.assertEqual(self.run_dedup(), {})
|
||||
|
||||
Reference in new issue
Block a user