comparison idavoll/backend.py @ 101:b75fcc554358

Added support for disco info meta data.
author Ralph Meijer <ralphm@ik.nu>
date Sun, 02 Jan 2005 20:10:02 +0000
parents b9c449f4c167
children 8d8946e67fcb
comparison
equal deleted inserted replaced
100:0228725b705b 101:b75fcc554358
169 169
170 class BackendService(service.MultiService, utility.EventDispatcher): 170 class BackendService(service.MultiService, utility.EventDispatcher):
171 171
172 __implements__ = IBackendService, 172 __implements__ = IBackendService,
173 173
174 options = {"pubsub#persist_items":
175 {"type": "boolean",
176 "label": "Persist items to storage"},
177 "pubsub#deliver_payloads":
178 {"type": "boolean",
179 "label": "Deliver payloads with event notifications"},
180 }
181
182 default_config = {"pubsub#persist_items": True,
183 "pubsub#deliver_payloads": True,
184 }
185
174 def __init__(self, storage): 186 def __init__(self, storage):
175 service.MultiService.__init__(self) 187 service.MultiService.__init__(self)
176 utility.EventDispatcher.__init__(self) 188 utility.EventDispatcher.__init__(self)
177 self.storage = storage 189 self.storage = storage
178 190
188 def get_node_type(self, node_id): 200 def get_node_type(self, node_id):
189 return self.storage.get_node_type(node_id) 201 return self.storage.get_node_type(node_id)
190 202
191 def get_nodes(self): 203 def get_nodes(self):
192 return self.storage.get_nodes() 204 return self.storage.get_nodes()
205
206 def get_node_meta_data(self, node_id):
207 d = self.storage.get_node_configuration(node_id)
208
209 d.addCallback(self._make_meta_data)
210 return d
211
212 def _make_meta_data(self, meta_data):
213 options = []
214 for key, value in meta_data.iteritems():
215 if self.options.has_key(key):
216 option = {"var": key}
217 option.update(self.options[key])
218 option["value"] = value
219 options.append(option)
220
221 return options
193 222
194 class PublishService(service.Service): 223 class PublishService(service.Service):
195 224
196 __implements__ = IPublishService, 225 __implements__ = IPublishService,
197 226
303 332
304 class NodeCreationService(service.Service): 333 class NodeCreationService(service.Service):
305 334
306 __implements__ = INodeCreationService, 335 __implements__ = INodeCreationService,
307 336
308 options = {"pubsub#persist_items":
309 {"type": "boolean",
310 "label": "Persist items to storage"},
311 "pubsub#deliver_payloads":
312 { "type": "boolean",
313 "label": "Deliver payloads with event notifications"}
314 }
315
316 def supports_instant_nodes(self): 337 def supports_instant_nodes(self):
317 return True 338 return True
318 339
319 def create_node(self, node_id, requestor): 340 def create_node(self, node_id, requestor):
320 if not node_id: 341 if not node_id:
327 348
328 def get_node_configuration(self, node_id): 349 def get_node_configuration(self, node_id):
329 if node_id: 350 if node_id:
330 d = self.parent.storage.get_node_configuration(node_id) 351 d = self.parent.storage.get_node_configuration(node_id)
331 else: 352 else:
332 d = defer.succeed({"pubsub#persist_items": True, 353 # XXX: this is disabled in pubsub.py
333 "pubsub#deliver_payloads": True}) 354 d = defer.succeed(self.parent.default_config)
334 355
335 d.addCallback(self._make_config) 356 d.addCallback(self._make_config)
336 return d 357 return d
337 358
338 def _make_config(self, config): 359 def _make_config(self, config):
339 options = [] 360 options = []
340 for key, value in config.iteritems(): 361 for key, value in self.parent.options.iteritems():
341 option = {"var": key} 362 option = {"var": key}
342 option.update(self.options[key]) 363 option.update(value)
343 if option["type"] == "boolean": 364 if config.has_key(key):
344 option["value"] = str(int(bool(value))) 365 option["value"] = config[key]
345 else:
346 option["value"] = str(value)
347 options.append(option) 366 options.append(option)
348 367
349 return options 368 return options
350 369
351 def set_node_configuration(self, node_id, options, requestor): 370 def set_node_configuration(self, node_id, options, requestor):
352 for key in options.iterkeys(): 371 for key in options.iterkeys():
353 if not self.options.has_key(key): 372 if not self.parent.options.has_key(key):
354 raise InvalidConfigurationOption 373 raise InvalidConfigurationOption
355 374
356 d = self.parent.storage.get_affiliation(node_id, requestor) 375 d = self.parent.storage.get_affiliation(node_id, requestor)
357 d.addCallback(self._do_set_node_configuration, node_id, options) 376 d.addCallback(self._do_set_node_configuration, node_id, options)
358 return d 377 return d