Mercurial > libervia-backend
changeset 38:3e24753b9e0b
Fixed parameters loading/saving
- removed unused "parent" argument in importParams
- changed "ext" for "tld" in wix jid example
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 17 Dec 2009 13:13:13 +1100 (2009-12-17) |
parents | a61beb21d16d |
children | 2e3411a6baad |
files | frontends/wix/main_window.py plugins/plugin_xep_0065.py tools/memory.py |
diffstat | 3 files changed, 20 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/wix/main_window.py Tue Dec 15 01:27:32 2009 +1100 +++ b/frontends/wix/main_window.py Thu Dec 17 13:13:13 2009 +1100 @@ -404,7 +404,7 @@ debug("Add contact request") dlg = wx.TextEntryDialog( self, 'Please enter new contact JID', - 'Adding a contact', 'name@server.ext') + 'Adding a contact', 'name@server.tld') if dlg.ShowModal() == wx.ID_OK: jid=JID(dlg.GetValue())
--- a/plugins/plugin_xep_0065.py Tue Dec 15 01:27:32 2009 +1100 +++ b/plugins/plugin_xep_0065.py Thu Dec 17 13:13:13 2009 +1100 @@ -470,7 +470,7 @@ self.client_factory = Socks5ClientFactory() #parameters - host.memory.importParams(self, XEP_0065.params) + host.memory.importParams(XEP_0065.params) host.memory.setDefault("IP", "File Transfert", self.getExternalIP) port = int(self.host.memory.getParamA("Port", "File Transfert"))
--- a/tools/memory.py Tue Dec 15 01:27:32 2009 +1100 +++ b/tools/memory.py Thu Dec 17 13:13:13 2009 +1100 @@ -53,11 +53,19 @@ def load_default_params(self): 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): debug("Parameters init") self.host = host - self.load_default_params() host.registerGeneralCB("registerNewAccount", host.registerNewAccountCB) def __get_unique_node(self, parent, tag, name): @@ -74,9 +82,8 @@ #the node is new return None - def importParams(self, parent, xml): + def importParams(self, 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.encode('utf-8')) @@ -184,12 +191,10 @@ def load(self): """Load parameters and all memory things from file/db""" - #first parameters + #parameters if os.path.exists(const_SAVEFILE_PARAM): try: - #gof: FIXME FIXME FIXME: sauver l'xml et non plus le pickle !!!!!!! - with open(const_SAVEFILE_PARAM, 'r') as params_pickle: - self.params=pickle.load(params_pickle) + self.params.load(const_SAVEFILE_PARAM) debug("params loaded") except: error ("Can't load params !") @@ -210,10 +215,12 @@ def save(self): """Save parameters and all memory things to file/db""" - with open(const_SAVEFILE_PARAM, 'w') as params_pickle: - pickle.dump(self.params, params_pickle) + #TODO: need to encrypt files (at least passwords !) and set permissions + self.params.save(const_SAVEFILE_PARAM) + debug("params saved") with open(const_SAVEFILE_HISTORY, 'w') as history_pickle: pickle.dump(self.history, history_pickle) + debug("history saved") def addToHistory(self, me_jid, from_jid, to_jid, type, message): me_short=me_jid.userhost() @@ -287,8 +294,8 @@ def setParam(self, name, value, category): return self.params.setParam(name, value, category) - def importParams(self, parent, xml): - return self.params.importParams(parent, xml) + def importParams(self, xml): + return self.params.importParams(xml) def setDefault(self, name, category, callback, errback=None): return self.params.setDefault(name, category, callback, errback)