[kupfer: 12/51] grouping: Bottom-up grouping with GroupingLeaf.grouping_slots
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer: 12/51] grouping: Bottom-up grouping with GroupingLeaf.grouping_slots
- Date: Sun, 10 Jan 2010 11:57:50 +0000 (UTC)
commit 7fe8ba95a0e0c043e8b417b174e0e63cdc38a7e7
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Thu Jan 7 02:29:45 2010 +0100
grouping: Bottom-up grouping with GroupingLeaf.grouping_slots
Let each GroupingLeaf tell how it wants to group with other leaves,
instead of the Source deciding. Each leaf type provides grouping_keys
which tell which (slot, value) pairs will it wants to have considered
to merge with.
kupfer/obj/grouping.py | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/kupfer/obj/grouping.py b/kupfer/obj/grouping.py
index 6a87563..f00b384 100644
--- a/kupfer/obj/grouping.py
+++ b/kupfer/obj/grouping.py
@@ -29,6 +29,8 @@ class GroupingLeaf (Leaf):
slot identifies the slot, and the value is something that
must be equal to be grouped.
"""
+ grouping_slots = ()
+
def __init__(self, obj, name):
Leaf.__init__(self, obj, name)
self.links = [self]
@@ -61,7 +63,6 @@ class GroupingLeaf (Leaf):
return (leaf.object[key] for leaf in self.links if key in leaf.object)
class GroupingSource (Source):
- grouping_keys = [EMAIL_KEY, NAME_KEY, JID_KEY]
def __init__(self, name, sources):
Source.__init__(self, name)
@@ -84,10 +85,12 @@ class GroupingSource (Source):
yield leaf
continue
slots = leaf.slots()
- for slot in self.grouping_keys:
- if slot not in slots:
- continue
+ for slot in leaf.grouping_slots:
groups.setdefault((slot, slots[slot]), set()).add(leaf)
+ if not leaf.grouping_slots:
+ self.output_error("GroupingLeaf has no grouping slots",
+ repr(leaf))
+
self.output_debug("LISTED ALL", time.time() -st)
# Keep track of keys that are only duplicate references
@@ -106,7 +109,7 @@ class GroupingSource (Source):
if len(leaves) <= 1:
continue
for leaf in list(leaves):
- for slot2 in self.grouping_keys:
+ for slot2 in leaf.grouping_slots:
for value2 in leaf.all(slot2):
merge_groups((slot, value), (slot2, value2))
self.output_debug("MERGED ALL", time.time() - st)
@@ -170,6 +173,7 @@ class _GroupedItemsSource(Source):
yield leaf
class ContactLeaf(GroupingLeaf):
+ grouping_slots = (EMAIL_KEY, NAME_KEY)
def get_icon_name(self):
return "stock_person"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]