class PostToWallTask(QueueTask): command = 'wall_post' @classmethod def describe(cls): return 'post to a user\'s wall' @classmethod def help(cls): return 'usage: %s user_id contents' % cls.command def execute(self, node): self.other_user_id, self.value = get_first_word(self.args) node.multiple_get( key = '%s_friends' % self.other_user_id, all_completed_callback=self.got_friends_file, ) def got_friends_file(self, multiple_append_request_id, (node, multiple_append_data)): max_version = VectorVersion() for ring_id in multiple_append_data['keys']: for physical_key in multiple_append_data['keys'][ring_id]: (contact, value) = multiple_append_data['keys'][ring_id][physical_key] if value != None: max_version.merge(value['version']) self.do_post(node, max_version)
def got_append(self, contact, obj): key = self.resolve_key(obj.key, obj.raw_key) if key not in self.data: self.data[key] = { 'data': [], 'requires': VectorVersionList(), 'version': VectorVersion(), } self.data[key]['data'].append(obj.value) self.data[key]['requires'].merge( VectorVersionList.from_tuples(obj.requires)) self.data[key]['version'].increment(obj.user_id) contact.send( AppendResponse(request_id=obj.request_id, version=self.data[key]['version'].to_tuples()))
def from_tuples(cls, tuples): version_list = VectorVersionList() for x in tuples: version_list.add(x[0], VectorVersion.from_tuples(x[1])) return version_list
def value_from_wire(self, data): return (None if data == None else { 'data': data['data'], 'requires': VectorVersionList.from_tuples(data['requires']), 'version': VectorVersion.from_tuples(data['version']), })