diff options
author | Bjoern Tropf <asymmail@googlemail.com> | 2009-06-05 19:49:02 +0200 |
---|---|---|
committer | Bjoern Tropf <asymmail@googlemail.com> | 2009-06-05 19:49:02 +0200 |
commit | 80bc641104e4265984d5f1f0b2c455ca1a42f4d8 (patch) | |
tree | 97707e271b4db125d3dc8d69f322259b3e93aab6 | |
parent | Fix FIXMEs, edit TODO (diff) | |
download | kernel-check-80bc641104e4265984d5f1f0b2c455ca1a42f4d8.tar.gz kernel-check-80bc641104e4265984d5f1f0b2c455ca1a42f4d8.tar.bz2 kernel-check-80bc641104e4265984d5f1f0b2c455ca1a42f4d8.zip |
Add reading/parsing/writing genpatches
-rwxr-xr-x | collector.py | 15 | ||||
-rwxr-xr-x | kernellib.py | 80 |
2 files changed, 84 insertions, 11 deletions
diff --git a/collector.py b/collector.py index 12341a8..87225fa 100755 --- a/collector.py +++ b/collector.py @@ -64,7 +64,20 @@ def main(argv): if not os.path.isdir(folder[directory]): os.makedirs(folder[directory]) - #lib.parse_genpatches_list(folder['tree']) + print('Reading available genpatches...') + read_patches = lib.read_genpatch_file('genpatches.xml') + + print('Parsing genpatches from portage...') + found_patches = lib.parse_genpatch_list(folder['tree']) + + new_items = 0 + for item in found_patches: + if item not in read_patches: + read_patches.append(item) + new_items = new_items + 1 + + print('Adding %i new genpatches...' % new_items) + lib.write_genpatch_file(read_patches, 'genpatches.xml') print('Receiving the latest xml file from the nvd...') lib.receive_nvd_recent(folder['nvd']) diff --git a/kernellib.py b/kernellib.py index dca8f2b..90f348c 100755 --- a/kernellib.py +++ b/kernellib.py @@ -127,10 +127,10 @@ def receive_bugzilla_bug(directory, bugid): receive_file(directory, path, bugid) -def parse_genpatches_list(directory): +def parse_genpatch_list(directory): 'Returns a list containing all genpatches from portage' - genpatches = list() + patches = list() directory = os.path.join(directory, 'sys-kernel') for sources in os.listdir(directory): @@ -150,9 +150,68 @@ def parse_genpatches_list(directory): break genpatch = [pkg[1], pkg[2] + '_' + pkg[3] if pkg[3] != 'r0' else pkg[2], pkg[2] + '-' + genpatch_v, genpatch_w] - genpatches.append(genpatch) + patches.append(genpatch) - return genpatches + return patches + + +def write_xml(root, filename): + #TODO: Description + + with open(filename, 'w') as xmlout: + indent(root) + doc = et.ElementTree(root) + doc.write(xmlout, encoding='utf-8') + + +def read_genpatch_file(filename): + #TODO: Description + + with open(filename, 'r+') as xml_data: + memory_map = mmap.mmap(xml_data.fileno(), 0) + root = et.parse(memory_map).getroot() + + patches = list() + + for tree in root: + genpatch = [tree.get('source'), tree.get('pvr'), tree.get('version'), ''] + + #FIXME: Can be done easier + if tree.get('base') == 'true': + genpatch[3] = 'base' + if tree.get('extras') == 'true': + genpatch[3] = 'base extras' + else: + if tree.get('extras') == 'true': + genpatch[3] = 'extras' + + patches.append(genpatch) + + return patches + + +def write_genpatch_file(genpatches, filename): + #TODO: Description + + root = et.Element('patches') + + for item in genpatches: + genpatch = et.SubElement(root, 'genpatch') + genpatch.set('source', item[0]) + genpatch.set('pvr', item[1]) + genpatch.set('version', item[2]) + if 'base' in item[3]: + genpatch.set('base', 'true') + else: + genpatch.set('base', 'false') + if 'extras' in item[3]: + genpatch.set('extras', 'false') + else: + genpatch.set('extras', 'true') + + write_xml(root, filename) + + return def parse_bugzilla_list(filename): @@ -208,7 +267,7 @@ def parse_nvd_dict(directory): elements = ['CVSS_vector', 'CVSS_score', 'name', 'severity', 'published'] - for i, tree in enumerate(root): + for tree in root: dic = dict() url = list() @@ -265,10 +324,13 @@ def extract_cves(string): return cves + def read_cve_file(): #TODO: Implement - return None + return + +#TODO: Deprecated, create a vulnerability class def write_cve_file(directory, bugid, bug_dict, nvd_dict): 'Write a bug file containing all important information for kernel-check' @@ -336,11 +398,9 @@ def write_cve_file(directory, bugid, bug_dict, nvd_dict): node = et.SubElement(cveroot, element) node.text = xml_cve_dic[element] - with open(filename, 'w') as xmlout: - indent(root) - doc = et.ElementTree(root) - doc.write(xmlout, encoding='utf-8') + write_xml(root, filename) + return class IntervalEntry: 'Defines an interval for kernel ebuilds' |