[Pkg-python-debian-commits] trunk r93: Sync debian_support.py with upstream, and drop local changes.

Adeodato Simó dato at net.com.org.es
Fri Dec 28 10:47:40 UTC 2007


------------------------------------------------------------
revno: 93
committer: Adeodato Simó <dato at net.com.org.es>
branch nick: trunk
timestamp: Fri 2007-12-28 11:47:40 +0100
message:
  Sync debian_support.py with upstream, and drop local changes.
removed:
  examples/packages/
added:
  TODO
renamed:
  examples/packages/grep-maintainer => examples/deb822/grep-maintainer*
modified:
  debian/changelog
  debian_bundle/debian_support.py
  examples/deb822/grep-maintainer*
    ------------------------------------------------------------
    revno: 91.1.1
    committer: Adeodato Simó <dato at net.com.org.es>
    branch nick: pd.debian_support
    timestamp: Thu 2007-12-27 17:39:17 +0100
    message:
      Sync debian_support.py with the latest code from secure-testing repo.
    modified:
      debian/changelog
      debian_bundle/debian_support.py
    ------------------------------------------------------------
    revno: 91.1.2
    committer: Adeodato Simó <dato at net.com.org.es>
    branch nick: pd.debian_support
    timestamp: Thu 2007-12-27 18:25:09 +0100
    message:
      Revert local changes to debian_support.py; rewrite example using deb822.
    removed:
      examples/packages/
    added:
      TODO
    renamed:
      examples/packages/grep-maintainer => examples/deb822/grep-maintainer*
    modified:
      debian/changelog
      debian_bundle/debian_support.py
      examples/deb822/grep-maintainer*
-------------- next part --------------
=== removed directory 'examples/packages'
=== added file 'TODO'
--- a/TODO	1970-01-01 00:00:00 +0000
+++ b/TODO	2007-12-27 17:25:09 +0000
@@ -0,0 +1,3 @@
+- Revamp the README files. In particular, note that debian_support.py
+  comes from the secure-testing repository (also in copyright!!), and
+  that for reading Packages files Deb822 should be used instead.

=== renamed file 'examples/packages/grep-maintainer' => 'examples/deb822/grep-maintainer' (properties changed)
--- a/examples/packages/grep-maintainer	2007-07-14 22:25:00 +0000
+++ b/examples/deb822/grep-maintainer	2007-12-27 17:25:09 +0000
@@ -8,12 +8,11 @@
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 
-"""Dumb maintainer-based grep for the dpkg status file, just to show the
-parsing API for Packages-like file."""
+"""Dumb maintainer-based grep for the dpkg status file."""
 
 import re
 import sys
-from debian_bundle.debian_support import PackageFile
+from debian_bundle import deb822
 
 try:
     maint_RE = re.compile(sys.argv[1])
@@ -21,8 +20,7 @@
     print "Usage: grep-maintainer REGEXP"
     sys.exit(1)
 
-packages = PackageFile('/var/lib/dpkg/status')
-for pkg in packages:
-    if maint_RE.search(pkg['maintainer']):
+for pkg in deb822.Packages.iter_paragraphs(file('/var/lib/dpkg/status')):
+    if pkg.has_key('Maintainer') and maint_RE.search(pkg['maintainer']):
         print pkg['package']
 

=== modified file 'debian/changelog'
--- a/debian/changelog	2007-12-24 11:07:35 +0000
+++ b/debian/changelog	2007-12-27 17:25:09 +0000
@@ -6,6 +6,22 @@
   [ Stefano Zacchiroli ]
   * Add examples dir for deb822 with a simple example.
 
+  [ Adeodato Simó ]
+
+  * Sync debian_support.py with the latest version from the secure-testing
+    repository. Note that this removes support for version comparison without
+    apt_pkg. (Our copy was modified in 0.1.2 to *accept* ~ in version strings,
+    but comparison without apt_pkg was already broken by then.)
+
+    Also, undo the change introduced for #431087, since we shouldn't be
+    keeping incompatible versions of debian_support.py around, plus the
+    desired functionality in that bug report is best provided by the deb822
+    module. (Closes: #457697, #457854)
+
+  * While rewriting the grep-maintainer example to use deb822.Packages to
+    accomodate the above change, make it cope with stanzas without a
+    maintainer field as well. (Closes: #457855)
+
  -- Stefano Zacchiroli <zack at debian.org>  Mon, 24 Dec 2007 12:06:49 +0100
 
 python-debian (0.1.7) unstable; urgency=low

=== modified file 'debian_bundle/debian_support.py'
--- a/debian_bundle/debian_support.py	2007-07-12 10:22:05 +0000
+++ b/debian_bundle/debian_support.py	2007-12-27 17:25:09 +0000
@@ -22,11 +22,8 @@
 import sha
 import types
 
-try:
-    import apt_pkg
-    __have_apt_pkg = True
-except ImportError:
-    __have_apt_pkg = False
+import apt_pkg
+apt_pkg.init()
 
 class ParseError(Exception):
     """An exception which is used to signal a parse failure.
@@ -58,100 +55,30 @@
         file.write("%s:%d: %s\n" % (self.filename, self.lineno, self.msg))
         file.flush()
 
-if __have_apt_pkg:
-    class Version:
-        """Version class which uses the original APT comparison algorithm."""
-
-        def __init__(self, version):
-            """Creates a new Version object."""
-            assert type(version) == types.StringType, `version`
-            assert version <> ""
-            self.__asString = version
-
-        def __str__(self):
-            return self.__asString
-
-        def __repr__(self):
-            return 'Version(%s)' % `self.__asString`
-
-        def __cmp__(self, other):
-            return apt_pkg.VersionCompare(self.__asString, other.__asString)
-
-
-    version_compare = apt_pkg.VersionCompare
-    apt_pkg.init()
-
-else:
-    letterValue = [None] * 256
-    def initLetterValue():
-        c = 0
-        for x in range(ord('A'), ord('Z') + 1):
-            letterValue[x] = chr(c)
-            c += 1
-        for x in range(ord('a'), ord('z') + 1):
-            letterValue[x] = chr(c)
-            c += 1
-        for x in "+-.:~":
-            letterValue[ord(x)] = chr(c)
-            c += 1
-    initLetterValue()
-    del initLetterValue
-
-    class Version:
-        """This class implements Debian version numbers."""
-
-        def __init__(self, version):
-            """Creates a new Version object."""
-            assert type(version) == types.StringType, `version`
-            assert version <> ""
-            self.__asString = version
-            self.__parsed = self.__parse(version)
-
-        def __str__(self):
-            return self.__asString
-
-        def __repr__(self):
-            return 'Version(%s)' % `self.__asString`
-
-        def __cmp__(self, other):
-            """Compares two versions.
-
-            This method implements the algorithm in the Debian Policy."""
-            return cmp(self.__parsed, other.__parsed)
-
-        def __parse(self, v, regexp=\
-                    re.compile(r'^(?:(\d+):)?([A-Za-z0-9.+~:-]+?)'
-                               + r'(?:-([A-Za-z0-9.+~]+))?$')):
-            match = regexp.match(v)
-            if match is None:
-                raise ValueError, "invalid Debian version string"
-            (epoch, upstream, debian) = match.groups()
-            if epoch is None:
-                epoch = 0
-            else:
-                epoch = int(epoch)
-            return (epoch, self.__parse_1(upstream), self.__parse_1(debian))
-
-        def __parse_1(self, x, non_digits=re.compile(r'^([^0-9]*)(.*)$'),
-                      digits=re.compile(r'^([0-9]*)(.*)$')):
-            l = []
-            while x is not None and x <> '':
-                (nd, x) = non_digits.match(x).groups()
-                (d, x) = digits.match(x).groups()
-                nd_l = []
-                for ch in nd:
-                    nd_l.append(letterValue[ord(ch)])
-                nd = ''.join(nd_l)
-                if d == '':
-                    d = 0
-                else:
-                    d = int(d)
-                l.append(nd)
-                l.append(d)
-            return l
-
-    def version_compare(a,b):
-        return cmp(Version(a), Version(b))
+class Version:
+    """Version class which uses the original APT comparison algorithm."""
+
+    def __init__(self, version):
+        """Creates a new Version object."""
+        t = type(version)
+        if t == types.UnicodeType:
+            version = version.encode('UTF-8')
+        else:
+            assert t == types.StringType, `version`
+        assert version <> ""
+        self.__asString = version
+
+    def __str__(self):
+        return self.__asString
+
+    def __repr__(self):
+        return 'Version(%s)' % `self.__asString`
+
+    def __cmp__(self, other):
+        return apt_pkg.VersionCompare(self.__asString, other.__asString)
+
+
+version_compare = apt_pkg.VersionCompare
 
 class PackageFile:
     """A Debian package file.
@@ -206,9 +133,9 @@
                     contents = "%s\n%s" % (contents, ncontents)
                 else:
                     break
-            pkg.append((name.lower(), contents))
+            pkg.append((name, contents))
         if pkg:
-            yield dict(pkg)
+            yield pkg
 
     def raiseSyntaxError(self, msg, lineno=None):
         if lineno is None:
@@ -233,7 +160,7 @@
 
 def listReleases():
     releases = {}
-    rels = ("potato", "woody", "sarge", "etch", "sid")
+    rels = ("potato", "woody", "sarge", "etch", "lenny", "sid")
     for r in range(len(rels)):
         releases[rels[r]] = Release(rels[r], r)
     Release.releases = releases



More information about the pkg-python-debian-commits mailing list