From fafe483991149607160325eb6ef572faa141acf2 Mon Sep 17 00:00:00 2001 From: Emilio Pozuelo Monfort Date: Fri, 11 May 2018 15:22:31 +0200 Subject: Simplify Extends support BugExtend.writeDB() is pretty similar to BugBase's, so update the latter to take extends into account when necessary to avoid unneeded duplicated code. --- lib/python/bugs.py | 64 +++++++++++++++++------------------------------------- 1 file changed, 20 insertions(+), 44 deletions(-) (limited to 'lib') diff --git a/lib/python/bugs.py b/lib/python/bugs.py index 5ec843b621..676f5f540f 100644 --- a/lib/python/bugs.py +++ b/lib/python/bugs.py @@ -201,6 +201,7 @@ class BugBase: self.notes = [] self.xref = [] self.not_for_us = False + self.is_extend = False def isFromCVE(self): """Returns True if the name has been officially assigned. @@ -226,16 +227,18 @@ class BugBase: not_for_us = 0 import apsw - try: - cursor.execute("""INSERT INTO bugs - (name, cve_status, not_for_us, description, release_date, - source_file, source_line) - VALUES (?, ?, ?, ?, ?, ?, ?)""", - (self.name, self.cveStatus(), not_for_us, - self.description, self.date or '', - self.source_file, self.source_line)) - except apsw.ConstraintError: - raise ValueError, "bug name %s is not unique" % self.name + + if not self.is_extend: + try: + cursor.execute("""INSERT INTO bugs + (name, cve_status, not_for_us, description, release_date, + source_file, source_line) + VALUES (?, ?, ?, ?, ?, ?, ?)""", + (self.name, self.cveStatus(), not_for_us, + self.description, self.date or '', + self.source_file, self.source_line)) + except apsw.ConstraintError: + raise ValueError, "bug name %s is not unique" % self.name for (typ, c) in self.comments: cursor.execute("""INSERT INTO bugs_notes @@ -258,7 +261,7 @@ class Bug(BugBase): """Class for bugs for which we have some data.""" def __init__(self, fname, lineno, date, name, description, comments, notes, - xref, not_for_us=False): + xref, not_for_us=False, is_extend=False): for n in notes: assert isinstance(n, PackageNote) \ or isinstance(n, PackageNoteNoDSA) @@ -269,6 +272,7 @@ class Bug(BugBase): self.notes = notes self.xref = xref self.not_for_us = not_for_us + self.is_extend = is_extend def mergeNotes(self): """Merge notes so that there is only one note for each @@ -300,28 +304,6 @@ class Bug(BugBase): nts.append(notes[key]) self.notes = nts -class BugExtend(Bug): - def writeDB(self, cursor): - """Writes the record to an SQLite3 database.""" - - for (typ, c) in self.comments: - cursor.execute("""INSERT INTO bugs_notes - (bug_name, typ, comment) VALUES (?, ?, ?)""", - (self.name, typ, c)) - - for n in self.notes: - n.writeDB(cursor, self.name) - - import apsw - for x in self.xref: - try: - cursor.execute("""INSERT INTO bugs_xref - (source, target) VALUES (?, ?)""", - (self.name, x)) - except apsw.ConstraintError: - raise ValueError, \ - "cross reference to %s appears multiple times" % x - class BugFromDB(Bug): def __init__(self, cursor, name): assert type(name) in types.StringTypes @@ -458,14 +440,12 @@ class FileBase(debian_support.PackageFile): re_rejected = re.compile(r'^(?:NOTE:\s+rejected|REJECTED)\s*$') re_note = re.compile(r'^NOTE:\s+(.*)$') re_todo = re.compile(r'^TODO:\s+(.*)$') + is_extend = False def __init__(self, name, fileObj=None): debian_support.PackageFile.__init__(self, name, fileObj) self.removed_packages = {} - def isExtend(self, name): - return False - def isUniqueName(self, name): """Returns True if the name is a real, unique name.""" return True @@ -754,13 +734,10 @@ class FileBase(debian_support.PackageFile): if first_bug: break record_name = temp_bug_name(first_bug, description) - if self.isExtend(record_name): - cls = BugExtend - else: - cls = Bug - yield self.finishBug(cls(self.file.name, first_lineno, date, + yield self.finishBug(Bug(self.file.name, first_lineno, date, record_name, description, - comments, notes=pkg_notes, xref=xref)) + comments, notes=pkg_notes, xref=xref, + is_extend=self.is_extend)) def finishBug(self, bug): """Applies a transformation to the bug after it has been @@ -806,8 +783,7 @@ class CVEFile(FileBase): class CVECUSTOMERFile(CVEFile): re_cve = re.compile(r'^(CVE-\d{4}-(?:\d{4,}|XXXX)|TEMP-\d+-\S+)\s+(.*?)\s*$') - def isExtend(self, name): - return True + is_extend = True class DSAFile(FileBase): """A DSA file. -- cgit v1.2.3