comparison src/tools/memory.py @ 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 15a12bf2bb62
children 0f9925193586
comparison
equal deleted inserted replaced
317:f1f7c94278f2 318:b544bec477dd
551 """Add an identity discovered from server 551 """Add an identity discovered from server
552 @param feature: string of the feature 552 @param feature: string of the feature
553 @param profile: which profile is using this server ?""" 553 @param profile: which profile is using this server ?"""
554 if not self.server_identities.has_key(profile): 554 if not self.server_identities.has_key(profile):
555 self.server_identities[profile] = {} 555 self.server_identities[profile] = {}
556 self.server_identities[profile][(category, type)] = entity 556 if not self.server_identities[profile].has_key((category, type)):
557 self.server_identities[profile][(category, type)]=set()
558 self.server_identities[profile][(category, type)].add(entity)
559
560 def getServerServiceEntities(self, category, type, profile):
561 """Return all available entities for a service"""
562 if self.server_identities.has_key(profile):
563 return self.server_identities[profile].get((category, type), set())
564 else:
565 return None
557 566
558 def getServerServiceEntity(self, category, type, profile): 567 def getServerServiceEntity(self, category, type, profile):
559 if self.server_identities.has_key(profile): 568 """Helper method to get first available entity for a service"""
560 return self.server_identities[profile].get((category, type)) 569 entities = self.getServerServiceEntities(category, type, profile)
561 return None 570 if entities == None:
571 warning(_("Entities not available, maybe they haven't been asked to server yet ?"))
572 return None
573 else:
574 return list(entities)[0] if entities else None
562 575
563 def hasServerFeature(self, feature, profile_key='@DEFAULT@'): 576 def hasServerFeature(self, feature, profile_key='@DEFAULT@'):
564 """Tell if the server of the profile has the required feature""" 577 """Tell if the server of the profile has the required feature"""
565 profile = self.getProfileName(profile_key) 578 profile = self.getProfileName(profile_key)
566 if not profile: 579 if not profile: