[conduit] fix xml serialization from outside SyncSet



commit 3cba683db76e613e42c568b0331001a35ddc0443
Author: John Stowers <john stowers gmail com>
Date:   Thu Jan 7 18:42:58 2010 +0100

    fix xml serialization from outside SyncSet

 conduit/ModuleWrapper.py              |    7 +++----
 conduit/SyncSet.py                    |   18 +++++++++---------
 conduit/XMLSerialization.py           |    8 ++++++--
 conduit/dataproviders/DataProvider.py |    4 ++--
 4 files changed, 20 insertions(+), 17 deletions(-)
---
diff --git a/conduit/ModuleWrapper.py b/conduit/ModuleWrapper.py
index a705bc4..4f887a2 100644
--- a/conduit/ModuleWrapper.py
+++ b/conduit/ModuleWrapper.py
@@ -245,8 +245,8 @@ class ModuleWrapper:
     
         return self.descriptiveIcon
         
-    def set_configuration_xml(self, xmltext, xmlversion):
-        self.module.set_configuration_xml(xmltext, xmlversion)
+    def set_configuration_xml(self, xmltext):
+        self.module.set_configuration_xml(xmltext)
 
     def get_configuration_xml(self):
         return self.module.get_configuration_xml()
@@ -279,9 +279,8 @@ class PendingDataproviderWrapper(ModuleWrapper):
     def get_key(self):
         return self.key
 
-    def set_configuration_xml(self, xmltext, xmlversion):
+    def set_configuration_xml(self, xmltext):
         self.xmltext = xmltext
-        self.xmlversion = xmlversion
 
     def get_configuration_xml(self):
         return self.xmltext
diff --git a/conduit/SyncSet.py b/conduit/SyncSet.py
index 84fef59..b375dcb 100644
--- a/conduit/SyncSet.py
+++ b/conduit/SyncSet.py
@@ -14,10 +14,9 @@ log = logging.getLogger("SyncSet")
 import conduit
 import conduit.Conduit as Conduit
 import conduit.Settings as Settings
+import conduit.XMLSerialization as XMLSerialization
 
-#Increment this number when the xml settings file
-#changes format
-SETTINGS_VERSION = "2"
+SETTINGS_VERSION = XMLSerialization.Settings.XML_VERSION
 
 class SyncSet(gobject.GObject):
     """
@@ -55,7 +54,7 @@ class SyncSet(gobject.GObject):
                 except Exception:
                     log.warn("Could not uninitialize %s" % dp, exc_info=True)
                 
-    def _restore_dataprovider(self, cond, wrapperKey, dpName="", dpxml="", xml_version=SETTINGS_VERSION, trySourceFirst=True):
+    def _restore_dataprovider(self, cond, wrapperKey, dpName="", dpxml="", trySourceFirst=True):
         """
         Adds the dataprovider back onto the canvas at the specifed
         location and configures it with the given settings
@@ -68,7 +67,7 @@ class SyncSet(gobject.GObject):
             if dpxml:
                 for i in dpxml.childNodes:
                     if i.nodeType == i.ELEMENT_NODE and i.localName == "configuration":
-                        wrapper.set_configuration_xml(xmltext=i.toxml(), xmlversion=xml_version)
+                        wrapper.set_configuration_xml(xmltext=i.toxml())
         cond.add_dataprovider(wrapper, trySourceFirst)
 
     def on_dataprovider_available_unavailable(self, loader, dpw):
@@ -220,8 +219,9 @@ class SyncSet(gobject.GObject):
                     os.remove(xmlSettingFilePath)
                     return
             else:
-                log.info("%s xml file version not found, assuming version 1" % xmlSettingFilePath)
-                xml_version = 1
+                log.info("%s xml file version not found, assuming too old, removing" % xmlSettingFilePath)
+                os.remove(xmlSettingFilePath)
+                return
             
             #Parse...    
             for conds in doc.getElementsByTagName("conduit"):
@@ -252,7 +252,7 @@ class SyncSet(gobject.GObject):
                         name = i.getAttribute("name")
                         #add to canvas
                         if len(key) > 0:
-                            self._restore_dataprovider(cond, key, name, i, xml_version, True)
+                            self._restore_dataprovider(cond, key, name, i, True)
                     #many datasinks
                     elif i.nodeType == i.ELEMENT_NODE and i.localName == "datasinks":
                         #each datasink
@@ -262,7 +262,7 @@ class SyncSet(gobject.GObject):
                                 name = sink.getAttribute("name")
                                 #add to canvas
                                 if len(key) > 0:
-                                    self._restore_dataprovider(cond, key, name, sink, xml_version, False)
+                                    self._restore_dataprovider(cond, key, name, sink, False)
 
         except:
             log.warn("Error parsing %s. Exception:\n%s" % (xmlSettingFilePath, traceback.format_exc()))
diff --git a/conduit/XMLSerialization.py b/conduit/XMLSerialization.py
index ad07b3e..cd68b89 100644
--- a/conduit/XMLSerialization.py
+++ b/conduit/XMLSerialization.py
@@ -27,12 +27,16 @@ class Settings( object ):
     A class to store/retrieve data to/from an XML file
     """
 
-    def __init__(self, xml_text="<configuration/>", xml_version = 2):
+    #Increment this number when the xml settings file
+    #changes format
+    XML_VERSION = "2"
+
+    def __init__(self, xml_text="<configuration/>"):
         """
         Initializes Settings class
         """
         self.xml_document = parseString(xml_text)
-        self.xml_version = xml_version
+        self.xml_version = self.XML_VERSION
 
     def __string_to_type__(self, string, desired_type):
         """
diff --git a/conduit/dataproviders/DataProvider.py b/conduit/dataproviders/DataProvider.py
index 838d42d..839b6e4 100644
--- a/conduit/dataproviders/DataProvider.py
+++ b/conduit/dataproviders/DataProvider.py
@@ -367,14 +367,14 @@ class DataProviderBase(gobject.GObject):
                         callable(getattr(self, c, None)))
                         )
 
-    def set_configuration_xml(self, xmltext, xmlversion):
+    def set_configuration_xml(self, xmltext):
         """
         Restores applications settings from XML
 
         @param xmltext: xml representation of settings
         @type xmltext: C{string}
         """
-        xml_configuration = XMLSerialization.Settings(xmltext, xmlversion)
+        xml_configuration = XMLSerialization.Settings(xmltext)
         settings = {}
         for name, value in xml_configuration:
             settings[name] = value



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]