Mercurial > libervia-backend
diff tools/memory.py @ 65:d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
/!\ profiles not managed yet for dbus signals
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 31 Jan 2010 15:57:03 +1100 |
parents | d46f849664aa |
children | 8147b4f40809 |
line wrap: on
line diff
--- a/tools/memory.py Sat Jan 30 16:17:33 2010 +1100 +++ b/tools/memory.py Sun Jan 31 15:57:03 2010 +1100 @@ -36,7 +36,7 @@ SAVEFILE_PRIVATE="/private" #file used to store misc values (mainly for plugins) class Param(): - """This class manage parameter with xml""" + """This class manage parameters with xml""" ### TODO: add desciption in params #TODO: mettre Watched dans un plugin @@ -505,53 +505,99 @@ return None - def addContact(self, contact_jid, attributes, groups): + def addContact(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'): debug("Memory addContact: %s",contact_jid.userhost()) + profile = self.getProfileName(profile_key) + if not profile: + error ('Trying to add a contact to a non-existant profile') + return assert(isinstance(attributes,dict)) assert(isinstance(groups,set)) - self.contacts[contact_jid.userhost()]=[attributes, groups] + if not self.contacts.has_key(profile): + self.contacts[profile] = {} + self.contacts[profile][contact_jid.userhost()]=[attributes, groups] - def delContact(self, contact_jid): + def delContact(self, contact_jid, profile_key='@DEFAULT@'): debug("Memory delContact: %s",contact_jid.userhost()) - if self.contacts.has_key(contact_jid.userhost()): - del self.contacts[contact_jid.userhost()] + profile = self.getProfileName(profile_key) + if not profile: + error ('Trying to delete a contact for a non-existant profile') + return + if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): + del self.contacts[profile][contact_jid.userhost()] - def getContact(self, contact_jid): - if self.contacts.has_key(contact_jid.userhost()): - self.contacts[contact_jid.userhost()] + def getContact(self, contact_jid, profile_key='@DEFAULT@'): + profile = self.getProfileName(profile_key) + if not profile: + error('Asking a contact for a non-existant profile') + return None + if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): + self.contacts[profile][contact_jid.userhost()] else: return None - def getContacts(self): + def getContacts(self, profile_key='@DEFAULT@'): + """Return list of contacts for given profile + @param profile_key: profile key + @return list of [contact, attr, groups]""" debug ("Memory getContact OK (%s)", self.contacts) + profile = self.getProfileName(profile_key) + if not profile: + error('Asking contacts for a non-existant profile') + return [] ret=[] - for contact in self.contacts: - attr, groups = self.contacts[contact] + for contact in self.contacts[profile]: + attr, groups = self.contacts[profile][contact] ret.append([contact, attr, groups ]) return ret - def addPresenceStatus(self, contact_jid, show, priority, statuses): - if not self.presenceStatus.has_key(contact_jid.userhost()): - self.presenceStatus[contact_jid.userhost()] = {} + def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'): + profile = self.getProfileName(profile_key) + if not profile: + error('Trying to add presence status to a non-existant profile') + return + if not self.presenceStatus.has_key(profile): + self.presenceStatus[profile] = {} + if not self.presenceStatus[profile].has_key(contact_jid.userhost()): + self.presenceStatus[profile][contact_jid.userhost()] = {} resource = jid.parse(contact_jid.full())[2] or '' - self.presenceStatus[contact_jid.userhost()][resource] = (show, priority, statuses) + self.presenceStatus[profile][contact_jid.userhost()][resource] = (show, priority, statuses) - def addWaitingSub(self, type, contact_jid): + def addWaitingSub(self, type, contact_jid, profile_key): """Called when a subcription request is received""" - self.subscriptions[contact_jid] = type + profile = self.getProfileName(profile_key) + assert(profile) + if not self.subscriptions.has_key(profile): + self.subscriptions[profile] = {} + self.subscriptions[profile][contact_jid] = type - def delWaitingSub(self, contact_jid): + def delWaitingSub(self, contact_jid, profile_key): """Called when a subcription request is finished""" - if self.subscriptions.has_key(contact_jid): - del self.subscriptions[contact_jid] + profile = self.getProfileName(profile_key) + assert(profile) + if self.subscriptions.has_key(profile) and self.subscriptions[profile].has_key(contact_jid): + del self.subscriptions[profile][contact_jid] - def getWaitingSub(self): + def getWaitingSub(self, profile_key='@DEFAULT@'): """Called to get a list of currently waiting subscription requests""" - return self.subscriptions + profile = self.getProfileName(profile_key) + if not profile: + error('Asking waiting subscriptions for a non-existant profile') + return {} + if not self.subscriptions.has_key(profile): + return {} + + return self.subscriptions[profile] - def getPresenceStatus(self): - debug ("Memory getPresenceStatus (%s)", self.presenceStatus) - return self.presenceStatus + def getPresenceStatus(self, profile_key='@DEFAULT@'): + profile = self.getProfileName(profile_key) + if not profile: + error('Asking contacts for a non-existant profile') + return {} + if not self.presenceStatus.has_key(profile): + self.presenceStatus[profile] = {} + debug ("Memory getPresenceStatus (%s)", self.presenceStatus[profile]) + return self.presenceStatus[profile] def getParamA(self, name, category, attr="value", profile_key="@DEFAULT@"): return self.params.getParamA(name, category, attr, profile_key)