[#138] Completed re-prioritization workflow, now all that is needed is to add more criteria, handle corner case and build the GUI for it.

This commit is contained in:
Virgil Dupras 2011-09-08 12:36:57 -04:00
parent 518228a368
commit 9c30486f14
4 changed files with 42 additions and 4 deletions

View File

@ -353,6 +353,11 @@ class DupeGuru(RegistrableApplication, Broadcaster):
logging.warning("dupeGuru Warning: %s" % str(e))
return False
def reprioritize_groups(self, sort_key):
for group in self.results.groups:
group.prioritize(key_func=sort_key)
self._results_changed()
def reveal_selected(self):
if self.selected_dupes:
self._reveal_path(self.selected_dupes[0].path)

View File

@ -21,10 +21,30 @@ class CriterionCategoryList(SelectableList):
class PrioritizeDialog:
def __init__(self, view, app):
self.app = app
self.categories = [KindCategory(app.results)]
self.category_list = CriterionCategoryList(self)
self.criteria_list = []
self.criteria = []
self.criteria_list = SelectableList()
self.prioritizations = []
#--- Private
def _sort_key(self, dupe):
# Our sort key consists of a tuple of inverted bool values represented as ints. When a dupe
# fits a criteria, we want it at the top of the listm and thus we'll give it the value 0.
# When the dupe doesn't fit a criteria, we ant it at the bottom, and we give the value 1.
result = (crit.test_dupe(dupe) for crit in self.prioritizations)
return tuple((0 if value else 1) for value in result)
#--- Public
def select_category(self, category):
criteria = category.criteria_list()
self.criteria_list = [c.value for c in criteria]
self.criteria = category.criteria_list()
self.criteria_list[:] = [c.value for c in self.criteria]
def add_selected(self):
# Add selected criteria in criteria_list to prioritization_list.
crit = self.criteria[self.criteria_list.selected_index]
self.prioritizations.append(crit)
def perform_reprioritization(self):
self.app.reprioritize_groups(self._sort_key)

View File

@ -29,6 +29,9 @@ class Criterion:
self.category = category
self.value = value
def test_dupe(self, dupe):
return self.category._extract_value(dupe) == self.value
@property
def display(self):
return "{} ({})".format(self.category, self.value)

View File

@ -40,4 +40,14 @@ def app_normal_results():
def test_kind_subcrit(app):
# The subcriteria of the "Kind" criteria is a list of extensions contained in the dupes.
app.select_pri_criterion("Kind")
eq_(app.pdialog.criteria_list, ['ext1', 'ext2'])
eq_(app.pdialog.criteria_list[:], ['ext1', 'ext2'])
@with_app(app_normal_results)
def test_perform_reprioritization(app):
# Just a simple test of the system as a whole.
# select a criterion, and perform re-prioritization and see if it worked.
app.select_pri_criterion("Kind")
app.pdialog.criteria_list.select([1]) # ext2
app.pdialog.add_selected()
app.pdialog.perform_reprioritization()
eq_(app.rtable[0].data[0], 'foo2.ext2')