From 9b3a13e5d48024e62352b25d882708c3505e02f9 Mon Sep 17 00:00:00 2001 From: Emilio Pozuelo Monfort Date: Tue, 1 Dec 2020 14:01:36 +0100 Subject: sectracker.parsers: add function to write the file back This change and the previous ones based on work by Brian with additional fixes and adaptations by me. --- lib/python/sectracker/parsers.py | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'lib') diff --git a/lib/python/sectracker/parsers.py b/lib/python/sectracker/parsers.py index 42e7da75cb..7f0f1e3dad 100644 --- a/lib/python/sectracker/parsers.py +++ b/lib/python/sectracker/parsers.py @@ -1,5 +1,7 @@ # sectracker.parsers -- various text file parsers # Copyright (C) 2010 Florian Weimer +# Copyright (C) 2019 Brian May +# Copyright (C) 2020 Emilio Pozuelo Monfort # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -276,6 +278,64 @@ def cvelist(path, f): return Bug(path, Header(headerlineno, name, desc), tuple(anns)) return _parselist(path, f, parseheader, finish) +def writecvelist(data, f): + for bug in data: + if isinstance(bug, Bug): + f.write(bug.header.name) + if bug.header.description: + f.write(" ") + f.write(bug.header.description) + f.write("\n") + for annotation in bug.annotations: + if isinstance(annotation, FlagAnnotation): + f.write("\t") + f.write(annotation.type) + f.write("\n") + elif isinstance(annotation, StringAnnotation): + f.write("\t") + f.write(annotation.type) + f.write(": ") + f.write(annotation.description) + f.write("\n") + elif isinstance(annotation, PackageAnnotation): + f.write("\t") + if annotation.release: + f.write("[") + f.write(str(annotation.release)) + f.write("] ") + f.write("- ") + f.write(annotation.package + " ") + if annotation.version: + f.write(annotation.version) + elif annotation.kind: + f.write("<") + f.write(annotation.kind) + f.write(">") + items = [] + for flag in annotation.flags: + if isinstance(flag, PackageBugAnnotation): + items.append("bug #%s" % flag.bug) + elif isinstance(flag, PackageUrgencyAnnotation): + items.append(flag.severity) + else: + raise RuntimeError("Got unexpected package flag type %s" % type(flag)) + if annotation.description: + items.append(str(annotation.description)) + if items: + f.write(" (") + f.write("; ".join(items)) + f.write(")") + f.write("\n") + elif isinstance(annotation, XrefAnnotation): + if annotation.bugs: + f.write("\t{") + f.write(" ".join(annotation.bugs)) + f.write("}\n") + else: + raise RuntimeError("Got unexpected annotation type %s" % type(annotation)) + else: + raise RuntimeError("Got unexpected bug type %s" % type(bug)) + def _checkrelease(anns, diag, kind): for ann in anns: if ann.type == "package" and ann.release is None: -- cgit v1.2.3