refactoring: using xml params part IV (default values)
- File Transfert/IP is now set by default to the ip externally visible
This commit is contained in:
parent
ea056ce96e
commit
b772500c91
1 changed files with 40 additions and 8 deletions
|
|
@ -27,6 +27,7 @@ import pickle
|
|||
from xml.dom import minidom
|
||||
from logging import debug, info, error
|
||||
import pdb
|
||||
from twisted.internet import defer
|
||||
|
||||
const_SAVEFILE_PARAM=os.path.expanduser("~/.sat_param.save")
|
||||
const_SAVEFILE_HISTORY=os.path.expanduser("~/.sat_history.save")
|
||||
|
|
@ -70,11 +71,10 @@ class Param():
|
|||
#the node is new
|
||||
return None
|
||||
|
||||
def import_params(self, parent, xml):
|
||||
def importParams(self, parent, xml):
|
||||
"""import xml in parameters, do nothing if the param already exist
|
||||
@param parent: parent class (usefull for callbacks)
|
||||
@param xml: parameters in xml form"""
|
||||
|
||||
src_dom = minidom.parseString(xml)
|
||||
|
||||
def import_node(tgt_parent, src_parent):
|
||||
|
|
@ -90,6 +90,29 @@ class Param():
|
|||
|
||||
import_node(self.dom.documentElement, src_dom.documentElement)
|
||||
|
||||
def __default_ok(self, value, name, category):
|
||||
self.setParam(name, value, category)
|
||||
|
||||
def __default_ko(self, failure, name, category):
|
||||
error ("Can't determine default value for [%s/%s]: %s" % (category, name, str(failure.value)))
|
||||
|
||||
def setDefault(self, name, category, callback, errback=None):
|
||||
"""Set default value of parameter
|
||||
'default_cb' attibute of parameter must be set to 'yes'
|
||||
@param name: name of the parameter
|
||||
@param category: category of the parameter
|
||||
@param callback: must return a string with the value (use deferred if needed)
|
||||
@param errback: must manage the error with args failure, name, category
|
||||
"""
|
||||
node = self.__getParamNode(name, category)
|
||||
if not node:
|
||||
error("Requested param [%s] in category [%s] doesn't exist !" , name, category)
|
||||
return
|
||||
if node.getAttribute('default_cb') == 'yes':
|
||||
del node.attributes['default_cb']
|
||||
d = defer.maybeDeferred(callback)
|
||||
d.addCallback(self.__default_ok, name, category)
|
||||
d.addErrback(errback or self.__default_ko, name, category)
|
||||
|
||||
def getParamV(self, name, category):
|
||||
"""Helper method to get the value in the good type
|
||||
|
|
@ -251,5 +274,8 @@ class Memory:
|
|||
def setParam(self, name, value, category):
|
||||
return self.params.setParam(name, value, category)
|
||||
|
||||
def import_params(self, parent, xml):
|
||||
return self.params.import_params(parent, xml)
|
||||
def importParams(self, parent, xml):
|
||||
return self.params.importParams(parent, xml)
|
||||
|
||||
def setDefault(self, name, category, callback, errback=None):
|
||||
return self.params.setDefault(name, category, callback, errback)
|
||||
|
|
|
|||
Loading…
Reference in a new issue