Mercurial > farol > farolluz
comparison farolluz/cvrf.py @ 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 | 90852c11fabd |
children | 4004b67216a9 |
comparison
equal
deleted
inserted
replaced
18:8a89b7a591e6 | 19:4b53e7bcff0d |
---|---|
697 """ Make sure you call this with a list (not a generator or a tuple) | 697 """ Make sure you call this with a list (not a generator or a tuple) |
698 when wished """ | 698 when wished """ |
699 if not isinstance(groupids, list): | 699 if not isinstance(groupids, list): |
700 groupids = [groupids] | 700 groupids = [groupids] |
701 for groupid in groupids: | 701 for groupid in groupids: |
702 print "testing GroupId: ", groupid | |
703 for _ in self.mentionsGroupId(groupid): | 702 for _ in self.mentionsGroupId(groupid): |
704 # We only need to know if the generator yield at least one elem. | 703 # We only need to know if the generator yield at least one elem. |
705 print 'True' | |
706 return True | 704 return True |
707 print 'False' | |
708 return False | 705 return False |
709 | 706 |
710 def validate(self, productids, groupids): | 707 def validate(self, productids, groupids): |
711 if not self._ordinal: | 708 if not self._ordinal: |
712 raise ValidationError('A Vulnerability must have an ordinal') | 709 raise ValidationError('A Vulnerability must have an ordinal') |
1038 for productid in status._productids: | 1035 for productid in status._productids: |
1039 products.add(productid) | 1036 products.add(productid) |
1040 return set(self.getProductForID(p) for p in products) | 1037 return set(self.getProductForID(p) for p in products) |
1041 | 1038 |
1042 def isProductOrphan(self, productid): | 1039 def isProductOrphan(self, productid): |
1043 """ Returns if a productid is mentionned nowhere in the document """ | 1040 """ Returns if a productid is mentioned nowhere in the document """ |
1044 # We first look at the ProductTree | 1041 # We first look at the ProductTree |
1045 ptree = self._producttree | 1042 ptree = self._producttree |
1046 for relation in ptree._relationships: | 1043 for relation in ptree._relationships: |
1047 if productid == relation._productreference: | 1044 if productid == relation._productreference: |
1048 return False | 1045 return False |
1054 # Go through all the Vulnerabilities | 1051 # Go through all the Vulnerabilities |
1055 for vulnerability in self._vulnerabilities: | 1052 for vulnerability in self._vulnerabilities: |
1056 if vulnerability.isMentioningProdId(productid): | 1053 if vulnerability.isMentioningProdId(productid): |
1057 return False | 1054 return False |
1058 for groupid in groupids: | 1055 for groupid in groupids: |
1056 # This will never be executed as we bail out on len(groups) > 0 | |
1059 if vulnerability.isMentioningGroupId(groupid): | 1057 if vulnerability.isMentioningGroupId(groupid): |
1058 return False | |
1059 return True | |
1060 | |
1061 def isGroupOrphan(self, groupid): | |
1062 """ Returns if a group can be safely deleted """ | |
1063 for vulnerability in self._vulnerabilities: | |
1064 if vulnerability.isMentioningGroupId(groupid): | |
1065 return False | |
1066 return True | |
1067 | |
1068 def isProductTreeOrphan(self): | |
1069 """ Difference with the previous method is that we don;t care about | |
1070 inter-producttree references """ | |
1071 for vulnerability in self._vulnerabilities: | |
1072 for product in self._producttree._products: | |
1073 if vulnerability.isMentioningProdId(product._productid): | |
1074 return False | |
1075 for group in self._producttree._groups: | |
1076 if vulnerability.isMentioningGroupId(group._groupid): | |
1060 return False | 1077 return False |
1061 return True | 1078 return True |
1062 | 1079 |
1063 def getNote(self, ordinal): | 1080 def getNote(self, ordinal): |
1064 for note in self._notes: | 1081 for note in self._notes: |