changeset 662:4f747d7fde8c

core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
author Goffi <goffi@goffi.org>
date Thu, 31 Oct 2013 17:14:15 +0100
parents d81f55a58c08
children 8004c7d4aba7
files src/memory/memory.py src/plugins/deprecated_misc_cs.py src/plugins/plugin_misc_imap.py src/plugins/plugin_misc_smtp.py src/plugins/plugin_misc_xmllog.py src/plugins/plugin_xep_0065.py src/plugins/plugin_xep_0085.py
diffstat 7 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/memory/memory.py	Tue Oct 15 23:10:31 2013 +0200
+++ b/src/memory/memory.py	Thu Oct 31 17:14:15 2013 +0100
@@ -217,7 +217,7 @@
         #the node is new
         return None
 
-    def importParams(self, xml):
+    def updateParams(self, xml):
         """import xml in parameters, do nothing if the param already exist
         @param xml: parameters in xml form"""
         src_dom = minidom.parseString(xml.encode('utf-8'))
@@ -230,7 +230,12 @@
                 if not node:  # The node is new
                     tgt_parent.appendChild(child)
                 else:
-                    import_node(node, child)
+                    if child.nodeName == "param":
+                        # The child update an existing parameter, we replace the node
+                        tgt_parent.replaceChild(child, node)
+                    else:
+                        # the node already exists, we recurse 1 more level
+                        import_node(node, child)
 
         import_node(self.dom.documentElement, src_dom.documentElement)
 
@@ -932,8 +937,8 @@
     def setParam(self, name, value, category, security_limit=NO_SECURITY_LIMIT, profile_key='@NONE@'):
         return self.params.setParam(name, value, category, security_limit, profile_key)
 
-    def importParams(self, xml):
-        return self.params.importParams(xml)
+    def updateParams(self, xml):
+        return self.params.updateParams(xml)
 
     def setDefault(self, name, category, callback, errback=None):
         return self.params.setDefault(name, category, callback, errback)
--- a/src/plugins/deprecated_misc_cs.py	Tue Oct 15 23:10:31 2013 +0200
+++ b/src/plugins/deprecated_misc_cs.py	Thu Oct 31 17:14:15 2013 +0100
@@ -69,7 +69,7 @@
         info(_("Plugin CS initialization"))
         self.host = host
         #parameters
-        host.memory.importParams(CS_Plugin.params)
+        host.memory.updateParams(CS_Plugin.params)
         #menu
         host.importMenu(_("Plugin"), "CouchSurfing", self.menuSelected, help_string=_("Launch CoushSurfing management interface"))
         self.data = {}  # TODO: delete cookies/data after a while
--- a/src/plugins/plugin_misc_imap.py	Tue Oct 15 23:10:31 2013 +0200
+++ b/src/plugins/plugin_misc_imap.py	Thu Oct 31 17:14:15 2013 +0100
@@ -64,7 +64,7 @@
         self.host = host
 
         #parameters
-        host.memory.importParams(self.params)
+        host.memory.updateParams(self.params)
 
         port = int(self.host.memory.getParamA("IMAP Port", "Mail Server"))
         info(_("Launching IMAP server on port %d"), port)
--- a/src/plugins/plugin_misc_smtp.py	Tue Oct 15 23:10:31 2013 +0200
+++ b/src/plugins/plugin_misc_smtp.py	Thu Oct 31 17:14:15 2013 +0100
@@ -63,7 +63,7 @@
         self.host = host
 
         #parameters
-        host.memory.importParams(self.params)
+        host.memory.updateParams(self.params)
 
         port = int(self.host.memory.getParamA("SMTP Port", "Mail Server"))
         info(_("Launching SMTP server on port %d"), port)
--- a/src/plugins/plugin_misc_xmllog.py	Tue Oct 15 23:10:31 2013 +0200
+++ b/src/plugins/plugin_misc_xmllog.py	Thu Oct 31 17:14:15 2013 +0100
@@ -68,7 +68,7 @@
         self.host = host
 
         #parameters
-        host.memory.importParams(self.params)
+        host.memory.updateParams(self.params)
 
         #bridge
         host.bridge.addSignal("xmlLog", ".plugin", signature='sss')  # args: direction("IN" or "OUT"), xml_data, profile
--- a/src/plugins/plugin_xep_0065.py	Tue Oct 15 23:10:31 2013 +0200
+++ b/src/plugins/plugin_xep_0065.py	Thu Oct 31 17:14:15 2013 +0100
@@ -468,7 +468,7 @@
         self.server_factory = Socks5ServerFactory(host, self.hash_sid_map, lambda sid, success, profile: self._killId(sid, success, profile=profile))
 
         #parameters
-        host.memory.importParams(XEP_0065.params)
+        host.memory.updateParams(XEP_0065.params)
         host.memory.setDefault("IP", "File Transfer", self.getExternalIP)
         port = int(self.host.memory.getParamA("Port", "File Transfer"))
 
--- a/src/plugins/plugin_xep_0085.py	Tue Oct 15 23:10:31 2013 +0200
+++ b/src/plugins/plugin_xep_0085.py	Thu Oct 31 17:14:15 2013 +0100
@@ -93,7 +93,7 @@
         self.host = host
 
         # parameter value is retrieved before each use
-        host.memory.importParams(self.params)
+        host.memory.updateParams(self.params)
 
         # triggers from core
         host.trigger.add("MessageReceived", self.messageReceivedTrigger)