changeset 19:4b53e7bcff0d

Add method to check group and producttree references
author Benoît Allard <benoit.allard@greenbone.net>
date Wed, 15 Oct 2014 09:50:32 +0200
parents 8a89b7a591e6
children dfa9fe731e78 4004b67216a9
files farolluz/cvrf.py
diffstat 1 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/farolluz/cvrf.py	Tue Oct 14 16:49:36 2014 +0200
+++ b/farolluz/cvrf.py	Wed Oct 15 09:50:32 2014 +0200
@@ -699,12 +699,9 @@
         if not isinstance(groupids, list):
             groupids = [groupids]
         for groupid in groupids:
-            print "testing GroupId: ", groupid
             for _ in self.mentionsGroupId(groupid):
                 # We only need to know if the generator yield at least one elem.
-                print 'True'
                 return True
-        print 'False'
         return False
 
     def validate(self, productids, groupids):
@@ -1040,7 +1037,7 @@
         return set(self.getProductForID(p) for p in products)
 
     def isProductOrphan(self, productid):
-        """ Returns if a productid is mentionned nowhere in the document """
+        """ Returns if a productid is mentioned nowhere in the document """
         # We first look at the ProductTree
         ptree = self._producttree
         for relation in ptree._relationships:
@@ -1056,10 +1053,30 @@
             if vulnerability.isMentioningProdId(productid):
                 return False
             for groupid in groupids:
+                # This will never be executed as we bail out on len(groups) > 0
                 if vulnerability.isMentioningGroupId(groupid):
                     return False
         return True
 
+    def isGroupOrphan(self, groupid):
+        """ Returns if a group can be safely deleted """
+        for vulnerability in self._vulnerabilities:
+            if vulnerability.isMentioningGroupId(groupid):
+                return False
+        return True
+
+    def isProductTreeOrphan(self):
+        """ Difference with the previous method is that we don;t care about
+        inter-producttree references """
+        for vulnerability in self._vulnerabilities:
+            for product in self._producttree._products:
+                if vulnerability.isMentioningProdId(product._productid):
+                    return False
+            for group in self._producttree._groups:
+                if vulnerability.isMentioningGroupId(group._groupid):
+                    return False
+        return True
+
     def getNote(self, ordinal):
         for note in self._notes:
             if note._ordinal == ordinal:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)