Mercurial > farol > farolluz
comparison farolluz/cvrf.py @ 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 | 90852c11fabd |
comparison
equal
deleted
inserted
replaced
14:640b88744523 | 15:dcc946b30343 |
---|---|
254 self._groups = [] | 254 self._groups = [] |
255 self._relationships = [] | 255 self._relationships = [] |
256 self._products = [] | 256 self._products = [] |
257 self._groups = [] | 257 self._groups = [] |
258 | 258 |
259 def addBranch(self, branch): | |
260 parent = self.getBranch(branch.getParent().getPath()) | |
261 if parent is self: | |
262 self._branches.append(branch) | |
263 else: | |
264 parent._childs.append(branch) | |
265 | |
266 def addProduct(self, product): | 259 def addProduct(self, product): |
267 if product not in self._products: | 260 """ Add to the product list """ |
268 self._products.append(product) | 261 self._products.append(product) |
269 if product._parent is not self: | |
270 product._parent._product = product | |
271 | 262 |
272 def addRelationship(self, rel): | 263 def addRelationship(self, rel): |
273 self._relationships.append(rel) | 264 self._relationships.append(rel) |
274 | 265 |
275 def addGroup(self, group): | 266 def addGroup(self, group): |
401 'Patch Level', 'Service Pack', 'Architecture', 'Language', | 392 'Patch Level', 'Service Pack', 'Architecture', 'Language', |
402 'Legacy', 'Specification') | 393 'Legacy', 'Specification') |
403 def __init__(self, _type, name, parentbranch): | 394 def __init__(self, _type, name, parentbranch): |
404 self._type = _type | 395 self._type = _type |
405 self._name = name | 396 self._name = name |
406 self._parentbranch = parentbranch | |
407 self._childs = [] | 397 self._childs = [] |
408 self._product = None | 398 self._product = None |
399 self.link(parentbranch) | |
409 | 400 |
410 def getParent(self): | 401 def getParent(self): |
411 return self._parentbranch | 402 return self._parentbranch |
412 | 403 |
413 def getPath(self, string=False): | 404 def getPath(self, string=False): |
460 self.getParent()._branches.remove(self) | 451 self.getParent()._branches.remove(self) |
461 else: | 452 else: |
462 self.getParent()._childs.remove(self) | 453 self.getParent()._childs.remove(self) |
463 self._parentbranch = None | 454 self._parentbranch = None |
464 | 455 |
456 def link(self, parent): | |
457 """ Actually, only set the parent """ | |
458 self._parentbranch = parent | |
459 if self.isRoot(): | |
460 parent._branches.append(self) | |
461 else: | |
462 parent._childs.append(self) | |
463 | |
464 | |
465 def validate(self): | 465 def validate(self): |
466 if not self._type: | 466 if not self._type: |
467 raise ValidationError('A Branch must have a Type') | 467 raise ValidationError('A Branch must have a Type') |
468 if self._type not in self.TYPES: | 468 if self._type not in self.TYPES: |
469 raise ValidationError('A Branch Type must be one of %s' % ', '.join(self.TYPES)) | 469 raise ValidationError('A Branch Type must be one of %s' % ', '.join(self.TYPES)) |
480 | 480 |
481 class CVRFFullProductName(object): | 481 class CVRFFullProductName(object): |
482 def __init__(self, productid, name, parent, cpe=None): | 482 def __init__(self, productid, name, parent, cpe=None): |
483 self._productid = productid | 483 self._productid = productid |
484 self._name = name | 484 self._name = name |
485 self._cpe = cpe | |
485 # Can be None (directly under the tree), a ProductBranch, or a | 486 # Can be None (directly under the tree), a ProductBranch, or a |
486 # Relationship | 487 # Relationship |
487 self._parent = parent | 488 self.link(parent) |
488 self._cpe = cpe | |
489 | 489 |
490 def isRoot(self): | 490 def isRoot(self): |
491 return isinstance(self._parent, CVRFProductTree) | 491 return isinstance(self._parent, CVRFProductTree) |
492 | 492 |
493 def isRelationship(self): | 493 def isRelationship(self): |
507 if self.isRelationship(): | 507 if self.isRelationship(): |
508 return self._parent | 508 return self._parent |
509 return None | 509 return None |
510 | 510 |
511 def unlink(self): | 511 def unlink(self): |
512 """ Unset our _parent, and remove us from the _parent._childs """ | 512 """ Unset our _parent, and remove us from the _parent._childs |
513 if self.isRoot(): | 513 We are still in the product list. |
514 self._parent._products.remove(self) | 514 """ |
515 else: | 515 if not self.isRoot(): |
516 self._parent._product = None | 516 self._parent._product = None |
517 self._parent = None | 517 self._parent = None |
518 | |
519 def link(self, parent): | |
520 self._parent = parent | |
521 if not self.isRoot(): | |
522 parent._product = self | |
518 | 523 |
519 def validate(self): | 524 def validate(self): |
520 if not self._productid: | 525 if not self._productid: |
521 raise ValidationError('A Product must have a ProductID') | 526 raise ValidationError('A Product must have a ProductID') |
522 if not self._name: | 527 if not self._name: |