Fixed parameters loading/saving
- removed unused "parent" argument in importParams - changed "ext" for "tld" in wix jid example
This commit is contained in:
parent
e3a3c1e975
commit
989f660a53
3 changed files with 20 additions and 13 deletions
|
|
@ -404,7 +404,7 @@ class MainWindow(wx.Frame, QuickApp):
|
||||||
debug("Add contact request")
|
debug("Add contact request")
|
||||||
dlg = wx.TextEntryDialog(
|
dlg = wx.TextEntryDialog(
|
||||||
self, 'Please enter new contact JID',
|
self, 'Please enter new contact JID',
|
||||||
'Adding a contact', 'name@server.ext')
|
'Adding a contact', 'name@server.tld')
|
||||||
|
|
||||||
if dlg.ShowModal() == wx.ID_OK:
|
if dlg.ShowModal() == wx.ID_OK:
|
||||||
jid=JID(dlg.GetValue())
|
jid=JID(dlg.GetValue())
|
||||||
|
|
|
||||||
|
|
@ -470,7 +470,7 @@ class XEP_0065(XMPPHandler):
|
||||||
self.client_factory = Socks5ClientFactory()
|
self.client_factory = Socks5ClientFactory()
|
||||||
|
|
||||||
#parameters
|
#parameters
|
||||||
host.memory.importParams(self, XEP_0065.params)
|
host.memory.importParams(XEP_0065.params)
|
||||||
host.memory.setDefault("IP", "File Transfert", self.getExternalIP)
|
host.memory.setDefault("IP", "File Transfert", self.getExternalIP)
|
||||||
|
|
||||||
port = int(self.host.memory.getParamA("Port", "File Transfert"))
|
port = int(self.host.memory.getParamA("Port", "File Transfert"))
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,18 @@ class Param():
|
||||||
def load_default_params(self):
|
def load_default_params(self):
|
||||||
self.dom = minidom.parseString(Param.default_xml.encode('utf-8'))
|
self.dom = minidom.parseString(Param.default_xml.encode('utf-8'))
|
||||||
|
|
||||||
|
def load(self, file):
|
||||||
|
"""Load parameters from file"""
|
||||||
|
self.dom = minidom.parse(file)
|
||||||
|
|
||||||
|
def save(self, file):
|
||||||
|
"""Save parameters to xml file"""
|
||||||
|
with open(file, 'wb') as xml_file:
|
||||||
|
self.dom.writexml(xml_file)
|
||||||
|
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
debug("Parameters init")
|
debug("Parameters init")
|
||||||
self.host = host
|
self.host = host
|
||||||
self.load_default_params()
|
|
||||||
host.registerGeneralCB("registerNewAccount", host.registerNewAccountCB)
|
host.registerGeneralCB("registerNewAccount", host.registerNewAccountCB)
|
||||||
|
|
||||||
def __get_unique_node(self, parent, tag, name):
|
def __get_unique_node(self, parent, tag, name):
|
||||||
|
|
@ -74,9 +82,8 @@ class Param():
|
||||||
#the node is new
|
#the node is new
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def importParams(self, parent, xml):
|
def importParams(self, xml):
|
||||||
"""import xml in parameters, do nothing if the param already exist
|
"""import xml in parameters, do nothing if the param already exist
|
||||||
@param parent: parent class (usefull for callbacks)
|
|
||||||
@param xml: parameters in xml form"""
|
@param xml: parameters in xml form"""
|
||||||
src_dom = minidom.parseString(xml.encode('utf-8'))
|
src_dom = minidom.parseString(xml.encode('utf-8'))
|
||||||
|
|
||||||
|
|
@ -184,12 +191,10 @@ class Memory:
|
||||||
def load(self):
|
def load(self):
|
||||||
"""Load parameters and all memory things from file/db"""
|
"""Load parameters and all memory things from file/db"""
|
||||||
|
|
||||||
#first parameters
|
#parameters
|
||||||
if os.path.exists(const_SAVEFILE_PARAM):
|
if os.path.exists(const_SAVEFILE_PARAM):
|
||||||
try:
|
try:
|
||||||
#gof: FIXME FIXME FIXME: sauver l'xml et non plus le pickle !!!!!!!
|
self.params.load(const_SAVEFILE_PARAM)
|
||||||
with open(const_SAVEFILE_PARAM, 'r') as params_pickle:
|
|
||||||
self.params=pickle.load(params_pickle)
|
|
||||||
debug("params loaded")
|
debug("params loaded")
|
||||||
except:
|
except:
|
||||||
error ("Can't load params !")
|
error ("Can't load params !")
|
||||||
|
|
@ -210,10 +215,12 @@ class Memory:
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""Save parameters and all memory things to file/db"""
|
"""Save parameters and all memory things to file/db"""
|
||||||
with open(const_SAVEFILE_PARAM, 'w') as params_pickle:
|
#TODO: need to encrypt files (at least passwords !) and set permissions
|
||||||
pickle.dump(self.params, params_pickle)
|
self.params.save(const_SAVEFILE_PARAM)
|
||||||
|
debug("params saved")
|
||||||
with open(const_SAVEFILE_HISTORY, 'w') as history_pickle:
|
with open(const_SAVEFILE_HISTORY, 'w') as history_pickle:
|
||||||
pickle.dump(self.history, history_pickle)
|
pickle.dump(self.history, history_pickle)
|
||||||
|
debug("history saved")
|
||||||
|
|
||||||
def addToHistory(self, me_jid, from_jid, to_jid, type, message):
|
def addToHistory(self, me_jid, from_jid, to_jid, type, message):
|
||||||
me_short=me_jid.userhost()
|
me_short=me_jid.userhost()
|
||||||
|
|
@ -287,8 +294,8 @@ class Memory:
|
||||||
def setParam(self, name, value, category):
|
def setParam(self, name, value, category):
|
||||||
return self.params.setParam(name, value, category)
|
return self.params.setParam(name, value, category)
|
||||||
|
|
||||||
def importParams(self, parent, xml):
|
def importParams(self, xml):
|
||||||
return self.params.importParams(parent, xml)
|
return self.params.importParams(xml)
|
||||||
|
|
||||||
def setDefault(self, name, category, callback, errback=None):
|
def setDefault(self, name, category, callback, errback=None):
|
||||||
return self.params.setDefault(name, category, callback, errback)
|
return self.params.setDefault(name, category, callback, errback)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue