Mercurial > libervia-backend
diff tools/memory.py @ 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 |
parents | a544b376b6f0 |
children | d24629c631fc |
line wrap: on
line diff
--- 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)