1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2024-10-29 21:05:57 +00:00

More cleanup and fixed a flake8 build issue

This commit is contained in:
Andrew Senetar 2021-08-25 01:11:24 -05:00
parent f11fccc889
commit 47dbe805bb
Signed by: arsenetar
GPG Key ID: C63300DCE48AB2F1
10 changed files with 83 additions and 82 deletions

View File

@ -390,7 +390,7 @@ class DupeGuru(Broadcaster):
g = self.results.get_group_of_duplicate(dupe)
for other in g:
if other is not dupe:
self.ignore_list.Ignore(str(other.path), str(dupe.path))
self.ignore_list.ignore(str(other.path), str(dupe.path))
self.remove_duplicates(dupes)
self.ignore_list_dialog.refresh()
@ -592,9 +592,8 @@ class DupeGuru(Broadcaster):
changed_groups = set()
for dupe in dupes:
g = self.results.get_group_of_duplicate(dupe)
if g not in changed_groups:
if self.results.make_ref(dupe):
changed_groups.add(g)
if g not in changed_groups and self.results.make_ref(dupe):
changed_groups.add(g)
# It's not always obvious to users what this action does, so to make it a bit clearer,
# we change our selection to the ref of all changed groups. However, we also want to keep
# the files that were ref before and weren't changed by the action. In effect, what this
@ -644,15 +643,14 @@ class DupeGuru(Broadcaster):
def open_selected(self):
"""Open :attr:`selected_dupes` with their associated application."""
if len(self.selected_dupes) > 10:
if not self.view.ask_yes_no(MSG_MANY_FILES_TO_OPEN):
return
if len(self.selected_dupes) > 10 and not self.view.ask_yes_no(MSG_MANY_FILES_TO_OPEN):
return
for dupe in self.selected_dupes:
desktop.open_path(dupe.path)
def purge_ignore_list(self):
"""Remove files that don't exist from :attr:`ignore_list`."""
self.ignore_list.Filter(lambda f, s: op.exists(f) and op.exists(s))
self.ignore_list.filter(lambda f, s: op.exists(f) and op.exists(s))
self.ignore_list_dialog.refresh()
def remove_directories(self, indexes):

View File

@ -15,16 +15,21 @@ class DupeGuruGUIObject(Listener):
self.app = app
def directories_changed(self):
# Implemented in child classes
pass
def dupes_selected(self):
# Implemented in child classes
pass
def marking_changed(self):
# Implemented in child classes
pass
def results_changed(self):
# Implemented in child classes
pass
def results_changed_but_keep_selection(self):
# Implemented in child classes
pass

View File

@ -24,7 +24,7 @@ class IgnoreListDialog:
return
msg = tr("Do you really want to remove all %d items from the ignore list?") % len(self.ignore_list)
if self.app.view.ask_yes_no(msg):
self.ignore_list.Clear()
self.ignore_list.clear()
self.refresh()
def refresh(self):

View File

@ -20,8 +20,7 @@ class IgnoreList:
# ---Override
def __init__(self):
self._ignored = {}
self._count = 0
self.clear()
def __iter__(self):
for first, seconds in self._ignored.items():
@ -32,7 +31,7 @@ class IgnoreList:
return self._count
# ---Public
def AreIgnored(self, first, second):
def are_ignored(self, first, second):
def do_check(first, second):
try:
matches = self._ignored[first]
@ -42,23 +41,23 @@ class IgnoreList:
return do_check(first, second) or do_check(second, first)
def Clear(self):
def clear(self):
self._ignored = {}
self._count = 0
def Filter(self, func):
def filter(self, func):
"""Applies a filter on all ignored items, and remove all matches where func(first,second)
doesn't return True.
"""
filtered = IgnoreList()
for first, second in self:
if func(first, second):
filtered.Ignore(first, second)
filtered.ignore(first, second)
self._ignored = filtered._ignored
self._count = filtered._count
def Ignore(self, first, second):
if self.AreIgnored(first, second):
def ignore(self, first, second):
if self.are_ignored(first, second):
return
try:
matches = self._ignored[first]
@ -109,7 +108,7 @@ class IgnoreList:
for sfn in subfile_elems:
subfile_path = sfn.get("path")
if subfile_path:
self.Ignore(file_path, subfile_path)
self.ignore(file_path, subfile_path)
def save_to_xml(self, outfile):
"""Create a XML file that can be used by load_from_xml.

View File

@ -167,7 +167,7 @@ class Scanner:
matches = [m for m in matches if m.first.path.exists() and m.second.path.exists()]
matches = [m for m in matches if not (m.first.is_ref and m.second.is_ref)]
if ignore_list:
matches = [m for m in matches if not ignore_list.AreIgnored(str(m.first.path), str(m.second.path))]
matches = [m for m in matches if not ignore_list.are_ignored(str(m.first.path), str(m.second.path))]
logging.info("Grouping matches")
groups = engine.get_groups(matches)
if self.scan_type in {

View File

@ -369,13 +369,13 @@ class TestCaseDupeGuruWithResults:
open(p1, "w").close()
open(p2, "w").close()
dne = "/does_not_exist"
app.ignore_list.Ignore(dne, p1)
app.ignore_list.Ignore(p2, dne)
app.ignore_list.Ignore(p1, p2)
app.ignore_list.ignore(dne, p1)
app.ignore_list.ignore(p2, dne)
app.ignore_list.ignore(p1, p2)
app.purge_ignore_list()
eq_(1, len(app.ignore_list))
assert app.ignore_list.AreIgnored(p1, p2)
assert not app.ignore_list.AreIgnored(dne, p1)
assert app.ignore_list.are_ignored(p1, p2)
assert not app.ignore_list.are_ignored(dne, p1)
def test_only_unicode_is_added_to_ignore_list(self, do_setup):
def fake_ignore(first, second):
@ -385,7 +385,7 @@ class TestCaseDupeGuruWithResults:
self.fail()
app = self.app
app.ignore_list.Ignore = fake_ignore
app.ignore_list.ignore = fake_ignore
self.rtable.select([4])
app.add_selected_to_ignore_list()

View File

@ -16,54 +16,54 @@ from ..ignore import IgnoreList
def test_empty():
il = IgnoreList()
eq_(0, len(il))
assert not il.AreIgnored("foo", "bar")
assert not il.are_ignored("foo", "bar")
def test_simple():
il = IgnoreList()
il.Ignore("foo", "bar")
assert il.AreIgnored("foo", "bar")
assert il.AreIgnored("bar", "foo")
assert not il.AreIgnored("foo", "bleh")
assert not il.AreIgnored("bleh", "bar")
il.ignore("foo", "bar")
assert il.are_ignored("foo", "bar")
assert il.are_ignored("bar", "foo")
assert not il.are_ignored("foo", "bleh")
assert not il.are_ignored("bleh", "bar")
eq_(1, len(il))
def test_multiple():
il = IgnoreList()
il.Ignore("foo", "bar")
il.Ignore("foo", "bleh")
il.Ignore("bleh", "bar")
il.Ignore("aybabtu", "bleh")
assert il.AreIgnored("foo", "bar")
assert il.AreIgnored("bar", "foo")
assert il.AreIgnored("foo", "bleh")
assert il.AreIgnored("bleh", "bar")
assert not il.AreIgnored("aybabtu", "bar")
il.ignore("foo", "bar")
il.ignore("foo", "bleh")
il.ignore("bleh", "bar")
il.ignore("aybabtu", "bleh")
assert il.are_ignored("foo", "bar")
assert il.are_ignored("bar", "foo")
assert il.are_ignored("foo", "bleh")
assert il.are_ignored("bleh", "bar")
assert not il.are_ignored("aybabtu", "bar")
eq_(4, len(il))
def test_clear():
il = IgnoreList()
il.Ignore("foo", "bar")
il.Clear()
assert not il.AreIgnored("foo", "bar")
assert not il.AreIgnored("bar", "foo")
il.ignore("foo", "bar")
il.clear()
assert not il.are_ignored("foo", "bar")
assert not il.are_ignored("bar", "foo")
eq_(0, len(il))
def test_add_same_twice():
il = IgnoreList()
il.Ignore("foo", "bar")
il.Ignore("bar", "foo")
il.ignore("foo", "bar")
il.ignore("bar", "foo")
eq_(1, len(il))
def test_save_to_xml():
il = IgnoreList()
il.Ignore("foo", "bar")
il.Ignore("foo", "bleh")
il.Ignore("bleh", "bar")
il.ignore("foo", "bar")
il.ignore("foo", "bleh")
il.ignore("bleh", "bar")
f = io.BytesIO()
il.save_to_xml(f)
f.seek(0)
@ -79,17 +79,17 @@ def test_save_to_xml():
def test_save_then_load():
il = IgnoreList()
il.Ignore("foo", "bar")
il.Ignore("foo", "bleh")
il.Ignore("bleh", "bar")
il.Ignore("\u00e9", "bar")
il.ignore("foo", "bar")
il.ignore("foo", "bleh")
il.ignore("bleh", "bar")
il.ignore("\u00e9", "bar")
f = io.BytesIO()
il.save_to_xml(f)
f.seek(0)
il = IgnoreList()
il.load_from_xml(f)
eq_(4, len(il))
assert il.AreIgnored("\u00e9", "bar")
assert il.are_ignored("\u00e9", "bar")
def test_load_xml_with_empty_file_tags():
@ -103,16 +103,16 @@ def test_load_xml_with_empty_file_tags():
def test_are_ignore_works_when_a_child_is_a_key_somewhere_else():
il = IgnoreList()
il.Ignore("foo", "bar")
il.Ignore("bar", "baz")
assert il.AreIgnored("bar", "foo")
il.ignore("foo", "bar")
il.ignore("bar", "baz")
assert il.are_ignored("bar", "foo")
def test_no_dupes_when_a_child_is_a_key_somewhere_else():
il = IgnoreList()
il.Ignore("foo", "bar")
il.Ignore("bar", "baz")
il.Ignore("bar", "foo")
il.ignore("foo", "bar")
il.ignore("bar", "baz")
il.ignore("bar", "foo")
eq_(2, len(il))
@ -121,7 +121,7 @@ def test_iterate():
il = IgnoreList()
expected = [("foo", "bar"), ("bar", "baz"), ("foo", "baz")]
for i in expected:
il.Ignore(i[0], i[1])
il.ignore(i[0], i[1])
for i in il:
expected.remove(i) # No exception should be raised
assert not expected # expected should be empty
@ -129,18 +129,18 @@ def test_iterate():
def test_filter():
il = IgnoreList()
il.Ignore("foo", "bar")
il.Ignore("bar", "baz")
il.Ignore("foo", "baz")
il.Filter(lambda f, s: f == "bar")
il.ignore("foo", "bar")
il.ignore("bar", "baz")
il.ignore("foo", "baz")
il.filter(lambda f, s: f == "bar")
eq_(1, len(il))
assert not il.AreIgnored("foo", "bar")
assert il.AreIgnored("bar", "baz")
assert not il.are_ignored("foo", "bar")
assert il.are_ignored("bar", "baz")
def test_save_with_non_ascii_items():
il = IgnoreList()
il.Ignore("\xac", "\xbf")
il.ignore("\xac", "\xbf")
f = io.BytesIO()
try:
il.save_to_xml(f)
@ -151,29 +151,29 @@ def test_save_with_non_ascii_items():
def test_len():
il = IgnoreList()
eq_(0, len(il))
il.Ignore("foo", "bar")
il.ignore("foo", "bar")
eq_(1, len(il))
def test_nonzero():
il = IgnoreList()
assert not il
il.Ignore("foo", "bar")
il.ignore("foo", "bar")
assert il
def test_remove():
il = IgnoreList()
il.Ignore("foo", "bar")
il.Ignore("foo", "baz")
il.ignore("foo", "bar")
il.ignore("foo", "baz")
il.remove("bar", "foo")
eq_(len(il), 1)
assert not il.AreIgnored("foo", "bar")
assert not il.are_ignored("foo", "bar")
def test_remove_non_existant():
il = IgnoreList()
il.Ignore("foo", "bar")
il.Ignore("foo", "baz")
il.ignore("foo", "bar")
il.ignore("foo", "baz")
with raises(ValueError):
il.remove("foo", "bleh")

View File

@ -391,8 +391,8 @@ def test_ignore_list(fake_fileexists):
f2.path = Path("dir2/foobar")
f3.path = Path("dir3/foobar")
ignore_list = IgnoreList()
ignore_list.Ignore(str(f1.path), str(f2.path))
ignore_list.Ignore(str(f1.path), str(f3.path))
ignore_list.ignore(str(f1.path), str(f2.path))
ignore_list.ignore(str(f1.path), str(f3.path))
r = s.get_dupe_groups([f1, f2, f3], ignore_list=ignore_list)
eq_(len(r), 1)
g = r[0]
@ -415,8 +415,8 @@ def test_ignore_list_checks_for_unicode(fake_fileexists):
f2.path = Path("foo2\u00e9")
f3.path = Path("foo3\u00e9")
ignore_list = IgnoreList()
ignore_list.Ignore(str(f1.path), str(f2.path))
ignore_list.Ignore(str(f1.path), str(f3.path))
ignore_list.ignore(str(f1.path), str(f2.path))
ignore_list.ignore(str(f1.path), str(f3.path))
r = s.get_dupe_groups([f1, f2, f3], ignore_list=ignore_list)
eq_(len(r), 1)
g = r[0]

View File

@ -230,8 +230,8 @@ def log_calls(func):
"""
def wrapper(*args, **kwargs):
unifiedArgs = _unify_args(func, args, kwargs)
wrapper.calls.append(unifiedArgs)
unified_args = _unify_args(func, args, kwargs)
wrapper.calls.append(unified_args)
return func(*args, **kwargs)
wrapper.calls = []

View File

@ -4,7 +4,6 @@
# which should be included with this package. The terms are also available at
# http://www.gnu.org/licenses/gpl-3.0.html
from qt.platform import HELP_PATH
import sys
import os
import os.path as op