diff options
author | Bjoern Tropf <asymmail@googlemail.com> | 2009-06-11 18:23:09 +0200 |
---|---|---|
committer | Bjoern Tropf <asymmail@googlemail.com> | 2009-06-11 18:23:09 +0200 |
commit | 70157ad02d9f9763f130f880144e68eb87279d68 (patch) | |
tree | a9dfad3689a9052e86739588b6ca178220a5082e | |
parent | Fix some bugs (diff) | |
download | kernel-check-70157ad02d9f9763f130f880144e68eb87279d68.tar.gz kernel-check-70157ad02d9f9763f130f880144e68eb87279d68.tar.bz2 kernel-check-70157ad02d9f9763f130f880144e68eb87279d68.zip |
Add kernel class; Fix some bugs
-rw-r--r-- | TODO | 1 | ||||
-rwxr-xr-x | kernel-check.py | 11 | ||||
-rwxr-xr-x | kernellib.py | 134 |
3 files changed, 80 insertions, 66 deletions
@@ -4,7 +4,6 @@ Todo - Find a solution for <ref source url/> - Rename functions - Rework classes (Use class methodes/clean) -- Implement kernel class Clean code ========== diff --git a/kernel-check.py b/kernel-check.py index 865aeb4..92074bf 100755 --- a/kernel-check.py +++ b/kernel-check.py @@ -52,9 +52,9 @@ def main(argv): print '>>> Gathering system information' kernel = lib.extract_version(os.uname()[2]) - if kernel: - info('Kernel version: %s' % (color('GOOD', '%s-%s' % (kernel['version'], kernel['revision'])))) - info('Kernel sources: %s' % color('GOOD', kernel['source'])) + if kernel is not None: + info('Kernel version: %s' % (color('GOOD', '%s-%s' % (kernel.version, kernel.revision)))) + info('Kernel sources: %s' % color('GOOD', kernel.source)) else: error('No kernel information found!') sys.exit() @@ -102,7 +102,7 @@ def main(argv): error('No vulnerability files found!') sys.exit() - + best = lib.best_version(kernel.source) if len(cve['canfix']): info('') info('These could be fixed by upgrading:') @@ -113,8 +113,7 @@ def main(argv): info('To print information about a vulnerability try:') info('$ %s -i [id]' % sys.argv[0]) info('') - info('Upgrading to the latest version') #FIXME latest version == current version - best = lib.best_version(kernel['source']) + info('Upgrading to the latest version') info('[%s]' % color('GOOD', best)) info('is recommended!') else: diff --git a/kernellib.py b/kernellib.py index 1b89852..c22a55e 100755 --- a/kernellib.py +++ b/kernellib.py @@ -26,7 +26,6 @@ import mmap import os import portage import re -import sys #TODO remove (debugging) import urllib BUGORDER = ['bugid', 'reporter', 'reported', 'arch', 'affected'] @@ -75,7 +74,7 @@ def debug(msg): def error(msg): logging.error(msg) -class Cve(dict): +class Cve: #TODO Description cve = str() @@ -89,37 +88,55 @@ class Cve(dict): def __init__(self, cve): self.cve = cve - return - -class Genpatch(dict): +class Genpatch: #TODO Description base = bool() extras = bool() - pvr = str() - source = str() + kernel = None version = str() want = str() #TODO use __repr__ def __init__(self, version): self.version = version - return + + #FIXME + def __eq__(self, other): + return (''.join((str(self.base), str(self.extras), + str(self.kernel.revision), str(self.kernel.source), + str(self.kernel.version), self.version)) + == ''.join((str(other.base), str(other.extras), + str(other.kernel.revision), str(other.kernel.source), + str(other.kernel.version), other.version))) + + + def __ne__(self,other): + return not self.__eq__(other) + + +class Kernel: + #TODO Description + + revision = str() + source = str() + version = str() + + def __init__(self, source): + self.source = source - #TODO Can be easier def __eq__(self, other): - print dir(self) - return (str(self.base) + str(self.extras) + self.pvr + self.source + self.version - == str(other.base) + str(other.extras) + other.pvr + other.source + other.version) + return (''.join((self.revision, self.source, self.version)) + == ''.join((other.revision, other.source, other.version))) def __ne__(self,other): return not self.__eq__(other) -class Vulnerability(dict): +class Vulnerability: #TODO Description arch = str() @@ -133,14 +150,19 @@ class Vulnerability(dict): def __init__(self, bugid): self.bugid = bugid - return - #FIXME Rework class Interval: 'Defines an interval for kernel ebuilds' - def __init__(self, name, lower, upper, lower_inclusive, upper_inclusive, expand): + name = str() + lower = str() + upper = str() + lower_i = str() + upper_i = str() + expand = str() + + def __init__(self, name, lower, upper, lower_i, upper_i, expand): if name == 'linux' or name == 'genpatches': pass elif name == 'gp': @@ -149,8 +171,8 @@ class Interval: name = '%s-sources' % (name) self.name = name - self.lower_inclusive = lower_inclusive - self.upper_inclusive = upper_inclusive + self.lower_i = lower_i + self.upper_i = upper_i if name == 'genpatches': if lower: self.lower = lower.replace('-','.') @@ -172,13 +194,13 @@ class Interval: if self.expand: interval += '+' interval += ' ' - if self.lower and self.lower_inclusive: + if self.lower and self.lower_i: interval += '>=%s ' % (self.lower) - if self.lower and not self.lower_inclusive: + if self.lower and not self.lower_i: interval += '>%s ' % (self.lower) - if self.upper and self.upper_inclusive: + if self.upper and self.upper_i: interval += '<=%s' % (self.upper) - if self.upper and not self.upper_inclusive: + if self.upper and not self.upper_i: interval += '<%s' % (self.upper) return interval @@ -227,16 +249,15 @@ def parse_genpatch_list(directory): except: break + kernel = Kernel(pkg[1]) + kernel.version = pkg[2] + kernel.revision = pkg[3] + genpatch = Genpatch(pkg[2] + '-' + genpatch_v) - genpatch.source = pkg[1] + genpatch.kernel = kernel genpatch.base = ('base' in genpatch_w) genpatch.extras = ('extras' in genpatch_w) - if pkg[3] == 'r0': - genpatch.pvr = pkg[2] - else: - genpatch.pvr = pkg[2] + '-' + pkg[3] - patches.append(genpatch) return patches @@ -253,9 +274,13 @@ def read_genpatch_file(directory): root = et.parse(memory_map).getroot() for tree in root: + #FIXME Rework + kernel = Kernel(tree.get('kernels')) + kernel.revision = tree.get('kernelr') + kernel.version = tree.get('kernelv') + genpatch = Genpatch(tree.get('version')) - genpatch.source = tree.get('source') - genpatch.pvr = tree.get('pvr') + genpatch.kernel = kernel genpatch.base = (tree.get('base') == 'true') genpatch.extras = (tree.get('extras') == 'true') @@ -272,24 +297,23 @@ def write_genpatch_file(directory, patches): for item in patches: genpatch = et.SubElement(root, 'genpatch') - genpatch.set('source', item.source) - genpatch.set('pvr', item.pvr) + #FIXME Rework + genpatch.set('kernelr', str(item.kernel.revision)) + genpatch.set('kernels', str(item.kernel.source)) + genpatch.set('kernelv', str(item.kernel.version)) genpatch.set('version', item.version) genpatch.set('base', str(item.base).lower()) genpatch.set('extras', str(item.extras).lower()) write_xml(root, filename) - return - -#TODO Rework +#TODO Rework, kernel moved into genpatch? def get_genpatch(patches, kernel): #TODO Description for item in patches: - if kernel['source'] == item.source: - if kernel['version'] + '-' + kernel['revision'] == item.pvr: + if item.kernel == kernel: #FIXME Why does 'is' not work? #TODO use __repr__ if item.base: item.want = 'base' @@ -508,8 +532,6 @@ def write_cve_file(directory, vul): write_xml(root, filename) - return - def write_xml(root, filename): #TODO Description @@ -519,8 +541,6 @@ def write_xml(root, filename): doc = et.ElementTree(root) doc.write(xmlout, encoding='utf-8') - return - #TODO move 'if self.lower' and 'if self.upper' together def is_in_interval(self, version): @@ -533,9 +553,9 @@ def is_in_interval(self, version): if not portage_versions.vercmp(version, self.lower): error("Could not compare %s and %s" % (self.lower, version, str(self))) - if not result and not self.lower_inclusive: + if not result and not self.lower_i: return False - if not result and self.lower_inclusive: + if not result and self.lower_i: return True if result < 0: return False @@ -544,9 +564,9 @@ def is_in_interval(self, version): if not portage_versions.vercmp(version, self.upper): error("Could not compare %s and %s" % (self.upper, version, str(self))) - if not result and not self.upper_inclusive: + if not result and not self.upper_i: return False - if not result and self.upper_inclusive: + if not result and self.upper_i: return True if result > 0: return False @@ -629,31 +649,27 @@ def extract_version(release): return None version, rest = match.groups() - source = 'vanilla' - revision = 'r0' + + kernel = Kernel('vanilla') + kernel.revision = 'r0' + kernel.version = version for elem in (rest or '').split('-'): if REGEX['rcd'].match(elem): - version += '_' + elem + kernel.version += '_' + elem elif REGEX['gitd'].match(elem): - source = 'git' - revision = 'r' + REGEX['gitd'].match(elem).groups()[0] + kernel.source = 'git' + kernel.revision = 'r' + REGEX['gitd'].match(elem).groups()[0] elif REGEX['rd'].match(elem): - revision = elem + kernel.revision = elem elif elem in GENERAL_KERNEL_TYPES: if elem in GENTOO_KERNEL_TYPES: - source = elem + '-sources' + kernel.source = elem + '-sources' else: - source = elem + kernel.source = elem elif elem != '': error('Dropping unknown version component \'%s\', probably local tag.' % elem) - kernel = { - 'revision' : revision, - 'source' : source, - 'version' : version - } - return kernel |