# HG changeset patch # User BenoƮt Allard # Date 1412857267 -7200 # Node ID dcc946b3034362908e1d08a169a863737a8b94ed # Parent 640b8874452311aa20c35c7c5b8aa9591d100ede Consolidate productTree edition diff -r 640b88744523 -r dcc946b30343 farolluz/cvrf.py --- 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') diff -r 640b88744523 -r dcc946b30343 farolluz/parsers/cvrf.py --- 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))