changeset 15:dcc946b30343

Consolidate productTree edition
author Benoît Allard <benoit.allard@greenbone.net>
date Thu, 09 Oct 2014 14:21:07 +0200
parents 640b88744523
children 858d8c0b49e2
files farolluz/cvrf.py farolluz/parsers/cvrf.py
diffstat 2 files changed, 25 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/farolluz/cvrf.py	Thu Oct 09 10:09:12 2014 +0200
+++ b/farolluz/cvrf.py	Thu Oct 09 14:21:07 2014 +0200
@@ -256,18 +256,9 @@
         self._products = []
         self._groups = []
 
-    def addBranch(self, branch):
-        parent = self.getBranch(branch.getParent().getPath())
-        if parent is self:
-            self._branches.append(branch)
-        else:
-            parent._childs.append(branch)
-
     def addProduct(self, product):
-        if product not in self._products:
-            self._products.append(product)
-        if product._parent is not self:
-            product._parent._product = product
+        """ Add to the product list """
+        self._products.append(product)
 
     def addRelationship(self, rel):
         self._relationships.append(rel)
@@ -403,9 +394,9 @@
     def __init__(self, _type, name, parentbranch):
         self._type = _type
         self._name = name
-        self._parentbranch = parentbranch
         self._childs = []
         self._product = None
+        self.link(parentbranch)
 
     def getParent(self):
         return self._parentbranch
@@ -462,6 +453,15 @@
             self.getParent()._childs.remove(self)
         self._parentbranch = None
 
+    def link(self, parent):
+        """ Actually, only set the parent """
+        self._parentbranch = parent
+        if self.isRoot():
+            parent._branches.append(self)
+        else:
+            parent._childs.append(self)
+
+
     def validate(self):
         if not self._type:
             raise ValidationError('A Branch must have a Type')
@@ -482,10 +482,10 @@
     def __init__(self, productid, name, parent, cpe=None):
         self._productid = productid
         self._name = name
+        self._cpe = cpe
         # Can be None (directly under the tree), a ProductBranch, or a
         # Relationship
-        self._parent = parent
-        self._cpe = cpe
+        self.link(parent)
 
     def isRoot(self):
         return isinstance(self._parent, CVRFProductTree)
@@ -509,13 +509,18 @@
         return None
 
     def unlink(self):
-        """ Unset our _parent, and remove us from the _parent._childs """
-        if self.isRoot():
-            self._parent._products.remove(self)
-        else:
+        """ Unset our _parent, and remove us from the _parent._childs
+        We are still in the product list.
+        """
+        if not self.isRoot():
             self._parent._product = None
         self._parent = None
 
+    def link(self, parent):
+        self._parent = parent
+        if not self.isRoot():
+            parent._product = self
+
     def validate(self):
         if not self._productid:
             raise ValidationError('A Product must have a ProductID')
--- a/farolluz/parsers/cvrf.py	Thu Oct 09 10:09:12 2014 +0200
+++ b/farolluz/parsers/cvrf.py	Thu Oct 09 14:21:07 2014 +0200
@@ -324,8 +324,8 @@
     cvrfptree = cvrfdoc.find(UN('prod', 'ProductTree'))
     if cvrfptree is not None:
         producttree = doc.createProductTree()
-        for branch in parseProdBranch(cvrfptree, producttree):
-            producttree.addBranch(branch)
+        # We need to exhaust our generator ...
+        for _ in parseProdBranch(cvrfptree, producttree): pass
 
         for product in cvrfptree.findall(UN('prod', 'FullProductName')):
             producttree.addProduct(parseFullProductName(product, producttree))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)