示例#1
0
    def restore_from_xml(self, xmlSettingFilePath=None):
        """
        Restores sync settings from the xml file
        """
        if xmlSettingFilePath == None:
            xmlSettingFilePath = self.xmlSettingFilePath
        log.info("Restoring Sync Set from %s" % xmlSettingFilePath)
           
        #Check the file exists
        if not os.path.isfile(xmlSettingFilePath):
            log.info("%s not present" % xmlSettingFilePath)
            return
            
        try:
            #Open                
            doc = xml.dom.minidom.parse(xmlSettingFilePath)
            
            #check the xml file is in a version we can read.
            if doc.documentElement.hasAttribute("settings-version"):
                if SETTINGS_VERSION != doc.documentElement.getAttribute("settings-version"):
                    log.info("%s xml file is incorrect version" % xmlSettingFilePath)
                    os.remove(xmlSettingFilePath)
                    return
            
            #Parse...    
            for conds in doc.getElementsByTagName("conduit"):
                #create a new conduit
                cond = Conduit.Conduit(self.syncManager, conds.getAttribute("uid"))
                self.add_conduit(cond)

                #restore conduit specific settings
                twoway = Settings.string_to_bool(conds.getAttribute("twoway"))
                if twoway == True:
                    cond.enable_two_way_sync()
                auto = Settings.string_to_bool(conds.getAttribute("autosync"))
                if auto == True:
                    cond.enable_auto_sync()
                for policyName in Conduit.CONFLICT_POLICY_NAMES:
                    cond.set_policy(
                                policyName,
                                conds.getAttribute("%s_policy" % policyName)
                                )

                #each dataprovider
                for i in conds.childNodes:
                    #keep a ref to the dataproider was added to so that we
                    #can apply settings to it at the end
                    #one datasource
                    if i.nodeType == i.ELEMENT_NODE and i.localName == "datasource":
                        key = i.getAttribute("key")
                        name = i.getAttribute("name")
                        #add to canvas
                        if len(key) > 0:
                            self._restore_dataprovider(cond, key, name, i, True)
                    #many datasinks
                    elif i.nodeType == i.ELEMENT_NODE and i.localName == "datasinks":
                        #each datasink
                        for sink in i.childNodes:
                            if sink.nodeType == sink.ELEMENT_NODE and sink.localName == "datasink":
                                key = sink.getAttribute("key")
                                name = sink.getAttribute("name")
                                #add to canvas
                                if len(key) > 0:
                                    self._restore_dataprovider(cond, key, name, sink, False)

        except:
            log.warn("Error parsing %s. Exception:\n%s" % (xmlSettingFilePath, traceback.format_exc()))
            os.remove(xmlSettingFilePath)
示例#2
0
                    log.warning("%s xml file is incorrect version" % xmlSettingFilePath)
                    os.remove(xmlSettingFilePath)
                    return
            else:
                log.info("%s xml file version not found, assuming too old, removing" % xmlSettingFilePath)
                os.remove(xmlSettingFilePath)
                return
            
            #Parse...    
            for conds in doc.getElementsByTagName("conduit"):
                #create a new conduit
                cond = Conduit.Conduit(self.syncManager, conds.getAttribute("uid"))
                self.add_conduit(cond)

                #restore conduit specific settings
                twoway = Settings.string_to_bool(conds.getAttribute("twoway"))
                if twoway == True:
                    cond.enable_two_way_sync()
                auto = Settings.string_to_bool(conds.getAttribute("autosync"))
                if auto == True:
                    cond.enable_auto_sync()
                for policyName in Conduit.CONFLICT_POLICY_NAMES:
                    cond.set_policy(
                                policyName,
                                conds.getAttribute("%s_policy" % policyName)
                                )

                #each dataprovider
                for i in conds.childNodes:
                    #keep a ref to the dataproider was added to so that we
                    #can apply settings to it at the end