Mercurial > libervia-backend
comparison tools/memory.py @ 20:fc8c202cda87
refactoring: using xml params part IV (default values)
- File Transfert/IP is now set by default to the ip externally visible
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 08 Nov 2009 00:11:00 +0100 |
parents | f2a745ca0fbc |
children | 633c5ed65701 |
comparison
equal
deleted
inserted
replaced
19:f2a745ca0fbc | 20:fc8c202cda87 |
---|---|
25 import time | 25 import time |
26 import pickle | 26 import pickle |
27 from xml.dom import minidom | 27 from xml.dom import minidom |
28 from logging import debug, info, error | 28 from logging import debug, info, error |
29 import pdb | 29 import pdb |
30 from twisted.internet import defer | |
30 | 31 |
31 const_SAVEFILE_PARAM=os.path.expanduser("~/.sat_param.save") | 32 const_SAVEFILE_PARAM=os.path.expanduser("~/.sat_param.save") |
32 const_SAVEFILE_HISTORY=os.path.expanduser("~/.sat_history.save") | 33 const_SAVEFILE_HISTORY=os.path.expanduser("~/.sat_history.save") |
33 | 34 |
34 class Param(): | 35 class Param(): |
68 #the node already exists | 69 #the node already exists |
69 return node | 70 return node |
70 #the node is new | 71 #the node is new |
71 return None | 72 return None |
72 | 73 |
73 def import_params(self, parent, xml): | 74 def importParams(self, parent, xml): |
74 """import xml in parameters, do nothing if the param already exist | 75 """import xml in parameters, do nothing if the param already exist |
75 @param parent: parent class (usefull for callbacks) | 76 @param parent: parent class (usefull for callbacks) |
76 @param xml: parameters in xml form""" | 77 @param xml: parameters in xml form""" |
77 | |
78 src_dom = minidom.parseString(xml) | 78 src_dom = minidom.parseString(xml) |
79 | 79 |
80 def import_node(tgt_parent, src_parent): | 80 def import_node(tgt_parent, src_parent): |
81 print "import_node [%s, %s]" % (tgt_parent.nodeName, src_parent.nodeName) | 81 print "import_node [%s, %s]" % (tgt_parent.nodeName, src_parent.nodeName) |
82 for child in src_parent.childNodes: | 82 for child in src_parent.childNodes: |
88 else: | 88 else: |
89 import_node(node, child) | 89 import_node(node, child) |
90 | 90 |
91 import_node(self.dom.documentElement, src_dom.documentElement) | 91 import_node(self.dom.documentElement, src_dom.documentElement) |
92 | 92 |
93 def __default_ok(self, value, name, category): | |
94 self.setParam(name, value, category) | |
95 | |
96 def __default_ko(self, failure, name, category): | |
97 error ("Can't determine default value for [%s/%s]: %s" % (category, name, str(failure.value))) | |
98 | |
99 def setDefault(self, name, category, callback, errback=None): | |
100 """Set default value of parameter | |
101 'default_cb' attibute of parameter must be set to 'yes' | |
102 @param name: name of the parameter | |
103 @param category: category of the parameter | |
104 @param callback: must return a string with the value (use deferred if needed) | |
105 @param errback: must manage the error with args failure, name, category | |
106 """ | |
107 node = self.__getParamNode(name, category) | |
108 if not node: | |
109 error("Requested param [%s] in category [%s] doesn't exist !" , name, category) | |
110 return | |
111 if node.getAttribute('default_cb') == 'yes': | |
112 del node.attributes['default_cb'] | |
113 d = defer.maybeDeferred(callback) | |
114 d.addCallback(self.__default_ok, name, category) | |
115 d.addErrback(errback or self.__default_ko, name, category) | |
93 | 116 |
94 def getParamV(self, name, category): | 117 def getParamV(self, name, category): |
95 """Helper method to get the value in the good type | 118 """Helper method to get the value in the good type |
96 getParamV stands for GetParamValue""" | 119 getParamV stands for GetParamValue""" |
97 node = self.__getParamNode(name, category) | 120 node = self.__getParamNode(name, category) |
249 return self.params.getParamsCategories() | 272 return self.params.getParamsCategories() |
250 | 273 |
251 def setParam(self, name, value, category): | 274 def setParam(self, name, value, category): |
252 return self.params.setParam(name, value, category) | 275 return self.params.setParam(name, value, category) |
253 | 276 |
254 def import_params(self, parent, xml): | 277 def importParams(self, parent, xml): |
255 return self.params.import_params(parent, xml) | 278 return self.params.importParams(parent, xml) |
279 | |
280 def setDefault(self, name, category, callback, errback=None): | |
281 return self.params.setDefault(name, category, callback, errback) |