[Secure-testing-commits] r2071 - lib/python

Florian Weimer fw at costa.debian.org
Wed Sep 21 15:15:43 UTC 2005


Author: fw
Date: 2005-09-21 15:15:42 +0000 (Wed, 21 Sep 2005)
New Revision: 2071

Modified:
   lib/python/bugs.py
   lib/python/debian_support.py
   lib/python/security_db.py
Log:
Make (bug_name, package, release) unique in the package_notes table.
This is necessary because otherwise, the version tracking code does
not work right.  We do not lose any data by doing this; package status
was already tracked by bug and not by package note.

lib/python/bugs.py (PackageNote.merge, Bug.mergeNotes):
  New.
(CANFile.finishBugs, CVEFile.finishBugs, DSAFile.finishBugs):
  New.  Merge package notes for CAN, CVE and DSA files.

lib/python/security_db.py (DB):
  Bump schema version.
(DB.initSchema):
  Add the UNIQUE index mentioned above.

lib/python/debian_support.py (mergeAsSets):
  New.
(test):
  Test cases for mergeAsSets.


Modified: lib/python/bugs.py
===================================================================
--- lib/python/bugs.py	2005-09-21 09:31:54 UTC (rev 2070)
+++ lib/python/bugs.py	2005-09-21 15:15:42 UTC (rev 2071)
@@ -169,6 +169,17 @@
                 ("SELECT bug FROM debian_bugs WHERE note = ?", (self.id,)):
             self.bugs.append(int(b))
 
+    def merge(self, other):
+        """Add the contents of another, compatible package note to this one."""
+        assert self.release is other.release
+        assert self.package == other.package
+        self.bugs = debian_support.mergeAsSets(self.bugs, other.bugs)
+        self.urgency = max(self.urgency, other.urgency)
+        if self.fixed_version is None or other.fixed_version is None:
+            self.fixed_version = None
+        else:
+            self.fixed_version = max(self.fixed_version, other.fixed_version)
+
 class PackageNoteFromDB(PackageNote):
     def __init__(self, cursor, nid):
         for bug_name, package, fixed_version, release, urgency, package_kind\
@@ -316,6 +327,25 @@
         self.xref = xref
         self.not_for_us = not_for_us
 
+    def mergeNotes(self):
+        """Merge notes so that there is only one note for each
+        (package, release) pair."""
+        if len(self.notes) < 2:
+            return
+        notes = {}
+        for n in self.notes:
+            key = (n.package, n.release)
+            if notes.has_key(key):
+                notes[key].merge(n)
+            else:
+                notes[key] = n
+        l = notes.keys()
+        l.sort()
+        nts = []
+        for key in l:
+            nts.append(notes[key])
+        self.notes = nts
+
 class BugFromDB(Bug):
     def __init__(self, cursor, name):
         assert type(name) == types.StringType
@@ -698,6 +728,11 @@
                     desc = desc[1:-1]
         return (None, cve, desc)
 
+    def finishBug(self, bug):
+        # Merge identical package notes, for historical reasons.
+        bug.mergeNotes()
+        return bug
+
 class CVEFile(FileBase):
     """A CVE file, as used by the Debian testing security team."""
 
@@ -726,6 +761,11 @@
                     desc = desc[1:-1]
         return (None, cve, desc)
 
+    def finishBug(self, bug):
+        # Merge identical package notes, for historical reasons.
+        bug.mergeNotes()
+        return bug
+        
 class DSAFile(FileBase):
     """A DSA file.
 
@@ -762,6 +802,11 @@
             self.raiseSyntaxError("invalid month name %s" % `month`)
         return ("%s-%02d-%s" % (year, month, day), name, desc)
 
+    def finishBug(self, bug):
+        # Merge identical package notes, for historical reasons.
+        bug.mergeNotes()
+        return bug
+        
 class DTSAFile(FileBase):
     """A DTSA file.
 

Modified: lib/python/debian_support.py
===================================================================
--- lib/python/debian_support.py	2005-09-21 09:31:54 UTC (rev 2070)
+++ lib/python/debian_support.py	2005-09-21 15:15:42 UTC (rev 2071)
@@ -419,6 +419,17 @@
     replaceFile(lines, local)
     return lines
 
+def mergeAsSets(*args):
+    """Create an order set (represented as a list) of the objects in
+    the sequences passed as arguments."""
+    s = {}
+    for x in args:
+        for y in x:
+            s[y] = True
+    l = s.keys()
+    l.sort()
+    return l
+
 def test():
     # Version
     assert Version('0') < Version('a')
@@ -459,5 +470,8 @@
     patchLines(file_a, patchesFromEdScript(patch))
     assert ''.join(file_b) == ''.join(file_a)
 
+    assert len(mergeAsSets([])) == 0
+    assert ''.join(mergeAsSets("abc", "cb")) == "abc"
+
 if __name__ == "__main__":
     test()

Modified: lib/python/security_db.py
===================================================================
--- lib/python/security_db.py	2005-09-21 09:31:54 UTC (rev 2070)
+++ lib/python/security_db.py	2005-09-21 15:15:42 UTC (rev 2071)
@@ -93,7 +93,7 @@
         self.db = apsw.Connection(name)
         self.verbose = verbose
 
-        self.schema_version = 8
+        self.schema_version = 9
 
         c = self.cursor()
         for (v,) in c.execute("PRAGMA user_version"):
@@ -197,7 +197,8 @@
          package_kind TEXT NOT NULL DEFAULT 'unknown',
          urgency TEXT NOT NULL)""")
         cursor.execute(
-            "CREATE INDEX package_notes_bug ON package_notes(bug_name)")
+            """CREATE UNIQUE INDEX package_notes_bug
+            ON package_notes(bug_name, package, release)""")
 
         cursor.execute("""CREATE TABLE debian_bugs
         (bug INTEGER NOT NULL,




More information about the Secure-testing-commits mailing list