Mercurial > libervia-backend
comparison src/memory/memory.py @ 635:eff8772fd472
core: memory's updateEntityData improvments.
- passing @ALL@ to updateEntityData updates the specified key for all entities
- passing @NONE@ to updateEntityData deletes the specified key
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 08 Sep 2013 19:12:59 +0200 |
parents | ca2cae6b2c6d |
children | 99eee75ec1b7 |
comparison
equal
deleted
inserted
replaced
634:ca2cae6b2c6d | 635:eff8772fd472 |
---|---|
561 self.params_gen[(category, name)] = value | 561 self.params_gen[(category, name)] = value |
562 self.storage.setGenParam(category, name, value) | 562 self.storage.setGenParam(category, name, value) |
563 for profile in self.storage.getProfilesList(): | 563 for profile in self.storage.getProfilesList(): |
564 if self.host.isConnected(profile): | 564 if self.host.isConnected(profile): |
565 self.host.bridge.paramUpdate(name, value, category, profile) | 565 self.host.bridge.paramUpdate(name, value, category, profile) |
566 self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile) | |
566 return | 567 return |
567 | 568 |
568 assert (node[0] == 'individual') | 569 assert (node[0] == 'individual') |
569 assert (profile_key != "@NONE@") | 570 assert (profile_key != "@NONE@") |
570 | 571 |
573 print "clique", node.toxml() | 574 print "clique", node.toxml() |
574 else: | 575 else: |
575 if self.host.isConnected(profile): # key can not exists if profile is not connected | 576 if self.host.isConnected(profile): # key can not exists if profile is not connected |
576 self.params[profile][(category, name)] = value | 577 self.params[profile][(category, name)] = value |
577 self.host.bridge.paramUpdate(name, value, category, profile) | 578 self.host.bridge.paramUpdate(name, value, category, profile) |
579 self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile) | |
578 self.storage.setIndParam(category, name, value, profile) | 580 self.storage.setIndParam(category, name, value, profile) |
579 | 581 |
580 | 582 |
581 class Memory(object): | 583 class Memory(object): |
582 """This class manage all persistent informations""" | 584 """This class manage all persistent informations""" |
802 | 804 |
803 entity_data.setdefault("presence", {})[resource] = (show, priority, statuses) | 805 entity_data.setdefault("presence", {})[resource] = (show, priority, statuses) |
804 | 806 |
805 def updateEntityData(self, entity_jid, key, value, profile_key): | 807 def updateEntityData(self, entity_jid, key, value, profile_key): |
806 """Set a misc data for an entity | 808 """Set a misc data for an entity |
807 @param entity_jid: JID of the entity | 809 @param entity_jid: JID of the entity, or '@ALL@' to update all entities) |
808 @param key: key to set (eg: "type") | 810 @param key: key to set (eg: "type") |
809 @param value: value for this key (eg: "chatroom") | 811 @param value: value for this key (eg: "chatroom"), or '@NONE@' to delete |
810 @param profile_key: %(doc_profile_key)s | 812 @param profile_key: %(doc_profile_key)s |
811 """ | 813 """ |
812 profile = self.getProfileName(profile_key) | 814 profile = self.getProfileName(profile_key) |
813 if not profile: | 815 if not profile: |
814 raise exceptions.UnknownProfileError(_('Trying to get entity data for a non-existant profile')) | 816 raise exceptions.UnknownProfileError(_('Trying to get entity data for a non-existant profile')) |
815 if not profile in self.entitiesCache: | 817 if not profile in self.entitiesCache: |
816 raise exceptions.ProfileNotInCacheError | 818 raise exceptions.ProfileNotInCacheError |
817 entity_data = self.entitiesCache[profile].setdefault(entity_jid.userhost(), {}) | 819 if entity_jid == "@ALL@": |
818 entity_data[key] = value | 820 entities_map = self.entitiesCache[profile] |
819 if isinstance(value, basestring): | 821 else: |
820 self.host.bridge.entityDataUpdated(entity_jid.userhost(), key, value, profile) | 822 entity = entity_jid.userhost() |
823 self.entitiesCache[profile].setdefault(entity, {}) | |
824 entities_map = {entity: self.entitiesCache[profile][entity]} | |
825 for entity in entities_map: | |
826 entity_map = entities_map[entity] | |
827 if value == "@NONE@" and key in entity_map: | |
828 del entity_map[key] | |
829 else: | |
830 entity_map[key] = value | |
831 if isinstance(value, basestring): | |
832 self.host.bridge.entityDataUpdated(entity, key, value, profile) | |
821 | 833 |
822 def getEntityData(self, entity_jid, keys_list, profile_key): | 834 def getEntityData(self, entity_jid, keys_list, profile_key): |
823 """Get a list of cached values for entity | 835 """Get a list of cached values for entity |
824 @param entity_jid: JID of the entity | 836 @param entity_jid: JID of the entity |
825 @param keys_list: list of keys to get, empty list for everything | 837 @param keys_list: list of keys to get, empty list for everything |