changeset 318:b544bec477dd

core: multiple identities with same category/type are now managed with getServerServiceEntities
author Goffi <goffi@goffi.org>
date Fri, 06 May 2011 15:34:02 +0200
parents f1f7c94278f2
children 5bb1cfc105d0
files src/tools/memory.py
diffstat 1 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/tools/memory.py	Fri May 06 15:33:07 2011 +0200
+++ b/src/tools/memory.py	Fri May 06 15:34:02 2011 +0200
@@ -553,12 +553,25 @@
         @param profile: which profile is using this server ?"""
         if not self.server_identities.has_key(profile):
             self.server_identities[profile] = {}
-        self.server_identities[profile][(category, type)] = entity
+        if not self.server_identities[profile].has_key((category, type)):
+            self.server_identities[profile][(category, type)]=set()
+        self.server_identities[profile][(category, type)].add(entity)
+
+    def getServerServiceEntities(self, category, type, profile):
+        """Return all available entities for a service"""
+        if self.server_identities.has_key(profile):
+            return self.server_identities[profile].get((category, type), set())
+        else:
+            return None
 
     def getServerServiceEntity(self, category, type, profile):
-        if self.server_identities.has_key(profile):
-            return self.server_identities[profile].get((category, type))
-        return None
+        """Helper method to get first available entity for a service"""
+        entities = self.getServerServiceEntities(category, type, profile)
+        if entities == None:
+            warning(_("Entities not available, maybe they haven't been asked to server yet ?"))
+            return None
+        else:
+            return list(entities)[0] if entities else None
 
     def hasServerFeature(self, feature, profile_key='@DEFAULT@'):
         """Tell if the server of the profile has the required feature"""