[PATCH 47 of 54] Add the possibility to batch-import trees

Wald Commits scm-commit at wald.intevation.org
Wed Jan 7 10:57:04 CET 2015


# HG changeset patch
# User Benoît Allard <benoit.allard at greenbone.net>
# Date 1419938886 -3600
# Node ID 1b7f3f4f1238cafd8c45a0745fe92f458531c32f
# Parent  0755199759334e053a3b94f44b3965d6dcb1c8fe
Add the possibility to batch-import trees

diff -r 075519975933 -r 1b7f3f4f1238 farolluz/producttree.py
--- a/farolluz/producttree.py	Tue Dec 30 12:18:09 2014 +0100
+++ b/farolluz/producttree.py	Tue Dec 30 12:28:06 2014 +0100
@@ -142,6 +142,19 @@
         """ Amount of 'raw' Products """
         return len([p for p in self._products if p._parent is self])
 
+    def importTree(self, tree):
+        """ tree is a list of tuple (type, value) like the one generated by
+        getTree() """
+        if len(tree) == 0:
+            return self
+        found = None
+        for branch in self._branches:
+            if branch.getTree() == tree[:1]:
+                found = branch
+        if found is None:
+            found = CVRFProductBranch(tree[0][0], tree[0][1], self)
+        return found.importTree(tree, 1)
+
     def validate(self):
         for branch in self._branches:
             branch.validate()
@@ -246,6 +259,18 @@
         else:
             parent._childs.append(self)
 
+    def importTree(self, tree, index):
+        """ tree is a list of tuple (type, value) like the one generated by
+        getTree() """
+        if len(tree) == index:
+            return self
+        found = None
+        for branch in self._childs:
+            if branch.getTree() == tree[:index + 1]:
+                found = branch
+        if found is None:
+            found = CVRFProductBranch(tree[index][0], tree[index][1], self)
+        return found.importTree(tree, index + 1)
 
     def validate(self):
         if not self._type:


More information about the Farol-commits mailing list