Exemplo n.º 1
0
    def merge(self):
        firstDomRoot = self.firstXml.getRootNode()
        secondDomRoot = self.secondXml.getRootNode()

        for action in self.actions:
            query = action["Query"]

            if action["Policy"] == QUERY_POLICY_BOTH:
                if self._initActionBoth(action, query, firstDomRoot, secondDomRoot) is False:
                    continue
                    pass
                pass
            elif action["Policy"] == QUERY_POLICY_ONLY_NEW:
                if self._initActionFirst(action, query, firstDomRoot) is False:
                    continue
                    pass
                pass
            else:
                ErrorHandler.error("Merge Query Policy not Support %s" % str(action["Policy"]) )
                continue
                pass

            rule = MergeRuleFactory.getRule( action["RuleName"],  action["Params"] )
            if rule is None:
                ErrorHandler.warning( "Merge rule %s  don`t exist" % action["RuleName"])
                continue
                pass

            if rule.run() is False:
                ErrorHandler.warning( "Merge rule return False %s %s" % (action["RuleName"], query) )
                pass
            pass
        pass
Exemplo n.º 2
0
    def _initActionBoth(self, action, query, firstDomRoot, secondDomRoot ):
        firstResult = query.execute(firstDomRoot)
        if firstResult is None:
            ErrorHandler.warning( "xml query failed %s  on %s" % (query, self.firstXml) )
            return False
            pass

        secondResult = query.execute(secondDomRoot)
        if secondResult is None:
            ErrorHandler.warning( "xml query failed %s  on %s" % (query, self.secondXml) )
            return False
            pass

        if len(secondResult) != len(firstResult):
            ErrorHandler.warning( "xml query %s results have incompatible length  %i != %i"
            % (query,  len(secondResult),len(firstResult) ) )
            return False
            pass

        if len(secondResult) != 1:
            ErrorHandler.warning( "xml query %s only single row result supported , you got %i"
            % (query,  len(secondResult) ) )
            return False
            pass

        action["Params"]["FirstXmlInput"] = firstResult[0]
        action["Params"]["SecondXmlInput"] = secondResult[0]
        return True
        pass
Exemplo n.º 3
0
    def _initActionFirst(self, action, query, firstDomRoot ):
        firstResult = query.execute(firstDomRoot)
        if firstResult is None:
            ErrorHandler.warning( "xml query failed %s  on %s" % (query, self.firstXml) )
            return False
            pass

        if len(firstResult) != 1:
            ErrorHandler.warning( "xml query %s only single row result supported , you got %i"
            % (query,  len(firstResult) ) )
            return False
            pass

        action["Params"]["FirstXmlInput"] = firstResult[0]
        return True
        pass
    def merge(self, node1, node2):
        #TODO VERY SLOW, IMPROVE SPEED
        isParent1 = node1.hasChildren()
        isParent2 = node2.hasChildren()

        if  isParent1 != isParent2:
            ErrorHandler.warning("MergeRuleSectionIntelligence:: nodes in different tree has different structure with same tagName new %s, old %s" % (node1,node2) )
            return
            pass

        if isParent1 is True:
            self._mergeSection(node1, node2)
            pass
        else:
            self._mergeNodes(node1, node2)
            pass
        pass
 def _onParams( self, params ):
     blackList = params.pop("BlackList", None)
     self.blackList = []
     
     if blackList is None:
         return
         pass
     
     for query in blackList:
         result = query.execute(self.secondXmlInput)
         if result is None:
             ErrorHandler.warning("init black list error. graph query doesn`t work %s" % query)
             continue
             pass
         
         self.blackList.extend(result)
         pass
     pass
    def openDocument(self, pathToXml):
        document = None

        try:
            document = parse(pathToXml)
            pass
        except IOError as e:
            message = "Parser.parseToDom IOError %s in %s " % ( str(e) ,self )
            ErrorHandler.warning(message)
            return None
            pass
        except xml.parsers.expat.ExpatError as e:
            message = "Parser.parseToDom xml.parsers.expat.ExpatError %s in %s " % (str(e) , self )
            ErrorHandler.warning(message)
            return None
            pass

        return document
        pass