# HG changeset patch # User souliane # Date 1378660379 -7200 # Node ID eff8772fd472ae3caf3cfd010a960814dad8605b # Parent ca2cae6b2c6d4726ce1b304f3518e184fc947077 core: memory's updateEntityData improvments. - passing @ALL@ to updateEntityData updates the specified key for all entities - passing @NONE@ to updateEntityData deletes the specified key diff -r ca2cae6b2c6d -r eff8772fd472 src/memory/memory.py --- a/src/memory/memory.py Thu Sep 05 20:28:44 2013 +0200 +++ b/src/memory/memory.py Sun Sep 08 19:12:59 2013 +0200 @@ -563,6 +563,7 @@ for profile in self.storage.getProfilesList(): if self.host.isConnected(profile): self.host.bridge.paramUpdate(name, value, category, profile) + self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile) return assert (node[0] == 'individual') @@ -575,6 +576,7 @@ if self.host.isConnected(profile): # key can not exists if profile is not connected self.params[profile][(category, name)] = value self.host.bridge.paramUpdate(name, value, category, profile) + self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile) self.storage.setIndParam(category, name, value, profile) @@ -804,9 +806,9 @@ def updateEntityData(self, entity_jid, key, value, profile_key): """Set a misc data for an entity - @param entity_jid: JID of the entity + @param entity_jid: JID of the entity, or '@ALL@' to update all entities) @param key: key to set (eg: "type") - @param value: value for this key (eg: "chatroom") + @param value: value for this key (eg: "chatroom"), or '@NONE@' to delete @param profile_key: %(doc_profile_key)s """ profile = self.getProfileName(profile_key) @@ -814,10 +816,20 @@ raise exceptions.UnknownProfileError(_('Trying to get entity data for a non-existant profile')) if not profile in self.entitiesCache: raise exceptions.ProfileNotInCacheError - entity_data = self.entitiesCache[profile].setdefault(entity_jid.userhost(), {}) - entity_data[key] = value - if isinstance(value, basestring): - self.host.bridge.entityDataUpdated(entity_jid.userhost(), key, value, profile) + if entity_jid == "@ALL@": + entities_map = self.entitiesCache[profile] + else: + entity = entity_jid.userhost() + self.entitiesCache[profile].setdefault(entity, {}) + entities_map = {entity: self.entitiesCache[profile][entity]} + for entity in entities_map: + entity_map = entities_map[entity] + if value == "@NONE@" and key in entity_map: + del entity_map[key] + else: + entity_map[key] = value + if isinstance(value, basestring): + self.host.bridge.entityDataUpdated(entity, key, value, profile) def getEntityData(self, entity_jid, keys_list, profile_key): """Get a list of cached values for entity