Mercurial > farol > farolluz
changeset 46:1b7f3f4f1238
Add the possibility to batch-import trees
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Tue, 30 Dec 2014 12:28:06 +0100 |
parents | 075519975933 |
children | 652f59fbea3a |
files | farolluz/producttree.py |
diffstat | 1 files changed, 25 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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: