[kupfer: 20/51] grouping: create hosts.py for HostLeaf, add check_key method in GroupingLeaf



commit 7846b07ea00ceed89b7ba0404283937fc32dd919
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date:   Thu Jan 7 21:16:00 2010 +0100

    grouping: create hosts.py for HostLeaf, add check_key method in GroupingLeaf
    
    ckeck_key method can be used instead of 'key in leaf and leaf[key]'.

 kupfer/obj/grouping.py |    9 ++++-----
 kupfer/obj/hosts.py    |   22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/kupfer/obj/grouping.py b/kupfer/obj/grouping.py
index dcf638e..2f13440 100644
--- a/kupfer/obj/grouping.py
+++ b/kupfer/obj/grouping.py
@@ -12,8 +12,6 @@ from kupfer import utils
 __author__ = ("Karol BÄ?dkowski <karol bedkowsk+gh gmail com>, "
               "Ulrik Sverdrup <ulrik sverdrup gmail com>" )
 
-HOSTS_CATEGORY = "Hosts"
-
 class GroupingLeaf (Leaf):
 	"""
 	A Leaf that groups with other leaves inside Grouping Sources
@@ -58,6 +56,10 @@ class GroupingLeaf (Leaf):
 		"Return iterator of all values for @key"
 		return (leaf.object[key] for leaf in self.links if key in leaf.object)
 
+	def check_key(self, key):
+		''' check if GroupedLeaf has non empty value for @key '''
+		return any(bool(leaf.object.get(key)) for leaf in self.links)
+
 class GroupingSource (Source):
 
 	def __init__(self, name, sources):
@@ -166,8 +168,5 @@ class _GroupedItemsSource(Source):
 		for leaf in self._leaf.links:
 			yield leaf
 
-class HostLeaf(GroupingLeaf):
-	def get_icon_name(self):
-		return "stock_host"
 
 
diff --git a/kupfer/obj/hosts.py b/kupfer/obj/hosts.py
new file mode 100644
index 0000000..bbf3c06
--- /dev/null
+++ b/kupfer/obj/hosts.py
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+"""
+Kupfer's Hosts API
+
+Main definition and *constructor* classes.
+"""
+
+from kupfer.obj.grouping import GroupingLeaf 
+
+__author__ = ("Ulrik Sverdrup <ulrik sverdrup gmail com>, "
+              "Karol BÄ?dkowski <karol bedkowsk+gh gmail com>" )
+
+HOST_NAME_KEY = "HOST_NAME"
+HOST_ADDRESS_KEY = "HOST_ADDRESS"
+
+class HostLeaf(GroupingLeaf):
+	grouping_slots = (HOST_NAME_KEY, HOST_ADDRESS_KEY)
+
+	def get_icon_name(self):
+		return "stock_host"
+
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]