From 9d50cd36f87541222fd21ee27b49a16ea6d3a9c0 Mon Sep 17 00:00:00 2001
From: Julian Andres Klode <jak@debian.org>
Date: Mon, 1 Mar 2010 12:15:45 +0100
Subject: [PATCH 1/2] Upgrade to the new python-apt API.

---
 examples/aptxapianindex.py      |    3 ++-
 examples/axi-query-pkgtype.py   |    3 ++-
 examples/axi-query-simple.py    |    5 +++--
 examples/axi-query.py           |    3 ++-
 examples/axi-searchasyoutype.py |    5 +++--
 examples/axi-searchcloud.py     |    8 +++++++-
 plugins/apttags.py              |    2 +-
 plugins/descriptions.py         |    2 +-
 plugins/sections.py             |    2 +-
 plugins/sizes.py                |    2 +-
 10 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/examples/aptxapianindex.py b/examples/aptxapianindex.py
index 75ddfbf..a425b62 100644
--- a/examples/aptxapianindex.py
+++ b/examples/aptxapianindex.py
@@ -97,7 +97,8 @@ def show_mset(mset):
         pkg = cache[name]
 
         # Print the match, together with the short description
-        print "%i%% %s - %s" % (m[xapian.MSET_PERCENT], name, pkg.summary)
+        if pkg.candidate:
+            print "%i%% %s - %s" % (m[xapian.MSET_PERCENT], name, pkg.candidate.summary)
 
 def readValueDB(pathname):
     """
diff --git a/examples/axi-query-pkgtype.py b/examples/axi-query-pkgtype.py
index b434607..0d0c34c 100755
--- a/examples/axi-query-pkgtype.py
+++ b/examples/axi-query-pkgtype.py
@@ -101,7 +101,8 @@ for m in matches:
     # description
     pkg = cache[name]
 
+    if pkg.candidate:
     # Print the match, together with the short description
-    print "%i%% %s - %s" % (m[xapian.MSET_PERCENT], name, pkg.summary)
+        print "%i%% %s - %s" % (m[xapian.MSET_PERCENT], name, pkg.candidate.summary)
 
 sys.exit(0)
diff --git a/examples/axi-query-simple.py b/examples/axi-query-simple.py
index ce0f88f..5eb33d5 100755
--- a/examples/axi-query-simple.py
+++ b/examples/axi-query-simple.py
@@ -117,7 +117,8 @@ for m in matches:
     # description
     pkg = cache[name]
 
-    # Print the match, together with the short description
-    print "%i%% %s - %s" % (m[xapian.MSET_PERCENT], name, pkg.summary)
+    if pkg.candidate:
+        # Print the match, together with the short description
+        print "%i%% %s - %s" % (m[xapian.MSET_PERCENT], name, pkg.candidate.summary)
 
 sys.exit(0)
diff --git a/examples/axi-query.py b/examples/axi-query.py
index fb4e8bd..5b4cc08 100755
--- a/examples/axi-query.py
+++ b/examples/axi-query.py
@@ -101,6 +101,7 @@ print "Results 1-%i:" % matches.size()
 for m in matches:
     name = m[xapian.MSET_DOCUMENT].get_data()
     pkg = cache[name]
-    print "%i%% %s - %s" % (m[xapian.MSET_PERCENT], name, pkg.summary)
+    if pkg.candidate:
+        print "%i%% %s - %s" % (m[xapian.MSET_PERCENT], name, pkg.candidate.summary)
 
 sys.exit(0)
diff --git a/examples/axi-searchasyoutype.py b/examples/axi-searchasyoutype.py
index 39b61bb..3b6b1bc 100755
--- a/examples/axi-searchasyoutype.py
+++ b/examples/axi-searchasyoutype.py
@@ -152,8 +152,9 @@ class Results:
             # description
             pkg = cache[name]
 
-            # Print the match, together with the short description
-            self.win.addstr(y+1, 0, "%i%% %s - %s" % (m[xapian.MSET_PERCENT], name, pkg.summary))
+            if pkg.candidate:
+                # Print the match, together with the short description
+                self.win.addstr(y+1, 0, "%i%% %s - %s" % (m[xapian.MSET_PERCENT], name, pkg.candidate.summary))
 
         self.win.refresh()
 
diff --git a/examples/axi-searchcloud.py b/examples/axi-searchcloud.py
index 863de2c..42e0fce 100755
--- a/examples/axi-searchcloud.py
+++ b/examples/axi-searchcloud.py
@@ -132,7 +132,13 @@ def SimpleOrQuery(input_terms):
             pkg = cache[name]
         except KeyError:
             continue
-        shortdesc = pkg.summary
+
+        # pkg.candidate may be none
+        try:
+            shortdesc = pkg.candidate.summary
+        except AttributeError:
+            continue
+
         packages.append((score, name, shortdesc))
 
     class Filter(xapian.ExpandDecider):
diff --git a/plugins/apttags.py b/plugins/apttags.py
index d12e733..b8b221d 100644
--- a/plugins/apttags.py
+++ b/plugins/apttags.py
@@ -25,7 +25,7 @@ class AptTags:
         """
         self.re_expand = re.compile(r"\b([^{]+)\{([^}]+)\}")
         self.re_split = re.compile(r"\s*,\s*")
-        file = apt.apt_pkg.Config.find_file("Dir::Cache::pkgcache")
+        file = apt.apt_pkg.config.find_file("Dir::Cache::pkgcache")
         return dict(timestamp = os.path.getmtime(file))
 
     def init(self, info, progress):
diff --git a/plugins/descriptions.py b/plugins/descriptions.py
index 57d9155..6126e64 100644
--- a/plugins/descriptions.py
+++ b/plugins/descriptions.py
@@ -22,7 +22,7 @@ class Descriptions:
         the timestamp shows that this plugin is currently not needed, then the
         long initialisation can just be skipped.
         """
-        file = apt.apt_pkg.Config.find_file("Dir::Cache::pkgcache")
+        file = apt.apt_pkg.config.find_file("Dir::Cache::pkgcache")
         return dict(timestamp = os.path.getmtime(file))
 
     def init(self, info, progress):
diff --git a/plugins/sections.py b/plugins/sections.py
index 78cd02a..197efb9 100644
--- a/plugins/sections.py
+++ b/plugins/sections.py
@@ -21,7 +21,7 @@ class Sections:
         the timestamp shows that this plugin is currently not needed, then the
         long initialisation can just be skipped.
         """
-        file = apt.apt_pkg.Config.find_file("Dir::Cache::pkgcache")
+        file = apt.apt_pkg.config.find_file("Dir::Cache::pkgcache")
         return dict(timestamp = os.path.getmtime(file))
 
     def init(self, info, progress):
diff --git a/plugins/sizes.py b/plugins/sizes.py
index d0c79bb..26da747 100644
--- a/plugins/sizes.py
+++ b/plugins/sizes.py
@@ -21,7 +21,7 @@ class Sizes:
         the timestamp shows that this plugin is currently not needed, then the
         long initialisation can just be skipped.
         """
-        file = apt.apt_pkg.Config.find_file("Dir::Cache::pkgcache")
+        file = apt.apt_pkg.config.find_file("Dir::Cache::pkgcache")
         return dict(
                 timestamp = os.path.getmtime(file),
                 values = [
-- 
1.7.0

