mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-10 05:34:36 +00:00
Don't allow dupes from ref folders to step down from their ref position during reprioritization.
This commit is contained in:
parent
11aa2c147c
commit
9fac97c147
@ -290,7 +290,8 @@ class Group:
|
|||||||
|
|
||||||
def prioritize(self, key_func, tie_breaker=None):
|
def prioritize(self, key_func, tie_breaker=None):
|
||||||
# tie_breaker(ref, dupe) --> True if dupe should be ref
|
# tie_breaker(ref, dupe) --> True if dupe should be ref
|
||||||
self.ordered.sort(key=key_func)
|
master_key_func = lambda x: (-x.is_ref, key_func(x))
|
||||||
|
self.ordered.sort(key=master_key_func)
|
||||||
if tie_breaker is None:
|
if tie_breaker is None:
|
||||||
return
|
return
|
||||||
ref = self.ref
|
ref = self.ref
|
||||||
@ -318,6 +319,8 @@ class Group:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def switch_ref(self, with_dupe):
|
def switch_ref(self, with_dupe):
|
||||||
|
if self.ref.is_ref:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
self.ordered.remove(with_dupe)
|
self.ordered.remove(with_dupe)
|
||||||
self.ordered.insert(0, with_dupe)
|
self.ordered.insert(0, with_dupe)
|
||||||
|
@ -80,7 +80,7 @@ class Scanner:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _key_func(dupe):
|
def _key_func(dupe):
|
||||||
return (not dupe.is_ref, -dupe.size)
|
return -dupe.size
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _tie_breaker(ref, dupe):
|
def _tie_breaker(ref, dupe):
|
||||||
|
@ -416,6 +416,8 @@ class TestCaseDupeGuru_renameSelected:
|
|||||||
fp = open(str(p + 'foo bar 3'),mode='w')
|
fp = open(str(p + 'foo bar 3'),mode='w')
|
||||||
fp.close()
|
fp.close()
|
||||||
files = fs.get_files(p)
|
files = fs.get_files(p)
|
||||||
|
for f in files:
|
||||||
|
f.is_ref = False
|
||||||
matches = engine.getmatches(files)
|
matches = engine.getmatches(files)
|
||||||
groups = engine.get_groups(matches)
|
groups = engine.get_groups(matches)
|
||||||
g = groups[0]
|
g = groups[0]
|
||||||
|
@ -599,6 +599,16 @@ class TestCaseGroup:
|
|||||||
g.switch_ref(NamedObject('',True))
|
g.switch_ref(NamedObject('',True))
|
||||||
assert o2 is g.ref
|
assert o2 is g.ref
|
||||||
|
|
||||||
|
def test_switch_ref_from_ref_dir(self):
|
||||||
|
# When the ref dupe is from a ref dir, switch_ref() does nothing
|
||||||
|
o1 = no(with_words=True)
|
||||||
|
o2 = no(with_words=True)
|
||||||
|
o1.is_ref = True
|
||||||
|
g = Group()
|
||||||
|
g.add_match(get_match(o1, o2))
|
||||||
|
g.switch_ref(o2)
|
||||||
|
assert o1 is g.ref
|
||||||
|
|
||||||
def test_get_match_of(self):
|
def test_get_match_of(self):
|
||||||
g = Group()
|
g = Group()
|
||||||
for m in get_match_triangle():
|
for m in get_match_triangle():
|
||||||
@ -684,6 +694,15 @@ class TestCaseGroup:
|
|||||||
g.prioritize(key_func, tie_breaker)
|
g.prioritize(key_func, tie_breaker)
|
||||||
assert g.ref is o2
|
assert g.ref is o2
|
||||||
|
|
||||||
|
def test_prioritize_with_ref_dupe(self):
|
||||||
|
# when the ref dupe of a group is from a ref dir, make it stay on top.
|
||||||
|
g = get_test_group()
|
||||||
|
o1, o2, o3 = g
|
||||||
|
o1.is_ref = True
|
||||||
|
o2.size = 2
|
||||||
|
g.prioritize(lambda x: -x.size)
|
||||||
|
assert g.ref is o1
|
||||||
|
|
||||||
def test_list_like(self):
|
def test_list_like(self):
|
||||||
g = Group()
|
g = Group()
|
||||||
o1,o2 = (NamedObject("foo",True),NamedObject("bar",True))
|
o1,o2 = (NamedObject("foo",True),NamedObject("bar",True))
|
||||||
|
@ -794,14 +794,4 @@ class TestCaseResultsRefFile:
|
|||||||
def test_stat_line(self):
|
def test_stat_line(self):
|
||||||
expected = '0 / 2 (0.00 B / 2.00 B) duplicates marked.'
|
expected = '0 / 2 (0.00 B / 2.00 B) duplicates marked.'
|
||||||
eq_(expected, self.results.stat_line)
|
eq_(expected, self.results.stat_line)
|
||||||
|
|
||||||
def test_make_ref(self):
|
|
||||||
d = self.results.groups[0].dupes[1] #non-ref
|
|
||||||
r = self.results.groups[0].ref
|
|
||||||
self.results.make_ref(d)
|
|
||||||
expected = '0 / 1 (0.00 B / 1.00 B) duplicates marked.'
|
|
||||||
eq_(expected, self.results.stat_line)
|
|
||||||
self.results.make_ref(r)
|
|
||||||
expected = '0 / 2 (0.00 B / 2.00 B) duplicates marked.'
|
|
||||||
eq_(expected, self.results.stat_line)
|
|
||||||
|
|
@ -11,5 +11,5 @@ from core.scanner import Scanner as ScannerBase
|
|||||||
class ScannerME(ScannerBase):
|
class ScannerME(ScannerBase):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _key_func(dupe):
|
def _key_func(dupe):
|
||||||
return (not dupe.is_ref, -dupe.bitrate, -dupe.size)
|
return (-dupe.bitrate, -dupe.size)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user