diff options
Diffstat (limited to 'lib/kernellib.py')
-rw-r--r-- | lib/kernellib.py | 77 |
1 files changed, 34 insertions, 43 deletions
diff --git a/lib/kernellib.py b/lib/kernellib.py index 0bc4044..bc979cd 100644 --- a/lib/kernellib.py +++ b/lib/kernellib.py @@ -5,7 +5,6 @@ from __future__ import with_statement from contextlib import closing -import xml.etree.cElementTree as et import cStringIO import datetime import inspect @@ -15,6 +14,7 @@ import os import portage import re import urllib +import xml.etree.cElementTree ARCHES = [ @@ -47,7 +47,7 @@ KERNEL_TYPES = [ 'vserver', 'win4lin', 'wolk-dev', 'wolk', 'xbox', 'xen', 'xfs' ] -VERSION = '0.3.9' +VERSION = '0.3.10' DEBUG = False FILEPATH = os.path.dirname(os.path.realpath(__file__)) PORTDIR = portage.settings['PORTDIR'] @@ -63,6 +63,7 @@ def BUG_ON(msg): print 'DEBUG line %s in %s(): %s' % (inspect.stack()[1][2], inspect.stack()[1][3], msg) + class Evaluation: """Evaluation class @@ -79,7 +80,7 @@ class Evaluation: self.unaffected = list() -class Comparison: +class Comparison: #TODO Check if deprecated """Comparison class """ @@ -118,11 +119,11 @@ class Cve: def __init__(self, cve): self.cve = cve - def __eq__(self, other): - return (self.cve == other.cve) #FIXME is this enough? + def __eq__(self, diff): + return (self.cve == diff.cve) #FIXME is this enough? - def __ne__(self, other): - return not self.__eq__(other) + def __ne__(self, diff): + return not self.__eq__(diff) class Genpatch: @@ -146,16 +147,16 @@ class Genpatch: return 'extras' - def __eq__(self, other): - if self.kernel == other.kernel: + def __eq__(self, diff): + if self.kernel == diff.kernel: return (''.join((str(self.base), str(self.extras), self.version)) - == ''.join((str(other.base), str(other.extras), other.version))) + == ''.join((str(diff.base), str(diff.extras), diff.version))) else: return False - def __ne__(self, other): - return not self.__eq__(other) + def __ne__(self, diff): + return not self.__eq__(diff) class Kernel: @@ -174,14 +175,15 @@ class Kernel: return str(self.version + '-' + self.source + '-' + self.revision) - def __eq__(self, other): - return (''.join((self.revision, self.source, self.version, - str(self.genpatch))) == ''.join((other.revision, - other.source, other.version, str(other.genpatch)))) + def __eq__(self, diff): + return (''.join((self.revision, self.source, + self.version, str(self.genpatch))) + == ''.join((diff.revision, diff.source, + diff.version, str(diff.genpatch)))) - def __ne__(self, other): - return not self.__eq__(other) + def __ne__(self, diff): + return not self.__eq__(diff) class Vulnerability: @@ -199,11 +201,11 @@ class Vulnerability: def __init__(self, bugid): self.bugid = bugid - def __eq__(self, other): - return (self.bugid == other.bugid) #FIXME is this enough? + def __eq__(self, diff): + return (self.bugid == diff.bugid) #FIXME is this enough? - def __ne__(self, other): - return not self.__eq__(other) + def __ne__(self, diff): + return not self.__eq__(diff) class Interval: @@ -217,7 +219,6 @@ class Interval: upper: a string representing the upper boundary of the interval lower_i: a boolean indicating if the lower boundary is inclusive upper_i: a boolean indicating if the upper boundary is inclusive - expand: a boolean indicating if the interval is shadowing other intervals """ name = str() @@ -225,9 +226,8 @@ class Interval: upper = str() lower_i = bool() upper_i = bool() - expand = str() - def __init__(self, name, lower, upper, lower_i, upper_i, expand): + def __init__(self, name, lower, upper, lower_i, upper_i): if name == 'linux' or name == 'genpatches': pass elif name == 'gp': @@ -251,13 +251,9 @@ class Interval: self.lower = lower self.upper = upper - self.expand = expand - def __repr__(self): interval = str(self.name) - if self.expand: - interval += '+' interval += ' ' if self.lower and self.lower_i: interval += '>=%s ' % (self.lower) @@ -280,7 +276,6 @@ def interval_from_xml(root): upper = '' lower_i = False upper_i = False - expand = '' #TODO implement if root.find('lower') is not None: lower = root.find('lower').text @@ -290,7 +285,7 @@ def interval_from_xml(root): upper = root.find('upper').text upper_i = (root.find('upper').get('inclusive') == 'true') - return Interval(name, lower, upper, lower_i, upper_i, expand) + return Interval(name, lower, upper, lower_i, upper_i) #TODO Use exceptions @@ -523,20 +518,18 @@ def read_cve_file(directory, bugid): try: with open(filename, 'r+') as xml_data: memory_map = mmap.mmap(xml_data.fileno(), 0) - root = et.parse(memory_map).getroot() + root = xml.etree.cElementTree.parse(memory_map).getroot() except IOError: return None bugroot = root.find('bug') vul = Vulnerability(bugroot.find('bugid').text) - vul.arch = bugroot.find('arch').text - vul.reported = bugroot.find('reported').text - vul.reporter = bugroot.find('reporter').text - vul.status = bugroot.find('status').text - affectedroot = bugroot.find('affected') + for elem in ['arch', 'reported', 'reporter', 'status']: + setattr(vul, elem, bugroot.find(elem).text) + affectedroot = bugroot.find('affected') for item in affectedroot: interval = interval_from_xml(item) affected.append(interval) @@ -546,12 +539,10 @@ def read_cve_file(directory, bugid): for item in root: if item.tag == 'cve': cve = Cve(item.find('cve').text) - cve.desc = item.find('desc').text - cve.published = item.find('published').text - cve.refs = item.find('refs').text #FIXME - cve.severity = item.find('severity').text - cve.score = item.find('score').text - cve.vector = item.find('vector').text + + for elem in ['desc', 'published', 'refs', + 'severity', 'score', 'vector']: + setattr(cve, elem, item.find(elem).text) cves.append(cve) vul.cves = cves |