[PATCH 20 of 54] Add method to check group and producttree references

Wald Commits scm-commit at wald.intevation.org
Wed Jan 7 10:56:37 CET 2015


# HG changeset patch
# User Benoît Allard <benoit.allard at greenbone.net>
# Date 1413359432 -7200
# Node ID 4b53e7bcff0d40108f14322206a5841c8216d853
# Parent  8a89b7a591e657c3daef81465d887251219693e4
Add method to check group and producttree references

diff -r 8a89b7a591e6 -r 4b53e7bcff0d farolluz/cvrf.py
--- 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:


More information about the Farol-commits mailing list