From 47dbe805bb563f3f4ffb90730fc8b1349448789e Mon Sep 17 00:00:00 2001 From: Andrew Senetar Date: Wed, 25 Aug 2021 01:11:24 -0500 Subject: [PATCH] More cleanup and fixed a flake8 build issue --- core/app.py | 14 ++--- core/gui/base.py | 5 ++ core/gui/ignore_list_dialog.py | 2 +- core/ignore.py | 17 +++--- core/scanner.py | 2 +- core/tests/app_test.py | 12 ++-- core/tests/ignore_test.py | 100 ++++++++++++++++----------------- core/tests/scanner_test.py | 8 +-- hscommon/testutil.py | 4 +- package.py | 1 - 10 files changed, 83 insertions(+), 82 deletions(-) diff --git a/core/app.py b/core/app.py index 117c2554..37921e94 100644 --- a/core/app.py +++ b/core/app.py @@ -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): diff --git a/core/gui/base.py b/core/gui/base.py index d6bf3523..72095b81 100644 --- a/core/gui/base.py +++ b/core/gui/base.py @@ -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 diff --git a/core/gui/ignore_list_dialog.py b/core/gui/ignore_list_dialog.py index f2c4f87b..ca126bf0 100644 --- a/core/gui/ignore_list_dialog.py +++ b/core/gui/ignore_list_dialog.py @@ -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): diff --git a/core/ignore.py b/core/ignore.py index cd206f48..095da4fe 100644 --- a/core/ignore.py +++ b/core/ignore.py @@ -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. diff --git a/core/scanner.py b/core/scanner.py index 1de7c953..ea68a20a 100644 --- a/core/scanner.py +++ b/core/scanner.py @@ -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 { diff --git a/core/tests/app_test.py b/core/tests/app_test.py index d05ebac4..9601486a 100644 --- a/core/tests/app_test.py +++ b/core/tests/app_test.py @@ -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() diff --git a/core/tests/ignore_test.py b/core/tests/ignore_test.py index 9021b653..fc8a3943 100644 --- a/core/tests/ignore_test.py +++ b/core/tests/ignore_test.py @@ -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") diff --git a/core/tests/scanner_test.py b/core/tests/scanner_test.py index 519d3a5f..e9167360 100644 --- a/core/tests/scanner_test.py +++ b/core/tests/scanner_test.py @@ -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] diff --git a/hscommon/testutil.py b/hscommon/testutil.py index 92255d45..b87415b0 100644 --- a/hscommon/testutil.py +++ b/hscommon/testutil.py @@ -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 = [] diff --git a/package.py b/package.py index a2515679..01103387 100644 --- a/package.py +++ b/package.py @@ -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