Mercurial > libervia-pubsub
comparison idavoll/backend.py @ 205:e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Author: ralphm.
Fixes #13.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Mon, 04 Aug 2008 07:10:45 +0000 |
parents | 77c61e2b8c75 |
children | 274a45d2a5ab |
comparison
equal
deleted
inserted
replaced
204:b4bf0a5ce50d | 205:e6b710bf2b24 |
---|---|
266 return d | 266 return d |
267 | 267 |
268 | 268 |
269 def getDefaultConfiguration(self): | 269 def getDefaultConfiguration(self): |
270 d = defer.succeed(self.defaultConfig) | 270 d = defer.succeed(self.defaultConfig) |
271 d.addCallback(self._makeConfig) | |
272 return d | 271 return d |
273 | 272 |
274 | 273 |
275 def getNodeConfiguration(self, nodeIdentifier): | 274 def getNodeConfiguration(self, nodeIdentifier): |
276 if not nodeIdentifier: | 275 if not nodeIdentifier: |
277 return defer.fail(error.NoRootNode()) | 276 return defer.fail(error.NoRootNode()) |
278 | 277 |
279 d = self.storage.getNode(nodeIdentifier) | 278 d = self.storage.getNode(nodeIdentifier) |
280 d.addCallback(lambda node: node.getConfiguration()) | 279 d.addCallback(lambda node: node.getConfiguration()) |
281 | 280 return d |
282 d.addCallback(self._makeConfig) | |
283 return d | |
284 | |
285 | |
286 def _makeConfig(self, config): | |
287 options = [] | |
288 for key, value in self.options.iteritems(): | |
289 option = {"var": key} | |
290 option.update(value) | |
291 if config.has_key(key): | |
292 option["value"] = config[key] | |
293 options.append(option) | |
294 | |
295 return options | |
296 | 281 |
297 | 282 |
298 def setNodeConfiguration(self, nodeIdentifier, options, requestor): | 283 def setNodeConfiguration(self, nodeIdentifier, options, requestor): |
299 if not nodeIdentifier: | 284 if not nodeIdentifier: |
300 return defer.fail(error.NoRootNode()) | 285 return defer.fail(error.NoRootNode()) |
301 | |
302 for key, value in options.iteritems(): | |
303 if not self.options.has_key(key): | |
304 return defer.fail(error.InvalidConfigurationOption()) | |
305 if self.options[key]["type"] == 'boolean': | |
306 try: | |
307 options[key] = bool(int(value)) | |
308 except ValueError: | |
309 return defer.fail(error.InvalidConfigurationValue()) | |
310 | 286 |
311 d = self.storage.getNode(nodeIdentifier) | 287 d = self.storage.getNode(nodeIdentifier) |
312 d.addCallback(_getAffiliation, requestor) | 288 d.addCallback(_getAffiliation, requestor) |
313 d.addCallback(self._doSetNodeConfiguration, options) | 289 d.addCallback(self._doSetNodeConfiguration, options) |
314 return d | 290 return d |
607 def create(self, requestor, service, nodeIdentifier): | 583 def create(self, requestor, service, nodeIdentifier): |
608 d = self.backend.createNode(nodeIdentifier, requestor) | 584 d = self.backend.createNode(nodeIdentifier, requestor) |
609 return d.addErrback(self._mapErrors) | 585 return d.addErrback(self._mapErrors) |
610 | 586 |
611 | 587 |
588 def getConfigurationOptions(self): | |
589 return self.backend.options | |
590 | |
591 | |
612 def getDefaultConfiguration(self, requestor, service): | 592 def getDefaultConfiguration(self, requestor, service): |
613 d = self.backend.getDefaultConfiguration() | 593 d = self.backend.getDefaultConfiguration() |
614 return d.addErrback(self._mapErrors) | 594 return d.addErrback(self._mapErrors) |
615 | 595 |
616 | 596 |