From 989f660a5352a30e7ff06fa9e3ca293fb9bb14e9 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 17 Dec 2009 13:13:13 +1100 Subject: [PATCH] Fixed parameters loading/saving - removed unused "parent" argument in importParams - changed "ext" for "tld" in wix jid example --- frontends/wix/main_window.py | 2 +- plugins/plugin_xep_0065.py | 2 +- tools/memory.py | 29 ++++++++++++++++++----------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/frontends/wix/main_window.py b/frontends/wix/main_window.py index 33568732..edd53637 100644 --- a/frontends/wix/main_window.py +++ b/frontends/wix/main_window.py @@ -404,7 +404,7 @@ class MainWindow(wx.Frame, QuickApp): 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()) diff --git a/plugins/plugin_xep_0065.py b/plugins/plugin_xep_0065.py index 142be98f..a3601bfb 100755 --- a/plugins/plugin_xep_0065.py +++ b/plugins/plugin_xep_0065.py @@ -470,7 +470,7 @@ class XEP_0065(XMPPHandler): 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")) diff --git a/tools/memory.py b/tools/memory.py index ed18c7e3..eb2f71bb 100644 --- a/tools/memory.py +++ b/tools/memory.py @@ -53,11 +53,19 @@ class Param(): 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 @@ class Param(): #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 @@ class Memory: 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 @@ class Memory: 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 @@ class Memory: 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)