[packagekit] packagekit: Branch 'master' - 27 commits

Richard Hughes hughsient at kemper.freedesktop.org
Wed Dec 19 13:27:50 PST 2007


 backends/apt.old/.gitignore                 |   10 
 backends/apt.old/Makefile.am                |   17 -
 backends/apt.old/helpers/.gitignore         |    2 
 backends/apt.old/helpers/Makefile.am        |   16 -
 backends/apt.old/helpers/aptBackend.py      |   55 -----
 backends/apt.old/helpers/refresh-cache.py   |   22 --
 backends/apt.old/pk-apt-build-db.cpp        |  283 ---------------------------
 backends/apt.old/pk-backend-apt.cpp         |  162 ---------------
 backends/apt.old/pk-backend-apt.h           |   30 --
 backends/apt.old/pk-python-backend-common.c |   39 ---
 backends/apt.old/pk-python-backend-common.h |   28 --
 backends/apt.old/pk-sqlite-pkg-cache.c      |  228 ----------------------
 backends/apt.old/pk-sqlite-pkg-cache.h      |   39 ---
 backends/apt/Makefile.am                    |   12 -
 backends/apt/helpers/.gitignore             |    1 
 backends/apt/helpers/aptBackend.py          |  201 +++++++++++++++++++
 backends/apt/helpers/get-depends.py         |   18 +
 backends/apt/helpers/get-repo-list.py       |   18 +
 backends/apt/helpers/get-requires.py        |   20 +
 backends/apt/pk-apt-build-db.cpp            |  284 ++++++++++++++++++++++++++++
 backends/apt/pk-apt-build-db.h              |   30 ++
 backends/apt/pk-apt-search-plain.c          |   21 --
 backends/apt/pk-apt-search-sqlite.cpp       |  135 +++++++++++++
 backends/apt/pk-apt-search.h                |    3 
 backends/apt/pk-backend-apt.c               |   14 -
 backends/apt/pk-sqlite-pkg-cache.cpp        |  253 ++++++++++++++++++++++++
 backends/apt/pk-sqlite-pkg-cache.h          |   42 ++++
 backends/yum/helpers/yumBackend.py          |    2 
 configure.ac                                |   26 +-
 python/packagekit/frontend.py               |    8 
 python/pk-frontend-test.py                  |    7 
 src/Makefile.am                             |    7 
 32 files changed, 1052 insertions(+), 981 deletions(-)

New commits:
commit 8a1df2fc678aa9162e756590be32e078c280d418
Author: Tom Parker <palfrey at tevp.net>
Date:   Wed Dec 19 18:33:49 2007 +0000

    apt: minor aptBackend cleanup

diff --git a/backends/apt/helpers/aptBackend.py b/backends/apt/helpers/aptBackend.py
index a8f737b..2501f72 100644
--- a/backends/apt/helpers/aptBackend.py
+++ b/backends/apt/helpers/aptBackend.py
@@ -75,11 +75,8 @@ class Package(object):
             if self.candidate_version != version:
                 if self._data == "":
                     for ver in pkg._pkg.VersionList:
-                        print "vers",dir(ver),version,ver
                         f, index = ver.FileList.pop(0)
-                        #print f,index
                         self._data = "%s/%s"%(f.Origin,f.Archive)
-                        #print data
                         if ver.VerStr == version:
                             break
 
commit fc672ce4f1e247577ae2b0a9c2f9bb7962a2b29c
Author: Tom Parker <palfrey at tevp.net>
Date:   Wed Dec 19 18:13:43 2007 +0000

    apt: re-add self to pk-backend-apt.c copyright

diff --git a/backends/apt/pk-backend-apt.c b/backends/apt/pk-backend-apt.c
index 054207d..0346a58 100644
--- a/backends/apt/pk-backend-apt.c
+++ b/backends/apt/pk-backend-apt.c
@@ -1,6 +1,7 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
  * Copyright (C) 2007 Ali Sabil <ali.sabil at gmail.com>
+ * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
  *
  * Licensed under the GNU General Public License Version 2
  *
commit 652fbcbcc9c4f3bd5d3fd73795520aa06803e877
Author: Tom Parker <palfrey at tevp.net>
Date:   Wed Dec 19 18:03:37 2007 +0000

    apt: Add get-repo-list
    Plus some fixes for 3rd party repos

diff --git a/backends/apt/helpers/aptBackend.py b/backends/apt/helpers/aptBackend.py
index 067ae07..a8f737b 100644
--- a/backends/apt/helpers/aptBackend.py
+++ b/backends/apt/helpers/aptBackend.py
@@ -22,7 +22,10 @@ import warnings
 warnings.filterwarnings(action='ignore', category=FutureWarning)
 import apt
 from aptsources.distro import get_distro
+from aptsources.sourceslist import SourcesList
 from sets import Set
+from os.path import join,exists
+from urlparse import urlparse
 
 _HYPHEN_PATTERN = re.compile(r'(\s|_)+')
 
@@ -44,21 +47,26 @@ class Package(object):
         wanted_ver = None
         if self.installed_version!=None and self._cmp_deps(version,self.installed_version):
             wanted_ver = self.installed_version
-        elif self.installed_version == None:
-            self._pkg.markInstall(False,False)
+        elif self.installed_version == None and version == []:
+            #self._pkg.markInstall(False,False)
             wanted_ver = self.candidate_version
 
         for ver in pkg._pkg.VersionList:
             #print "vers",dir(ver),version,ver
-            f, index = ver.FileList.pop(0)
-            #print f,index
             #print data
             if (wanted_ver == None or wanted_ver == ver.VerStr) and self._cmp_deps(version,ver.VerStr):
+                f, index = ver.FileList.pop(0)
                 if self._data == "":
-                    self._data = "%s/%s"%(f.Origin,f.Archive)
+                    if f.Origin!="" or f.Archive!="":
+                        self._data = "%s/%s"%(f.Origin,f.Archive)
+                    else:
+                        self._data = "%s/unknown"%f.Site
                 self._version = ver.VerStr
                 break
         else:
+            print "wanted",wanted_ver
+            for ver in pkg._pkg.VersionList:
+                print "vers",version,ver.VerStr
             backend.error(ERROR_INTERNAL_ERROR,"Can't find version %s for %s"%(version,self.name))
     
     def setVersion(self,version,compare="="):
@@ -367,7 +375,45 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         pkgs = Set()
         self._do_reqs(pkg,pkgs, recursive)
 
-  ### Helpers ###
+    def get_repo_list(self):
+        '''
+        Implement the {backend}-get-repo-list functionality
+        '''
+        self.allow_interrupt(True)
+        self.status(STATUS_INFO)
+        sources = SourcesList()
+        root = apt_pkg.Config.FindDir("Dir::State::Lists")
+        #print root
+        for entry in sources:
+            if entry.type!="":
+                url = entry.uri
+                #if entry.template!=None:
+                url +="/dists/"
+                url += entry.dist
+                url = url.replace("//dists","/dists")
+                #print url
+                path = join(root,"%s_Release"%(apt_pkg.URItoFileName(url)))
+                if not exists(path):
+                    #print path
+                    name = "%s/unknown"%urlparse(entry.uri)[1]
+                else:
+                    lines = file(path).readlines()
+                    origin = ""
+                    suite = ""
+                    for l in lines:
+                        if l.find("Origin: ")==0:
+                            origin = l.split(" ",1)[1].strip()
+                        elif l.find("Suite: ")==0:
+                            suite = l.split(" ",1)[1].strip()
+                    assert origin!="" and suite!=""
+                    name = "%s/%s"%(origin,suite)
+                    
+                #print entry
+                #print name
+                self.repo_detail(entry.line.strip(),name,not entry.disabled)
+                #print
+        
+    ### Helpers ###
     def _emit_package(self, package):
         id = self.get_package_id(package.name,
                 package._version,
diff --git a/backends/apt/helpers/get-repo-list.py b/backends/apt/helpers/get-repo-list.py
new file mode 100755
index 0000000..4481b7f
--- /dev/null
+++ b/backends/apt/helpers/get-repo-list.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+#
+# Licensed under the GNU General Public License Version 2
+#
+# 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+import sys
+
+from aptBackend import PackageKitAptBackend
+backend = PackageKitAptBackend(sys.argv[2:])
+backend.get_repo_list()
+backend.unLock()
+sys.exit(0)
diff --git a/backends/apt/pk-backend-apt.c b/backends/apt/pk-backend-apt.c
index a0fa0d1..054207d 100644
--- a/backends/apt/pk-backend-apt.c
+++ b/backends/apt/pk-backend-apt.c
@@ -87,7 +87,7 @@ PK_BACKEND_OPTIONS (
 	backend_search_name,			/* search_name */
 	pk_backend_python_update_package,			/* update_package */
 	pk_backend_python_update_system,			/* update_system */
-	NULL,					/* get_repo_list */
+	pk_backend_python_get_repo_list,					/* get_repo_list */
 	NULL,					/* repo_enable */
 	NULL					/* repo_set_data */
 );
commit 939214299d57bcb3e758e544f6b587e391c388f7
Author: Tom Parker <palfrey at tevp.net>
Date:   Wed Dec 19 14:59:42 2007 +0000

    apt: Fix resolution of not installed packages

diff --git a/backends/apt/helpers/aptBackend.py b/backends/apt/helpers/aptBackend.py
index b911618..067ae07 100644
--- a/backends/apt/helpers/aptBackend.py
+++ b/backends/apt/helpers/aptBackend.py
@@ -44,6 +44,9 @@ class Package(object):
         wanted_ver = None
         if self.installed_version!=None and self._cmp_deps(version,self.installed_version):
             wanted_ver = self.installed_version
+        elif self.installed_version == None:
+            self._pkg.markInstall(False,False)
+            wanted_ver = self.candidate_version
 
         for ver in pkg._pkg.VersionList:
             #print "vers",dir(ver),version,ver
@@ -53,7 +56,6 @@ class Package(object):
             if (wanted_ver == None or wanted_ver == ver.VerStr) and self._cmp_deps(version,ver.VerStr):
                 if self._data == "":
                     self._data = "%s/%s"%(f.Origin,f.Archive)
-                #print self.name,version,compare,ver.VerStr
                 self._version = ver.VerStr
                 break
         else:
@@ -310,7 +312,7 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         Implement the {backend}-resolve functionality
         '''
         self.status(STATUS_INFO)
-        pkg = Package(self._apt_cache[name], self)
+        pkg = Package(self,self._apt_cache[name])
         self._emit_package(pkg)
 
     def get_depends(self,package):
commit 90b426750ed1f150eb7a2d04a0c41212d588f145
Author: Tom Parker <palfrey at tevp.net>
Date:   Wed Dec 19 14:50:05 2007 +0000

    Apt: Adding get-requires.py might be a bright idea...

diff --git a/backends/apt/helpers/get-requires.py b/backends/apt/helpers/get-requires.py
new file mode 100755
index 0000000..e0fe567
--- /dev/null
+++ b/backends/apt/helpers/get-requires.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+#
+# Licensed under the GNU General Public License Version 2
+#
+# 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+import sys
+
+from aptBackend import PackageKitAptBackend
+package = sys.argv[1]
+recursive = sys.argv[2]
+
+backend = PackageKitAptBackend(sys.argv[1:])
+backend.get_requires(package, recursive == "True")
+sys.exit(0)
commit ceaa53fcc83da21476cc7ac196b7a66bf64fe290
Author: Tom Parker <palfrey at tevp.net>
Date:   Wed Dec 19 14:49:34 2007 +0000

    apt: Yet more backend fixes
    - Handle the other operators for dep versions (not just '=')
    - Do recursive requires

diff --git a/backends/apt/helpers/aptBackend.py b/backends/apt/helpers/aptBackend.py
index f301e55..b911618 100644
--- a/backends/apt/helpers/aptBackend.py
+++ b/backends/apt/helpers/aptBackend.py
@@ -22,21 +22,53 @@ import warnings
 warnings.filterwarnings(action='ignore', category=FutureWarning)
 import apt
 from aptsources.distro import get_distro
+from sets import Set
 
 _HYPHEN_PATTERN = re.compile(r'(\s|_)+')
 
 class Package(object):
-    def __init__(self, backend, pkg, version=None, data=None):
+    def __str__(self):
+        return "Package %s, version %s"%(self.name,self._version)
+
+    def _cmp_deps(self,deps, version):
+        for (v,c) in deps:
+            if not apt_pkg.CheckDep(version,c,v):
+                return False
+        return True
+
+    def __init__(self, backend, pkg, data="",version=[]):
         self._pkg = pkg
-        if version!=None and self.installed_version != version:
+        self._version = version
+        self._data = data
+        self._backend = backend
+        wanted_ver = None
+        if self.installed_version!=None and self._cmp_deps(version,self.installed_version):
+            wanted_ver = self.installed_version
+
+        for ver in pkg._pkg.VersionList:
+            #print "vers",dir(ver),version,ver
+            f, index = ver.FileList.pop(0)
+            #print f,index
+            #print data
+            if (wanted_ver == None or wanted_ver == ver.VerStr) and self._cmp_deps(version,ver.VerStr):
+                if self._data == "":
+                    self._data = "%s/%s"%(f.Origin,f.Archive)
+                #print self.name,version,compare,ver.VerStr
+                self._version = ver.VerStr
+                break
+        else:
+            backend.error(ERROR_INTERNAL_ERROR,"Can't find version %s for %s"%(version,self.name))
+    
+    def setVersion(self,version,compare="="):
+        if version!=None and (self.installed_version == None or not apt_pkg.CheckDep(version,compare,self.installed_version)):
             self._pkg.markInstall(False,False)
             if self.candidate_version != version:
-                if data == None:
+                if self._data == "":
                     for ver in pkg._pkg.VersionList:
-                        #print "vers",dir(ver),version,ver
+                        print "vers",dir(ver),version,ver
                         f, index = ver.FileList.pop(0)
                         #print f,index
-                        data = "%s/%s"%(f.Origin,f.Archive)
+                        self._data = "%s/%s"%(f.Origin,f.Archive)
                         #print data
                         if ver.VerStr == version:
                             break
@@ -44,20 +76,21 @@ class Package(object):
                 # FIXME: this is a nasty hack, assuming that the best way to resolve
                 # deps for non-default repos is by switching the default release.
                 # We really need a better resolver (but that's hard)
-                origin = data[data.find("/")+1:]
-                #print "origin",origin
+                assert self._data!=""
+                origin = self._data[self._data.find("/")+1:]
+                print "origin",origin
                 name = self.name
-                if not backend._caches.has_key(origin):
-                    apt_pkg.Config.Set("APT::Default-Release",origin)
-                    backend._caches[origin] = apt.Cache(PackageKitProgress(self))
+                apt_pkg.Config.Set("APT::Default-Release",origin)
+                if not self._backend._caches.has_key(origin):
+                    self._backend._caches[origin] = apt.Cache(PackageKitProgress(self))
                     print "new cache for %s"%origin
-                self._pkg = backend._caches[origin][name]
+                self._pkg = self._backend._caches[origin][name]
                 self._pkg.markInstall(False,False)
-                if self.candidate_version != version:
-                    backend.error(ERROR_INTERNAL_ERROR,
-                            "Unable to locate package version %s (only got %s)"%(version,self.candidate_version))
+                if not apt_pkg.CheckDep(self.candidate_version,compare,version):
+                    self._backend.error(ERROR_INTERNAL_ERROR,
+                            "Unable to locate package version %s (only got %s) for %s"%(version,self.candidate_version,name))
                     return
-            self._pkg.markKeep()
+                self._pkg.markKeep()
 
     @property
     def id(self):
@@ -120,7 +153,7 @@ class Package(object):
 
     @property
     def is_installed(self):
-        return self._pkg.isInstalled
+        return self._pkg.isInstalled and self.installed_version == self._version
 
     @property
     def is_upgradable(self):
@@ -287,32 +320,57 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         self.allow_interrupt(True)
         self.status(STATUS_INFO)
         name, version, arch, data = self.get_package_from_id(package)
-        pkg = Package(self._apt_cache[name], self)
+        pkg = Package(self,self._apt_cache[name],version=[(version,"=")],data=data)
+        pkg.setVersion(version)
         pkg._pkg.markInstall()
+        deps = {}
         for x in pkg._pkg.candidateDependencies:
-            self._emit_package(Package(self._apt_cache[x.or_dependencies[0].name],self))
+            n = x.or_dependencies[0].name
+            if not deps.has_key(n):
+                deps[n] = []
+            deps[n].append((x.or_dependencies[0].version,x.or_dependencies[0].relation))
+        for n in deps.keys():
+            self._emit_package(Package(self,self._apt_cache[n],version=deps[n]))
+
+    def _do_reqs(self,inp,pkgs,recursive):
+        extra = []
+        fails = []
+        for r in inp._pkg._pkg.RevDependsList:
+            ch = apt_pkg.CheckDep(inp._version,r.CompType,r.TargetVer)
+            v = (r.ParentPkg.Name,r.ParentVer.VerStr)
+            if not ch or v in fails:
+                #print "skip",r.TargetVer,r.CompType,r.ParentPkg.Name,r.ParentVer.VerStr
+                fails.append(v)
+                continue
+            p = Package(self,self._apt_cache[r.ParentPkg.Name],r.ParentVer.VerStr)
+            if v not in pkgs:
+                extra.append(p)
+                #print "new pkg",p
+                self._emit_package(p)
+            pkgs.add(v)
+        if recursive:
+            for e in extra:
+                pkgs = self._do_reqs(p, pkgs,recursive)
+        return pkgs
 
     def get_requires(self,package,recursive):
         '''
         Implement the {backend}-get-requires functionality
-        Needed to be implemented in a sub class
         '''
         self.allow_interrupt(True)
         self.status(STATUS_INFO)
         name, version, arch, data = self.get_package_from_id(package)
         pkg = Package(self,self._apt_cache[name], version, data)
 
-        for r in pkg._pkg._pkg.RevDependsList:
-            print r.ParentPkg,
-            print version,pkg._pkg._pkg.CurrentVer.VerStr,r.CompType
-            print apt_pkg.CheckDep(version,r.CompType,pkg._pkg._pkg.CurrentVer.VerStr)
+        pkgs = Set()
+        self._do_reqs(pkg,pkgs, recursive)
 
   ### Helpers ###
     def _emit_package(self, package):
         id = self.get_package_id(package.name,
-                package.installed_version or package.candidate_version,
+                package._version,
                 package.architecture,
-                "")
+                package._data)
         if package.is_installed:
             status = INFO_INSTALLED
         else:
@@ -338,7 +396,7 @@ class PackageKitAptBackend(PackageKitBaseBackend):
             if not self._do_filtering(package, filters):
                 continue
             for ver in package._pkg._pkg.VersionList:
-                yield Package(self, package._pkg, ver.VerStr)
+                yield Package(self, package._pkg, version=[[ver.VerStr,"="]])
         self.percentage(100)
 
     def _do_filtering(self, package, filters):
commit b6fdcc2e5c28db7660694f76a895a458c3466288
Author: Tom Parker <palfrey at tevp.net>
Date:   Wed Dec 19 11:45:22 2007 +0000

    apt: lots of backend work
    - Make the multiple-versioning done at a Package level
    - Initial work on getRequires
    - Yield multiple versions from searches

diff --git a/backends/apt/helpers/aptBackend.py b/backends/apt/helpers/aptBackend.py
index 8df4d1f..f301e55 100644
--- a/backends/apt/helpers/aptBackend.py
+++ b/backends/apt/helpers/aptBackend.py
@@ -21,12 +21,43 @@ import apt_pkg
 import warnings
 warnings.filterwarnings(action='ignore', category=FutureWarning)
 import apt
+from aptsources.distro import get_distro
 
 _HYPHEN_PATTERN = re.compile(r'(\s|_)+')
 
 class Package(object):
-    def __init__(self, pkg, backend):
+    def __init__(self, backend, pkg, version=None, data=None):
         self._pkg = pkg
+        if version!=None and self.installed_version != version:
+            self._pkg.markInstall(False,False)
+            if self.candidate_version != version:
+                if data == None:
+                    for ver in pkg._pkg.VersionList:
+                        #print "vers",dir(ver),version,ver
+                        f, index = ver.FileList.pop(0)
+                        #print f,index
+                        data = "%s/%s"%(f.Origin,f.Archive)
+                        #print data
+                        if ver.VerStr == version:
+                            break
+
+                # FIXME: this is a nasty hack, assuming that the best way to resolve
+                # deps for non-default repos is by switching the default release.
+                # We really need a better resolver (but that's hard)
+                origin = data[data.find("/")+1:]
+                #print "origin",origin
+                name = self.name
+                if not backend._caches.has_key(origin):
+                    apt_pkg.Config.Set("APT::Default-Release",origin)
+                    backend._caches[origin] = apt.Cache(PackageKitProgress(self))
+                    print "new cache for %s"%origin
+                self._pkg = backend._caches[origin][name]
+                self._pkg.markInstall(False,False)
+                if self.candidate_version != version:
+                    backend.error(ERROR_INTERNAL_ERROR,
+                            "Unable to locate package version %s (only got %s)"%(version,self.candidate_version))
+                    return
+            self._pkg.markKeep()
 
     @property
     def id(self):
@@ -163,7 +194,21 @@ class PackageKitAptBackend(PackageKitBaseBackend):
     def __init__(self, args):
         PackageKitBaseBackend.__init__(self, args)
         self.status(STATUS_SETUP)
+        self._caches  = {}
         self._apt_cache = apt.Cache(PackageKitProgress(self))
+        default = apt_pkg.Config.Find("APT::Default-Release")
+        if default=="":
+            d = get_distro()
+            print d.id
+            if d.id == "Debian":
+                default = "stable"
+            elif d.id == "Ubuntu":
+                default = "main"
+            else:
+                raise Exception
+
+        self._caches[default] = self._apt_cache
+            
 
     def search_name(self, filters, key):
         '''
@@ -244,27 +289,24 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         name, version, arch, data = self.get_package_from_id(package)
         pkg = Package(self._apt_cache[name], self)
         pkg._pkg.markInstall()
-        if pkg.installed_version != version:
-            pkg._pkg.markInstall()
-            if pkg.candidate_version != version:
-                if data.find("/")!=-1:
-                    # FIXME: this is a nasty hack, assuming that the best way to resolve
-                    # deps for non-default repos is by switching the default release.
-                    # We really need a better resolver (but that's hard)
-                    origin = data[data.find("/")+1:]
-                    apt_pkg.Config.Set("APT::Default-Release",origin)
-
-                    self._apt_cache.open(PackageKitProgress(self))
-                    pkg = Package(self._apt_cache[name], self)
-                    pkg._pkg.markInstall()
-                if pkg.candidate_version != version:
-                    self.error(ERROR_INTERNAL_ERROR,
-                            "Unable to determine dependencies for package version %s (only got %s)"%(version,pkg.candidate_version))
-                    return
-                
         for x in pkg._pkg.candidateDependencies:
             self._emit_package(Package(self._apt_cache[x.or_dependencies[0].name],self))
 
+    def get_requires(self,package,recursive):
+        '''
+        Implement the {backend}-get-requires functionality
+        Needed to be implemented in a sub class
+        '''
+        self.allow_interrupt(True)
+        self.status(STATUS_INFO)
+        name, version, arch, data = self.get_package_from_id(package)
+        pkg = Package(self,self._apt_cache[name], version, data)
+
+        for r in pkg._pkg._pkg.RevDependsList:
+            print r.ParentPkg,
+            print version,pkg._pkg._pkg.CurrentVer.VerStr,r.CompType
+            print apt_pkg.CheckDep(version,r.CompType,pkg._pkg._pkg.CurrentVer.VerStr)
+
   ### Helpers ###
     def _emit_package(self, package):
         id = self.get_package_id(package.name,
@@ -287,7 +329,7 @@ class PackageKitAptBackend(PackageKitBaseBackend):
             if new_percentage - percentage >= 5:
                 percentage = new_percentage
                 self.percentage(percentage)
-            package = Package(pkg, self)
+            package = Package(self, pkg)
             if package.installed_version is None and \
                     package.candidate_version is None:
                 continue
@@ -295,10 +337,10 @@ class PackageKitAptBackend(PackageKitBaseBackend):
                 continue
             if not self._do_filtering(package, filters):
                 continue
-            yield package
+            for ver in package._pkg._pkg.VersionList:
+                yield Package(self, package._pkg, ver.VerStr)
         self.percentage(100)
 
-
     def _do_filtering(self, package, filters):
         if len(filters) == 0 or filters == ['none']:
             return True
commit c9127256ac01b2a145f48f32f7aae79d5247e18b
Author: Tom Parker <palfrey at tevp.net>
Date:   Wed Dec 19 00:52:11 2007 +0100

    Output error codes from pk-frontend-test

diff --git a/python/pk-frontend-test.py b/python/pk-frontend-test.py
index 0057f21..02f5f21 100755
--- a/python/pk-frontend-test.py
+++ b/python/pk-frontend-test.py
@@ -58,6 +58,13 @@ class pkt(PackageKit):
 		print "  %s" % timespec
 		print "  %s seconds" % duration
 		print "  %s" % success
+	
+	def ErrorCode(self,
+			jid,        # Job ID
+			error_code, # enumerated - see pk-enum.c in PackageKit source
+			details     # non-localized details
+			):
+		print "Error (type is %s):"%error_code,details
 
 try:
 	p = pkt()
commit f4c689b369c48356b1fc6bd665ad94f5cb202ad6
Author: Tom Parker <palfrey at tevp.net>
Date:   Wed Dec 19 00:48:41 2007 +0100

    apt: Fix dep handling for installed packages

diff --git a/backends/apt/helpers/aptBackend.py b/backends/apt/helpers/aptBackend.py
index 1db4b61..8df4d1f 100644
--- a/backends/apt/helpers/aptBackend.py
+++ b/backends/apt/helpers/aptBackend.py
@@ -244,24 +244,26 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         name, version, arch, data = self.get_package_from_id(package)
         pkg = Package(self._apt_cache[name], self)
         pkg._pkg.markInstall()
-        if pkg.candidate_version != version:
-            if data.find("/")!=-1:
-                # FIXME: this is a nasty hack, assuming that the best way to resolve
-                # deps for non-default repos is by switching the default release.
-                # We really need a better resolver (but that's hard)
-                origin = data[data.find("/")+1:]
-                apt_pkg.Config.Set("APT::Default-Release",origin)
-
-                self._apt_cache.open(PackageKitProgress(self))
-                pkg = Package(self._apt_cache[name], self)
-                pkg._pkg.markInstall()
+        if pkg.installed_version != version:
+            pkg._pkg.markInstall()
             if pkg.candidate_version != version:
-                self.error(ERROR_INTERNAL_ERROR,
-                        "Unable to determine dependencies for package version %s (only got %s)"%(version,pkg.candidate_version))
-                return
-            
-        for x in self._apt_cache.getChanges():
-            self._emit_package(Package(x,self))
+                if data.find("/")!=-1:
+                    # FIXME: this is a nasty hack, assuming that the best way to resolve
+                    # deps for non-default repos is by switching the default release.
+                    # We really need a better resolver (but that's hard)
+                    origin = data[data.find("/")+1:]
+                    apt_pkg.Config.Set("APT::Default-Release",origin)
+
+                    self._apt_cache.open(PackageKitProgress(self))
+                    pkg = Package(self._apt_cache[name], self)
+                    pkg._pkg.markInstall()
+                if pkg.candidate_version != version:
+                    self.error(ERROR_INTERNAL_ERROR,
+                            "Unable to determine dependencies for package version %s (only got %s)"%(version,pkg.candidate_version))
+                    return
+                
+        for x in pkg._pkg.candidateDependencies:
+            self._emit_package(Package(self._apt_cache[x.or_dependencies[0].name],self))
 
   ### Helpers ###
     def _emit_package(self, package):
commit 5a46b9dfcf40585829ffe6b99ec4aeb208eb9ecd
Author: Tom Parker <palfrey at tevp.net>
Date:   Tue Dec 18 23:53:33 2007 +0100

    apt: Reduce whining about lack of status messages

diff --git a/backends/apt/helpers/aptBackend.py b/backends/apt/helpers/aptBackend.py
index bf5120d..1db4b61 100644
--- a/backends/apt/helpers/aptBackend.py
+++ b/backends/apt/helpers/aptBackend.py
@@ -162,12 +162,14 @@ class PackageKitProgress(apt.progress.OpProgress, apt.progress.FetchProgress):
 class PackageKitAptBackend(PackageKitBaseBackend):
     def __init__(self, args):
         PackageKitBaseBackend.__init__(self, args)
+        self.status(STATUS_SETUP)
         self._apt_cache = apt.Cache(PackageKitProgress(self))
 
     def search_name(self, filters, key):
         '''
         Implement the {backend}-search-name functionality
         '''
+        self.status(STATUS_INFO)
         self.allow_interrupt(True)
         for package in self._do_search(filters,
                 lambda pkg: pkg.match_name(key)):
@@ -177,6 +179,7 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-search-details functionality
         '''
+        self.status(STATUS_INFO)
         self.allow_interrupt(True)
         for package in self._do_search(filters,
                 lambda pkg: pkg.match_details(key)):
@@ -186,6 +189,7 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-search-group functionality
         '''
+        self.status(STATUS_INFO)
         self.allow_interrupt(True)
         for package in self._do_search(filters,
                 lambda pkg: pkg.match_group(key)):
@@ -205,6 +209,7 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-refresh_cache functionality
         '''
+        self.status(STATUS_REFRESH_CACHE)
         try:
             res = self._apt_cache.update(PackageKitProgress(self))
         except Exception, error_message:
@@ -216,6 +221,7 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-get-description functionality
         '''
+        self.status(STATUS_INFO)
         name, version, arch, data = self.get_package_from_id(package)
         pkg = Package(self._apt_cache[name], self)
         description = re.sub('\s+', ' ', pkg.description).strip()
@@ -225,6 +231,7 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-resolve functionality
         '''
+        self.status(STATUS_INFO)
         pkg = Package(self._apt_cache[name], self)
         self._emit_package(pkg)
 
@@ -232,15 +239,17 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-get-depends functionality
         '''
+        self.allow_interrupt(True)
+        self.status(STATUS_INFO)
         name, version, arch, data = self.get_package_from_id(package)
         pkg = Package(self._apt_cache[name], self)
         pkg._pkg.markInstall()
         if pkg.candidate_version != version:
             if data.find("/")!=-1:
                 # FIXME: this is a nasty hack, assuming that the best way to resolve
-				# deps for non-default repos is by switching the default release.
-				# We really need a better resolver (but that's hard)
-				origin = data[data.find("/")+1:]
+                # deps for non-default repos is by switching the default release.
+                # We really need a better resolver (but that's hard)
+                origin = data[data.find("/")+1:]
                 apt_pkg.Config.Set("APT::Default-Release",origin)
 
                 self._apt_cache.open(PackageKitProgress(self))
commit 47f8e666720b74b10f40f1db421b33685469414c
Author: Tom Parker <palfrey at tevp.net>
Date:   Tue Dec 18 23:49:41 2007 +0100

    apt: Add get_depends
    There's a nasty hack in here currently, working around the multiple-repo
    dependency issues by assuming that the repo containing a particular
    version of a program is the right place to look for its other
    dependencies. We really need a better dependency checker, but this is
    a difficult problem.

diff --git a/backends/apt/helpers/aptBackend.py b/backends/apt/helpers/aptBackend.py
index aa084a9..bf5120d 100644
--- a/backends/apt/helpers/aptBackend.py
+++ b/backends/apt/helpers/aptBackend.py
@@ -234,21 +234,25 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         '''
         name, version, arch, data = self.get_package_from_id(package)
         pkg = Package(self._apt_cache[name], self)
-        print pkg._pkg._pkg.VersionList
-        print "ok",self._apt_cache._depcache.SetCandidateVer(pkg._pkg._pkg,pkg._pkg._pkg.VersionList[0])
-        print self._apt_cache._depcache.GetCandidateVer(pkg._pkg._pkg),pkg._pkg._pkg.VersionList[0]
-        print "mi",pkg._pkg.markInstall(autoFix=False)
-        print pkg._pkg._pkg.VersionList
-        print "other",self._apt_cache._depcache.SetCandidateVer(pkg._pkg._pkg,pkg._pkg._pkg.VersionList[0])
-        print self._apt_cache._depcache.GetCandidateVer(pkg._pkg._pkg),pkg._pkg._pkg.VersionList[0]
-        print pkg.candidate_version
-        for d in pkg._pkg.candidateDependencies:
-            for o in d.or_dependencies:
-                dep = Package(self._apt_cache[o.name],self)
-        print "changes"
+        pkg._pkg.markInstall()
+        if pkg.candidate_version != version:
+            if data.find("/")!=-1:
+                # FIXME: this is a nasty hack, assuming that the best way to resolve
+				# deps for non-default repos is by switching the default release.
+				# We really need a better resolver (but that's hard)
+				origin = data[data.find("/")+1:]
+                apt_pkg.Config.Set("APT::Default-Release",origin)
+
+                self._apt_cache.open(PackageKitProgress(self))
+                pkg = Package(self._apt_cache[name], self)
+                pkg._pkg.markInstall()
+            if pkg.candidate_version != version:
+                self.error(ERROR_INTERNAL_ERROR,
+                        "Unable to determine dependencies for package version %s (only got %s)"%(version,pkg.candidate_version))
+                return
+            
         for x in self._apt_cache.getChanges():
-            print x.name,x.candidateVersion
-        raise Exception
+            self._emit_package(Package(x,self))
 
   ### Helpers ###
     def _emit_package(self, package):
diff --git a/backends/apt/pk-backend-apt.c b/backends/apt/pk-backend-apt.c
index bb78d0c..a0fa0d1 100644
--- a/backends/apt/pk-backend-apt.c
+++ b/backends/apt/pk-backend-apt.c
@@ -69,7 +69,7 @@ PK_BACKEND_OPTIONS (
 	backend_get_groups,			/* get_groups */
 	backend_get_filters,			/* get_filters */
 	NULL,					/* cancel */
-	NULL,					/* get_depends */
+	pk_backend_python_get_depends,					/* get_depends */
 	backend_get_description,		/* get_description */
 	NULL,					/* get_files */
 	NULL,					/* get_requires */
commit 2ec789f95b33cbc1ecb2c330803de5c3933f5c78
Author: Tom Parker <palfrey at tevp.net>
Date:   Tue Dec 18 22:23:22 2007 +0100

    apt: sqlite searching should do finish, and also can't use thread_helper
    anymore

diff --git a/backends/apt/pk-sqlite-pkg-cache.cpp b/backends/apt/pk-sqlite-pkg-cache.cpp
index dc8c435..d7c61df 100644
--- a/backends/apt/pk-sqlite-pkg-cache.cpp
+++ b/backends/apt/pk-sqlite-pkg-cache.cpp
@@ -145,6 +145,7 @@ sqlite_search_packages_thread (PkBackend *backend, gpointer data)
 	g_free(st->search);
 	g_free(st);
 
+	pk_backend_finished (backend);
 	return TRUE;
 }
 
@@ -166,7 +167,7 @@ backend_search_common(PkBackend * backend, const gchar * filter, const gchar * s
 		data->search = g_strdup(search);
 		data->filter = g_strdup(filter);
 		data->depth = which;
-		pk_backend_thread_helper (backend, func, data);
+		pk_backend_thread_create (backend, func, data);
 	}
 }
 
@@ -245,7 +246,7 @@ sqlite_get_description (PkBackend *backend, const gchar *package_id)
 		return;
 	}
 
-	pk_backend_thread_helper (backend, sqlite_get_description_thread, data);
+	pk_backend_thread_create (backend, sqlite_get_description_thread, data);
 	return;
 }
 
commit 7a8fb6cc9332498c4c40c85af97a8215d77bd38f
Author: Tom Parker <palfrey at tevp.net>
Date:   Tue Dec 18 22:22:44 2007 +0100

    Make apt plain searching use the pk_backend_python* functions

diff --git a/backends/apt/pk-apt-search-plain.c b/backends/apt/pk-apt-search-plain.c
index 08683f4..155fdb8 100644
--- a/backends/apt/pk-apt-search-plain.c
+++ b/backends/apt/pk-apt-search-plain.c
@@ -23,6 +23,7 @@
 #include <glib.h>
 #include <string.h>
 #include <pk-backend.h>
+#include <pk-backend-python.h>
 
 /**
  * backend_get_groups:
@@ -65,9 +66,7 @@ backend_get_filters (PkBackend *backend, PkEnumList *elist)
 void
 backend_get_description (PkBackend *backend, const gchar *package_id)
 {
-	g_return_if_fail (backend != NULL);
-	pk_backend_allow_interrupt (backend, TRUE);
-	pk_backend_spawn_helper (backend, "get-description.py", package_id, NULL);
+	pk_backend_python_get_description(backend,package_id);
 }
 
 /**
@@ -77,9 +76,7 @@ backend_get_description (PkBackend *backend, const gchar *package_id)
 void
 backend_search_details (PkBackend *backend, const gchar *filter, const gchar *search)
 {
-	g_return_if_fail (backend != NULL);
-	pk_backend_allow_interrupt (backend, TRUE);
-	pk_backend_spawn_helper (backend, "search-details.py", filter, search, NULL);
+	pk_backend_python_search_details(backend,filter,search);
 }
 
 /**
@@ -88,9 +85,7 @@ backend_search_details (PkBackend *backend, const gchar *filter, const gchar *se
 void
 backend_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
 {
-	g_return_if_fail (backend != NULL);
-	pk_backend_allow_interrupt (backend, TRUE);
-	pk_backend_spawn_helper (backend, "search-name.py", filter, search, NULL);
+	pk_backend_python_search_name(backend,filter,search);
 }
 
 /**
@@ -99,9 +94,7 @@ backend_search_name (PkBackend *backend, const gchar *filter, const gchar *searc
 void
 backend_search_group (PkBackend *backend, const gchar *filter, const gchar *search)
 {
-	g_return_if_fail (backend != NULL);
-	pk_backend_allow_interrupt (backend, TRUE);
-	pk_backend_spawn_helper (backend, "search-group.py", filter, search, NULL);
+	pk_backend_python_search_group(backend,filter,search);
 }
 
 /* don't need to do any setup/finalize in the plain search mode */
commit 98112c8e770fef9264b25096536e8b1e86d23544
Author: Tom Parker <palfrey at tevp.net>
Date:   Tue Dec 18 22:09:37 2007 +0100

    Fix python frontend GetDepends

diff --git a/python/packagekit/frontend.py b/python/packagekit/frontend.py
index 6b861f0..ddeccb6 100644
--- a/python/packagekit/frontend.py
+++ b/python/packagekit/frontend.py
@@ -291,12 +291,12 @@ class PackageKit:
 
 	@dbusException
 	@job_id
-	def GetDepends(self,package_id):
+	def GetDepends(self,package_id,recursive=False):
 		"""
 		Lists package dependancies?
 		(description is a guess, since this doesn't seem to work for me)
 		"""
-		return self.pk_iface.GetDepends(self.tid(),package_id)
+		return self.pk_iface.GetDepends(self.tid(),package_id,recursive)
 
 	@dbusException
 	@job_id
commit 6519ab6053df25953349b95c6c7db08499cd7bc6
Author: Tom Parker <palfrey at tevp.net>
Date:   Tue Dec 18 22:04:25 2007 +0100

    PackageKitExceptions now include the original DBusException

diff --git a/python/packagekit/frontend.py b/python/packagekit/frontend.py
index 2647fd7..6b861f0 100644
--- a/python/packagekit/frontend.py
+++ b/python/packagekit/frontend.py
@@ -64,9 +64,9 @@ class PackageKit:
 				return func(*args,**kwargs)
 			except dbus.exceptions.DBusException,e:
 				if e.get_dbus_name() == "org.freedesktop.DBus.Error.AccessDenied":
-					raise PackageKitAccessDenied
+					raise PackageKitAccessDenied(e)
 				elif e.get_dbus_name() == "org.freedesktop.DBus.Error.NoReply":
-					raise PackageKitBackendFailure
+					raise PackageKitBackendFailure(e)
 				else:
 					raise PackageKitException(e)
 		return wrapper
commit 0a530141312d3ff410c046930a64e02c977b7e89
Author: Tom Parker <palfrey at tevp.net>
Date:   Tue Dec 18 21:47:50 2007 +0100

    Do security defines with integers, not strings

diff --git a/configure.ac b/configure.ac
index c62c3aa..5c9e8da 100755
--- a/configure.ac
+++ b/configure.ac
@@ -251,9 +251,9 @@ if test x$with_security_framework = xpolkit; then
 	if test -z "$POLKIT_POLICY_FILE_VALIDATE"; then
 	   AC_MSG_ERROR([polkit-policy-file-validate not found])
 	fi
-	AC_DEFINE(USE_SECURITY_POLKIT, "polkit", [if we should use PolicyKit])
+	AC_DEFINE(USE_SECURITY_POLKIT, 1, [if we should use PolicyKit])
 elif test x$with_security_framework = xdummy; then
-	AC_DEFINE(USE_SECURITY_DUMMY, "dummy", [if we should use a dummy security framework])
+	AC_DEFINE(USE_SECURITY_DUMMY, 1, [if we should use a dummy security framework])
 fi
 
 AM_CONDITIONAL(SECURITY_TYPE_DUMMY, [test x$with_security_framework = xdummy], [using dummy security framework])
commit 2f5ac2b038ba27443b8c68a85966f7218dbbe173
Author: Tom Parker <palfrey at tevp.net>
Date:   Mon Dec 17 22:11:50 2007 +0100

    Ignore apt *.pyc's

diff --git a/backends/apt/helpers/.gitignore b/backends/apt/helpers/.gitignore
new file mode 100644
index 0000000..0d20b64
--- /dev/null
+++ b/backends/apt/helpers/.gitignore
@@ -0,0 +1 @@
+*.pyc
commit 380f0d4bc35c3cb761c8b1fca01f7a61f5c4cbb1
Author: Tom Parker <palfrey at tevp.net>
Date:   Tue Dec 4 13:06:55 2007 +0100

    More random getdepds stuff

diff --git a/backends/apt/helpers/aptBackend.py b/backends/apt/helpers/aptBackend.py
index ce50f8d..aa084a9 100644
--- a/backends/apt/helpers/aptBackend.py
+++ b/backends/apt/helpers/aptBackend.py
@@ -234,11 +234,20 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         '''
         name, version, arch, data = self.get_package_from_id(package)
         pkg = Package(self._apt_cache[name], self)
-        print dir(pkg._depcache)
-        print dir(pkg._pkg)
-        print pkg._pkg.VersionList
-        pkg._depcache.SetCandidateVer(pkg._pkg,pkg._pkg.VersionList[0])
-        print pkg._depcache.getChanges()
+        print pkg._pkg._pkg.VersionList
+        print "ok",self._apt_cache._depcache.SetCandidateVer(pkg._pkg._pkg,pkg._pkg._pkg.VersionList[0])
+        print self._apt_cache._depcache.GetCandidateVer(pkg._pkg._pkg),pkg._pkg._pkg.VersionList[0]
+        print "mi",pkg._pkg.markInstall(autoFix=False)
+        print pkg._pkg._pkg.VersionList
+        print "other",self._apt_cache._depcache.SetCandidateVer(pkg._pkg._pkg,pkg._pkg._pkg.VersionList[0])
+        print self._apt_cache._depcache.GetCandidateVer(pkg._pkg._pkg),pkg._pkg._pkg.VersionList[0]
+        print pkg.candidate_version
+        for d in pkg._pkg.candidateDependencies:
+            for o in d.or_dependencies:
+                dep = Package(self._apt_cache[o.name],self)
+        print "changes"
+        for x in self._apt_cache.getChanges():
+            print x.name,x.candidateVersion
         raise Exception
 
   ### Helpers ###
commit 71bbfd26713d1de57ad22b78924265fa0e285e08
Author: Tom Parker <palfrey at tevp.net>
Date:   Tue Dec 4 12:11:00 2007 +0100

    Make minor changes for get_depends

diff --git a/backends/apt/helpers/aptBackend.py b/backends/apt/helpers/aptBackend.py
index 7a31786..ce50f8d 100644
--- a/backends/apt/helpers/aptBackend.py
+++ b/backends/apt/helpers/aptBackend.py
@@ -234,8 +234,11 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         '''
         name, version, arch, data = self.get_package_from_id(package)
         pkg = Package(self._apt_cache[name], self)
-        print dir(pkg)
         print dir(pkg._depcache)
+        print dir(pkg._pkg)
+        print pkg._pkg.VersionList
+        pkg._depcache.SetCandidateVer(pkg._pkg,pkg._pkg.VersionList[0])
+        print pkg._depcache.getChanges()
         raise Exception
 
   ### Helpers ###
commit 57d99ca4c60aaab8e75d65b9add289b3f3070cec
Author: Tom Parker <palfrey at tevp.net>
Date:   Mon Nov 26 18:20:05 2007 +0000

    Change apt output on configure to note searching type

diff --git a/configure.ac b/configure.ac
index f612e52..c62c3aa 100755
--- a/configure.ac
+++ b/configure.ac
@@ -453,6 +453,10 @@ AM_CONDITIONAL(BACKEND_TYPE_SMART, [test x$with_default_backend = xsmart], [usin
 AM_CONDITIONAL(BACKEND_TYPE_PISI, [test x$with_default_backend = xpisi], [using PiSi backend])
 AM_CONDITIONAL(BACKEND_TYPE_ZYPP, [test x$with_default_backend = xzypp], [using Zypp backend])
 
+if test x$with_default_backend = xapt; then
+	# now we've done the conditionals, rename for searching backend
+	with_default_backend="apt (with $with_apt_search searching)"
+fi
 
 dnl ---------------------------------------------------------------------------
 dnl - Makefiles, etc.
commit c2ee3b9976c92fe714016bd2155b288fccf64e6c
Author: Tom Parker <palfrey at tevp.net>
Date:   Thu Nov 22 13:47:21 2007 +0100

    Add search type to apt description + me to authors list

diff --git a/backends/apt/pk-backend-apt.c b/backends/apt/pk-backend-apt.c
index 660c81a..bb78d0c 100644
--- a/backends/apt/pk-backend-apt.c
+++ b/backends/apt/pk-backend-apt.c
@@ -25,6 +25,7 @@
 #include <pk-backend.h>
 #include <pk-backend-python.h>
 #include "pk-apt-search.h"
+#include "config.h"
 
 /**
  * backend_get_groups:
@@ -61,8 +62,8 @@ backend_get_filters (PkBackend *backend, PkEnumList *elist)
 }
 
 PK_BACKEND_OPTIONS (
-	"Apt",				/* description */
-	"Ali Sabil <ali.sabil at gmail.com>",	/* author */
+	"Apt (with " APT_SEARCH " searching)",				/* description */
+	"Ali Sabil <ali.sabil at gmail.com>; Tom Parker <palfrey at tevp.net>",	/* author */
 	backend_init_search,					/* initalize */
 	backend_finish_search,					/* destroy */
 	backend_get_groups,			/* get_groups */
commit c979f8759b40930e1a1883b1edc62a97a1bdf16c
Author: Tom Parker <palfrey at tevp.net>
Date:   Mon Nov 19 18:15:25 2007 +0100

    Add finalize methods to apt search stuff
    Also, add initializer stub to plain search.

diff --git a/backends/apt/pk-apt-search-plain.c b/backends/apt/pk-apt-search-plain.c
index 9eec5fe..08683f4 100644
--- a/backends/apt/pk-apt-search-plain.c
+++ b/backends/apt/pk-apt-search-plain.c
@@ -103,3 +103,7 @@ backend_search_group (PkBackend *backend, const gchar *filter, const gchar *sear
 	pk_backend_allow_interrupt (backend, TRUE);
 	pk_backend_spawn_helper (backend, "search-group.py", filter, search, NULL);
 }
+
+/* don't need to do any setup/finalize in the plain search mode */
+void backend_init_search(PkBackend *backend) {}
+void backend_finish_search(PkBackend *backend) {}
diff --git a/backends/apt/pk-apt-search-sqlite.cpp b/backends/apt/pk-apt-search-sqlite.cpp
index ac3c83f..f921861 100644
--- a/backends/apt/pk-apt-search-sqlite.cpp
+++ b/backends/apt/pk-apt-search-sqlite.cpp
@@ -128,3 +128,8 @@ extern "C" void backend_init_search(PkBackend *backend)
 		inited = TRUE;
 	}
 }
+
+extern "C" void backend_finish_search(PkBackend *backend)
+{
+	sqlite_finish_cache(backend);
+}
diff --git a/backends/apt/pk-apt-search.h b/backends/apt/pk-apt-search.h
index 645e03d..02ed3c8 100644
--- a/backends/apt/pk-apt-search.h
+++ b/backends/apt/pk-apt-search.h
@@ -26,6 +26,7 @@
 #include <pk-backend.h>
 
 void backend_init_search(PkBackend *backend);
+void backend_finish_search(PkBackend *backend);
 
 void backend_get_description (PkBackend *backend, const gchar *package_id);
 void backend_search_details (PkBackend *backend, const gchar *filter, const gchar *search);
diff --git a/backends/apt/pk-backend-apt.c b/backends/apt/pk-backend-apt.c
index 191f756..660c81a 100644
--- a/backends/apt/pk-backend-apt.c
+++ b/backends/apt/pk-backend-apt.c
@@ -64,7 +64,7 @@ PK_BACKEND_OPTIONS (
 	"Apt",				/* description */
 	"Ali Sabil <ali.sabil at gmail.com>",	/* author */
 	backend_init_search,					/* initalize */
-	NULL,					/* destroy */
+	backend_finish_search,					/* destroy */
 	backend_get_groups,			/* get_groups */
 	backend_get_filters,			/* get_filters */
 	NULL,					/* cancel */
diff --git a/backends/apt/pk-sqlite-pkg-cache.cpp b/backends/apt/pk-sqlite-pkg-cache.cpp
index 55e4bfa..dc8c435 100644
--- a/backends/apt/pk-sqlite-pkg-cache.cpp
+++ b/backends/apt/pk-sqlite-pkg-cache.cpp
@@ -75,6 +75,13 @@ sqlite_init_cache(PkBackend *backend, const char* dbname, const char *compare_fn
 	sqlite3_exec(db,"insert into params values ('build_complete',1)", NULL, NULL, NULL);
 }
 
+
+void sqlite_finish_cache(PkBackend *backend)
+{
+	sqlite3_close(db);
+}
+
+
 // sqlite_search_packages_thread
 static gboolean
 sqlite_search_packages_thread (PkBackend *backend, gpointer data)
diff --git a/backends/apt/pk-sqlite-pkg-cache.h b/backends/apt/pk-sqlite-pkg-cache.h
index e568411..e9a77a2 100644
--- a/backends/apt/pk-sqlite-pkg-cache.h
+++ b/backends/apt/pk-sqlite-pkg-cache.h
@@ -32,6 +32,8 @@ typedef enum {
 #include <sqlite3.h>
 
 void sqlite_init_cache(PkBackend *backend, const char* dbname, const char* compare_fname, void (*build_db)(PkBackend *, sqlite3 *db));
+void sqlite_finish_cache(PkBackend *backend);
+
 void sqlite_search_details (PkBackend *backend, const gchar *filter, const gchar *search);
 void sqlite_search_name (PkBackend *backend, const gchar *filter, const gchar *search);
 void backend_search_common(PkBackend * backend, const gchar * filter, const gchar * search, SearchDepth which, PkBackendThreadFunc func);
commit 96f488bb83dbe3d5174ad66814c208563e9f22a7
Author: Tom Parker <palfrey at tevp.net>
Date:   Mon Nov 19 16:55:21 2007 +0100

    Fully re-integrate sqlite search backend for apt
    We've now reintegrated everything from apt.old,
    so we're dropping that at the same time

diff --git a/backends/apt.old/.gitignore b/backends/apt.old/.gitignore
deleted file mode 100644
index c851833..0000000
--- a/backends/apt.old/.gitignore
+++ /dev/null
@@ -1,10 +0,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-*.loT
-*.o
-*~
-
diff --git a/backends/apt.old/Makefile.am b/backends/apt.old/Makefile.am
deleted file mode 100644
index a4126a0..0000000
--- a/backends/apt.old/Makefile.am
+++ /dev/null
@@ -1,17 +0,0 @@
-SUBDIRS = helpers
-plugindir = @PK_PLUGIN_DIR@
-plugin_LTLIBRARIES = libpk_backend_apt.la
-libpk_backend_apt_la_INCLUDES = $(APT_CFLAGS) $(SQLITE_CFLAGS)
-libpk_backend_apt_la_SOURCES =		\
-	pk-backend-apt.h		\
-	pk-backend-apt.cpp		\
-	pk-sqlite-pkg-cache.h		\
-	pk-sqlite-pkg-cache.c		\
-	pk-apt-build-db.cpp		\
-	pk-python-backend-common.h		\
-	pk-python-backend-common.c
-libpk_backend_apt_la_LIBADD = @PK_PLUGIN_LIBS@ $(APT_LIBS) $(SQLITE_LIBS)
-libpk_backend_apt_la_LDFLAGS = -module -avoid-version
-libpk_backend_apt_la_CFLAGS = @PK_PLUGIN_CFLAGS@ -DDATABASEDIR=\""$(PK_DB_DIR)"\"
-libpk_backend_apt_la_CXXFLAGS = @PK_PLUGIN_CFLAGS@ -DDATABASEDIR=\""$(PK_DB_DIR)"\"
-
diff --git a/backends/apt.old/pk-apt-build-db.cpp b/backends/apt.old/pk-apt-build-db.cpp
deleted file mode 100644
index 894b70b..0000000
--- a/backends/apt.old/pk-apt-build-db.cpp
+++ /dev/null
@@ -1,283 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include "pk-backend-apt.h"
-#include <apt-pkg/configuration.h>
-#include <sqlite3.h>
-
-typedef enum {FIELD_PKG=1,FIELD_VER,FIELD_DEPS,FIELD_ARCH,FIELD_SHORT,FIELD_LONG,FIELD_REPO} Fields;
-
-void apt_build_db(PkBackend * backend, sqlite3 *db)
-{
-	GMatchInfo *match_info;
-	GError *error = NULL;
-	gchar *contents = NULL;
-	gchar *sdir;
-	const gchar *fname;
-	GRegex *origin, *suite;
-	GDir *dir;
-	GHashTable *releases;
-	int res;
-	sqlite3_stmt *package = NULL;
-
-	pk_backend_change_status(backend, PK_STATUS_ENUM_QUERY);
-	pk_backend_no_percentage_updates(backend);
-
-	sdir = g_build_filename(_config->Find("Dir").c_str(),_config->Find("Dir::State").c_str(),_config->Find("Dir::State::lists").c_str(), NULL);
-	dir = g_dir_open(sdir,0,&error);
-	if (error!=NULL)
-	{
-		pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "can't open %s",dir);
-		g_error_free(error);
-		goto search_task_cleanup;
-	}
-
-	origin = g_regex_new("^Origin: (\\S+)",(GRegexCompileFlags)(G_REGEX_CASELESS|G_REGEX_OPTIMIZE|G_REGEX_MULTILINE),(GRegexMatchFlags)0,NULL);
-	suite = g_regex_new("^Suite: (\\S+)",(GRegexCompileFlags)(G_REGEX_CASELESS|G_REGEX_OPTIMIZE|G_REGEX_MULTILINE),(GRegexMatchFlags)0,NULL);
-
-	releases = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
-	while ((fname = g_dir_read_name(dir))!=NULL)
-	{
-		gchar *temp, *parsed_name;
-		gchar** items = g_strsplit(fname,"_",-1);
-		guint len = g_strv_length(items);
-		if(len<=3) // minimum is <source>_<type>_<group>
-		{
-			g_strfreev(items);
-			continue;
-		}
-
-		/* warning: nasty hack with g_strjoinv */
-		temp = items[len-2];
-		items[len-2] = NULL;
-		parsed_name = g_strjoinv("_",items);
-		items[len-2] = temp;
-
-		if (g_ascii_strcasecmp(items[len-1],"Release")==0 && g_ascii_strcasecmp(items[len-2],"source")!=0)
-		{
-			gchar * repo = NULL, *fullname;
-			fullname = g_build_filename(sdir,fname,NULL);
-			if (g_file_get_contents(fullname,&contents,NULL,NULL) == FALSE)
-			{
-				pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "error loading %s",fullname);
-				goto search_task_cleanup;
-			}
-			g_free(fullname);
-
-			g_regex_match (origin, contents, (GRegexMatchFlags)0, &match_info);
-			if (!g_match_info_matches(match_info))
-			{
-				pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "origin regex failure in %s",fname);
-				goto search_task_cleanup;
-			}
-			repo = g_match_info_fetch (match_info, 1);
-
-			g_regex_match (suite, contents, (GRegexMatchFlags)0, &match_info);
-			if (g_match_info_matches(match_info))
-			{
-				temp = g_strconcat(repo,"/",g_match_info_fetch (match_info, 1),NULL);
-				g_free(repo);
-				repo = temp;
-			}
-
-			temp = parsed_name;
-			parsed_name = g_strconcat(temp,"_",items[len-2],NULL);
-			g_free(temp);
-
-			pk_debug("type is %s, group is %s, parsed_name is %s",items[len-2],items[len-1],parsed_name);
-
-			g_hash_table_insert(releases, parsed_name, repo);
-			g_free(contents);
-			contents = NULL;
-		}
-		else
-			g_free(parsed_name);
-		g_strfreev(items);
-	}
-	g_dir_close(dir);
-
-	/* and then we need to do this again, but this time we're looking for the packages */
-	dir = g_dir_open(sdir,0,&error);
-	res = sqlite3_prepare_v2(db, "insert or replace into packages values (?,?,?,?,?,?,?)", -1, &package, NULL);
-	if (res!=SQLITE_OK)
-		pk_error("sqlite error during insert prepare: %s", sqlite3_errmsg(db));
-	else
-		pk_debug("insert prepare ok for %p",package);
-	while ((fname = g_dir_read_name(dir))!=NULL)
-	{
-		gchar** items = g_strsplit(fname,"_",-1);
-		guint len = g_strv_length(items);
-		if(len<=3) // minimum is <source>_<type>_<group>
-		{
-			g_strfreev(items);
-			continue;
-		}
-
-		if (g_ascii_strcasecmp(items[len-1],"Packages")==0)
-		{
-			const gchar *repo;
-			gchar *temp=NULL, *parsed_name=NULL;
-			gchar *fullname= NULL;
-			gchar *begin=NULL, *next=NULL, *description = NULL;
-			glong count = 0;
-			gboolean haspk = FALSE;
-
-			/* warning: nasty hack with g_strjoinv */
-			if (g_str_has_prefix(items[len-2],"binary-"))
-			{
-				temp = items[len-3];
-				items[len-3] = NULL;
-				parsed_name = g_strjoinv("_",items);
-				items[len-3] = temp;
-			}
-			else
-			{
-				temp = items[len-1];
-				items[len-1] = NULL;
-				parsed_name = g_strjoinv("_",items);
-				items[len-1] = temp;
-			}
-
-			pk_debug("type is %s, group is %s, parsed_name is %s",items[len-2],items[len-1],parsed_name);
-
-			repo = (const gchar *)g_hash_table_lookup(releases,parsed_name);
-			if (repo == NULL)
-			{
-				pk_debug("Can't find repo for %s, marking as \"unknown\"",parsed_name);
-				repo = g_strdup("unknown");
-				//g_assert(0);
-			}
-			else
-				pk_debug("repo for %s is %s",parsed_name,repo);
-			g_free(parsed_name);
-
-			fullname = g_build_filename(sdir,fname,NULL);
-			pk_debug("loading %s",fullname);
-			if (g_file_get_contents(fullname,&contents,NULL,NULL) == FALSE)
-			{
-				pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "error loading %s",fullname);
-				goto search_task_cleanup;
-			}
-			/*else
-				pk_debug("loaded");*/
-
-			res = sqlite3_bind_text(package,FIELD_REPO,repo,-1,SQLITE_TRANSIENT);
-			if (res!=SQLITE_OK)
-				pk_error("sqlite error during repo bind: %s", sqlite3_errmsg(db));
-			/*else
-				pk_debug("repo bind ok");*/
-
-			res = sqlite3_exec(db,"begin",NULL,NULL,NULL);
-			g_assert(res == SQLITE_OK);
-
-			begin = contents;
-
-			while (true)
-			{
-				next = strstr(begin,"\n");
-				if (next!=NULL)
-				{
-					next[0] = '\0';
-					next++;
-				}
-
-				if (begin[0]=='\0')
-				{
-					if (haspk)
-					{
-						if (description!=NULL)
-						{
-							res=sqlite3_bind_text(package,FIELD_LONG,description,-1,SQLITE_TRANSIENT);
-							if (res!=SQLITE_OK)
-								pk_error("sqlite error during description bind: %s", sqlite3_errmsg(db));
-							g_free(description);
-							description = NULL;
-						}
-						res = sqlite3_step(package);
-						if (res!=SQLITE_DONE)
-							pk_error("sqlite error during step: %s", sqlite3_errmsg(db));
-						sqlite3_reset(package);
-						//pk_debug("added package");
-						haspk = FALSE;
-					}
-					//g_assert(0);
-				}
-				else if (begin[0]==' ')
-				{
-					if (description == NULL)
-						description = g_strdup(&begin[1]);
-					else
-					{
-						gchar *oldval = description;
-						description = g_strconcat(oldval, "\n",&begin[1],NULL);
-						g_free(oldval);
-					}
-				}
-				else
-				{
-					gchar *colon = strchr(begin,':');
-					g_assert(colon!=NULL);
-					colon[0] = '\0';
-					colon+=2;
-					/*if (strlen(colon)>3000)
-						pk_error("strlen(colon) = %d\ncolon = %s",strlen(colon),colon);*/
-					//pk_debug("entry = '%s','%s'",begin,colon);
-					if (begin[0] == 'P' && g_strcasecmp("Package",begin)==0)
-					{
-						res=sqlite3_bind_text(package,FIELD_PKG,colon,-1,SQLITE_STATIC);
-						haspk = TRUE;
-						count++;
-						if (count%1000==0)
-							pk_debug("Package %ld (%s)",count,colon);
-					}
-					else if (begin[0] == 'V' && g_strcasecmp("Version",begin)==0)
-						res=sqlite3_bind_text(package,FIELD_VER,colon,-1,SQLITE_STATIC);
-					else if (begin[0] == 'D' && g_strcasecmp("Depends",begin)==0)
-						res=sqlite3_bind_text(package,FIELD_DEPS,colon,-1,SQLITE_STATIC);
-					else if (begin[0] == 'A' && g_strcasecmp("Architecture",begin)==0)
-						res=sqlite3_bind_text(package,FIELD_ARCH,colon,-1,SQLITE_STATIC);
-					else if (begin[0] == 'D' && g_strcasecmp("Description",begin)==0)
-						res=sqlite3_bind_text(package,FIELD_SHORT,colon,-1,SQLITE_STATIC);
-					if (res!=SQLITE_OK)
-						pk_error("sqlite error during %s bind: %s", begin, sqlite3_errmsg(db));
-				}
-				if (next == NULL)
-					break;
-				begin = next;
-			}
-			res = sqlite3_exec(db,"commit",NULL,NULL,NULL);
-			if (res!=SQLITE_OK)
-				pk_error("sqlite error during commit: %s", sqlite3_errmsg(db));
-			res = sqlite3_clear_bindings(package);
-			if (res!=SQLITE_OK)
-				pk_error("sqlite error during clear: %s", sqlite3_errmsg(db));
-			g_free(contents);
-			contents = NULL;
-		}
-	}
-	sqlite3_finalize(package);
-
-search_task_cleanup:
-	g_dir_close(dir);
-	g_free(sdir);
-	g_free(contents);
-}
-
diff --git a/backends/apt.old/pk-backend-apt.cpp b/backends/apt.old/pk-backend-apt.cpp
deleted file mode 100644
index 2c5e159..0000000
--- a/backends/apt.old/pk-backend-apt.cpp
+++ /dev/null
@@ -1,162 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
- * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include <gmodule.h>
-#include <glib.h>
-#include <glib/gprintf.h>
-
-#include <math.h>
-#include <string.h>
-
-#include <pk-backend.h>
-#include <pk-debug.h>
-#include <pk-package-id.h>
-#include "config.h"
-
-#include <apt-pkg/configuration.h>
-#include <apt-pkg/init.h>
-
-#include "pk-backend-apt.h"
-extern "C" {
-#include "sqlite-pkg-cache.h"
-#include "python-backend-common.h"
-}
-
-static gboolean inited = FALSE;
-
-#define APT_DB DATABASEDIR "/apt.db"
-
-static void backend_initialize(PkBackend *backend)
-{
-	if (!inited)
-	{
-		gchar *apt_fname = NULL;
-		if (pkgInitConfig(*_config) == false)
-			pk_debug("pkginitconfig was false");
-		if (pkgInitSystem(*_config, _system) == false)
-			pk_debug("pkginitsystem was false");
-
-		apt_fname = g_strconcat(
-				_config->Find("Dir").c_str(),
-				_config->Find("Dir::Cache").c_str(),
-				_config->Find("Dir::Cache::pkgcache").c_str(),
-				NULL);
-
-		sqlite_init_cache(backend, APT_DB, apt_fname, apt_build_db);
-		g_free(apt_fname);
-		inited = TRUE;
-	}
-}
-
-/**
- * backend_get_groups:
- */
-static void
-backend_get_groups (PkBackend *backend, PkEnumList *elist)
-{
-	g_return_if_fail (backend != NULL);
-	pk_enum_list_append_multiple (elist,
-				      PK_GROUP_ENUM_ACCESSIBILITY,
-				      PK_GROUP_ENUM_GAMES,
-				      PK_GROUP_ENUM_SYSTEM,
-				      -1);
-}
-
-/**
- * backend_get_filters:
- */
-static void
-backend_get_filters (PkBackend *backend, PkEnumList *elist)
-{
-	g_return_if_fail (backend != NULL);
-	pk_enum_list_append_multiple (elist,
-				      PK_FILTER_ENUM_GUI,
-				      PK_FILTER_ENUM_INSTALLED,
-				      PK_FILTER_ENUM_DEVELOPMENT,
-				      -1);
-}
-
-static gboolean backend_search_file_thread (PkBackend *backend, gpointer data)
-{
-	//search_task *st = (search_task*)data;
-	gchar *sdir = g_path_get_dirname(_config->Find("Dir::State::status").c_str());
-	gchar *ldir = g_build_filename(sdir,"info",NULL);
-	g_free(sdir);
-	GError *error = NULL;
-	GDir *list = g_dir_open(ldir,0,&error);
-	if (error!=NULL)
-	{
-		pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "can't open %s",ldir);
-		g_free(ldir);
-		g_error_free(error);
-		return FALSE;
-	}
-	const gchar * fname = NULL;
-	while ((fname = g_dir_read_name(list))!=NULL)
-	{
-		//pk_backend_package(backend, J->installed, pid, P.ShortDesc().c_str());
-	}
-	pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "search file is incomplete");
-	g_dir_close(list);
-	g_free(ldir);
-	return TRUE;
-}
-
-/**
- * backend_search_file:
- **/
-static void backend_search_file(PkBackend *backend, const gchar *filter, const gchar *search)
-{
-	backend_search_common(backend, filter, search, SEARCH_FILE, backend_search_file_thread);
-}
-
-extern "C" PK_BACKEND_OPTIONS (
-	"APT",					/* description */
-	"0.0.1",				/* version */
-	"Tom Parker <palfrey at tevp.net>",	/* author */
-	backend_initialize,			/* initalize */
-	NULL,					/* destroy */
-	backend_get_groups,			/* get_groups */
-	backend_get_filters,			/* get_filters */
-	NULL,					/* cancel */
-	NULL,					/* get_depends */
-	sqlite_get_description,		/* get_description */
-	NULL,					/* get_requires */
-	NULL,					/* get_update_detail */
-	NULL,					/* get_updates */
-	NULL,					/* install_package */
-	NULL,					/* install_name */
-	python_refresh_cache,			/* refresh_cache */
-	NULL,					/* remove_package */
-	NULL,					/* resolve */
-	NULL,					/* rollback */
-	sqlite_search_details,			/* search_details */
-	backend_search_file,			/* search_file */
-	NULL,					/* search_group */
-	sqlite_search_name,			/* search_name */
-	NULL,					/* update_package */
-	NULL,					/* update_system */
-	NULL,					/* get_repo_list */
-	NULL,					/* repo_enable */
-	NULL					/* repo_set_data */
-);
-
diff --git a/backends/apt.old/pk-backend-apt.h b/backends/apt.old/pk-backend-apt.h
deleted file mode 100644
index ff67654..0000000
--- a/backends/apt.old/pk-backend-apt.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef PK_BACKEND_APT
-#define PK_BACKEND_APT
-
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include <sqlite3.h>
-#include <pk-backend.h>
-
-void apt_build_db(PkBackend * backend, sqlite3 *db);
-
-#endif
diff --git a/backends/apt.old/pk-sqlite-pkg-cache.c b/backends/apt.old/pk-sqlite-pkg-cache.c
deleted file mode 100644
index 29647a5..0000000
--- a/backends/apt.old/pk-sqlite-pkg-cache.c
+++ /dev/null
@@ -1,228 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include <sqlite3.h>
-#include <glib.h>
-#include <glib/gstdio.h>
-#include "sqlite-pkg-cache.h"
-
-static sqlite3 *db = NULL;
-
-typedef struct {
-	PkPackageId *pi;
-} desc_task;
-
-typedef struct {
-	gchar *search;
-	gchar *filter;
-	SearchDepth depth;
-} search_task;
-
-void
-sqlite_init_cache(PkBackend *backend, const char* dbname, const char *compare_fname, void (*build_db)(PkBackend *, sqlite3 *))
-{
-	int ret;
-	struct stat st;
-	time_t db_age;
-
-	ret = sqlite3_open (dbname, &db);
-	ret = sqlite3_exec(db,"PRAGMA synchronous = OFF",NULL,NULL,NULL);
-	g_assert(ret == SQLITE_OK);
-
-	g_stat(dbname, &st);
-	db_age = st.st_mtime;
-	g_stat(compare_fname, &st);
-	if (db_age>=st.st_mtime)
-	{
-		ret = sqlite3_exec(db, "select value from params where name = 'build_complete'", NULL, NULL, NULL);
-		if (ret != SQLITE_ERROR)
-			return;
-	}
-	ret = sqlite3_exec(db,"drop table packages",NULL,NULL,NULL); // wipe it!
-	//g_assert(ret == SQLITE_OK);
-	pk_debug("wiped db");
-	ret = sqlite3_exec(db,"create table packages (name text, version text, deps text, arch text, short_desc text, long_desc text, repo string, primary key(name,version,arch,repo))",NULL,NULL,NULL);
-	g_assert(ret == SQLITE_OK);
-
-	build_db(backend,db);
-
-	sqlite3_exec(db,"create table params (name text primary key, value integer)", NULL, NULL, NULL);
-	sqlite3_exec(db,"insert into params values ('build_complete',1)", NULL, NULL, NULL);
-}
-
-// sqlite_search_packages_thread
-static gboolean
-sqlite_search_packages_thread (PkBackend *backend, gpointer data)
-{
-	search_task *st = (search_task *) data;
-	int res;
-	gchar *sel;
-
-	pk_backend_change_status(backend, PK_STATUS_ENUM_QUERY);
-	pk_backend_no_percentage_updates(backend);
-
-	pk_debug("finding %s", st->search);
-
-	sqlite3_stmt *package = NULL;
-	g_strdelimit(st->search," ",'%');
-
-	if (st->depth == SEARCH_NAME)
-		sel = g_strdup_printf("select name,version,arch,repo,short_desc from packages where name like '%%%s%%'",st->search);
-	else if (st->depth == SEARCH_DETAILS)
-		sel = g_strdup_printf("select name,version,arch,repo,short_desc from packages where name like '%%%s%%' or short_desc like '%%%s%%' or long_desc like '%%%s%%'",st->search, st->search, st->search);
-	else
-	{
-		pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Unknown search task type");
-		goto end_search_packages;
-	}
-
-	pk_debug("statement is '%s'",sel);
-	res = sqlite3_prepare_v2(db,sel, -1, &package, NULL);
-	g_free(sel);
-	if (res!=SQLITE_OK)
-		pk_error("sqlite error during select prepare: %s", sqlite3_errmsg(db));
-	res = sqlite3_step(package);
-	while (res == SQLITE_ROW)
-	{
-		gchar *pid = pk_package_id_build((const gchar*)sqlite3_column_text(package,0),
-				(const gchar*)sqlite3_column_text(package,1),
-				(const gchar*)sqlite3_column_text(package,2),
-				(const gchar*)sqlite3_column_text(package,3));
-		pk_backend_package(backend, PK_INFO_ENUM_UNKNOWN, pid, (const gchar*)sqlite3_column_text(package,4));
-		g_free(pid);
-		if (res==SQLITE_ROW)
-			res = sqlite3_step(package);
-	}
-	if (res!=SQLITE_DONE)
-	{
-		pk_debug("sqlite error during step (%d): %s", res, sqlite3_errmsg(db));
-		g_assert(0);
-	}
-
-	end_search_packages:
-	g_free(st->search);
-	g_free(st);
-
-	return TRUE;
-}
-
-/**
- * backend_search_common
- **/
-void
-backend_search_common(PkBackend * backend, const gchar * filter, const gchar * search, SearchDepth which, PkBackendThreadFunc func)
-{
-	g_return_if_fail (backend != NULL);
-	search_task *data = g_new(search_task, 1);
-	if (data == NULL)
-	{
-		pk_backend_error_code(backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory for search task");
-		pk_backend_finished(backend);
-	}
-	else
-	{
-		data->search = g_strdup(search);
-		data->filter = g_strdup(filter);
-		data->depth = which;
-		pk_backend_thread_helper (backend, func, data);
-	}
-}
-
-/**
- * sqlite_search_details:
- */
-void
-sqlite_search_details (PkBackend *backend, const gchar *filter, const gchar *search)
-{
-	backend_search_common(backend, filter, search, SEARCH_DETAILS, sqlite_search_packages_thread);
-}
-
-/**
- * sqlite_search_name:
- */
-void
-sqlite_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
-{
-	backend_search_common(backend, filter, search, SEARCH_NAME, sqlite_search_packages_thread);
-}
-
-// sqlite_get_description_thread
-static gboolean sqlite_get_description_thread (PkBackend *backend, gpointer data)
-{
-	desc_task *dt = (desc_task *) data;
-	int res;
-
-	pk_backend_change_status(backend, PK_STATUS_ENUM_QUERY);
-	pk_backend_no_percentage_updates(backend);
-
-	pk_debug("finding %s", dt->pi->name);
-
-	sqlite3_stmt *package = NULL;
-	gchar *sel = g_strdup_printf("select long_desc from packages where name = '%s' and version = '%s' and repo = '%s'",dt->pi->name,dt->pi->version,dt->pi->data);
-	pk_debug("statement is '%s'",sel);
-	res = sqlite3_prepare_v2(db,sel, -1, &package, NULL);
-	g_free(sel);
-	if (res!=SQLITE_OK)
-		pk_error("sqlite error during select prepare: %s", sqlite3_errmsg(db));
-	res = sqlite3_step(package);
-	pk_backend_description(backend,dt->pi->name, "unknown", PK_GROUP_ENUM_OTHER,(const gchar*)sqlite3_column_text(package,0),"",0,"");
-	res = sqlite3_step(package);
-	if (res==SQLITE_ROW)
-		pk_error("multiple matches for that package!");
-	if (res!=SQLITE_DONE)
-	{
-		pk_debug("sqlite error during step (%d): %s", res, sqlite3_errmsg(db));
-		g_assert(0);
-	}
-
-	g_free(dt);
-
-	return TRUE;
-}
-
-/**
- * sqlite_get_description:
- */
-void
-sqlite_get_description (PkBackend *backend, const gchar *package_id)
-{
-	g_return_if_fail (backend != NULL);
-	desc_task *data = g_new(desc_task, 1);
-	if (data == NULL)
-	{
-		pk_backend_error_code(backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory for search task");
-		pk_backend_finished(backend);
-		return;
-	}
-
-	data->pi = pk_package_id_new_from_string(package_id);
-	if (data->pi == NULL)
-	{
-		pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
-		pk_backend_finished(backend);
-		return;
-	}
-
-	pk_backend_thread_helper (backend, sqlite_get_description_thread, data);
-	return;
-}
-
-
diff --git a/backends/apt.old/pk-sqlite-pkg-cache.h b/backends/apt.old/pk-sqlite-pkg-cache.h
deleted file mode 100644
index 68f5287..0000000
--- a/backends/apt.old/pk-sqlite-pkg-cache.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef SQLITE_PKT_CACHE
-#define SQLITE_PKT_CACHE
-
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-typedef enum {
-	SEARCH_NAME = 1,
-	SEARCH_DETAILS,
-	SEARCH_FILE
-} SearchDepth;
-
-#include <pk-backend.h>
-
-void sqlite_init_cache(PkBackend *backend, const char* dbname, const char* compare_fname, void (*build_db)(PkBackend *, sqlite3 *db));
-void sqlite_search_details (PkBackend *backend, const gchar *filter, const gchar *search);
-void sqlite_search_name (PkBackend *backend, const gchar *filter, const gchar *search);
-void backend_search_common(PkBackend * backend, const gchar * filter, const gchar * search, SearchDepth which, PkBackendThreadFunc func);
-void sqlite_get_description (PkBackend *backend, const gchar *package_id);
-
-#endif
diff --git a/backends/apt/Makefile.am b/backends/apt/Makefile.am
index 53285ef..4930e74 100644
--- a/backends/apt/Makefile.am
+++ b/backends/apt/Makefile.am
@@ -3,9 +3,9 @@ plugindir = @PK_PLUGIN_DIR@
 plugin_LTLIBRARIES = libpk_backend_apt.la
 libpk_backend_apt_la_SOURCES = pk-backend-apt.c
 libpk_backend_apt_la_LIBADD = @PK_PLUGIN_LIBS@
-libpk_backend_apt_la_LDFLAGS = -module -avoid-version
-libpk_backend_apt_la_CFLAGS = @PK_PLUGIN_CFLAGS@
-libpk_backend_apt_la_CXXFLAGS = @PK_PLUGIN_CFLAGS@
+libpk_backend_apt_la_LDFLAGS = -module -avoid-version $(APT_LIBS)
+libpk_backend_apt_la_CFLAGS = @PK_PLUGIN_CFLAGS@ $(APT_CFLAGS)
+libpk_backend_apt_la_CXXFLAGS = @PK_PLUGIN_CFLAGS@ $(APT_CFLAGS) -DPK_DB_DIR=\""$(PK_DB_DIR)"\"
 
 if APT_SEARCH_PLAIN
 libpk_backend_apt_la_SOURCES += pk-apt-search-plain.c
@@ -13,7 +13,7 @@ endif
 
 if APT_SEARCH_SQLITE
 libpk_backend_apt_la_SOURCES += pk-sqlite-pkg-cache.h	\
-								pk-sqlite-pkg-cache.c	\
+								pk-sqlite-pkg-cache.cpp	\
 								pk-apt-build-db.cpp		\
-								pk-apt-search-sqlite.c
+								pk-apt-search-sqlite.cpp
 endif
diff --git a/backends/apt/pk-apt-build-db.h b/backends/apt/pk-apt-build-db.h
new file mode 100644
index 0000000..bb786a9
--- /dev/null
+++ b/backends/apt/pk-apt-build-db.h
@@ -0,0 +1,30 @@
+#ifndef PK_APT_BUILD_DB
+#define PK_APT_BUILD_DB
+
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <sqlite3.h>
+#include <pk-backend.h>
+
+void apt_build_db(PkBackend * backend, sqlite3 *db);
+
+#endif
diff --git a/backends/apt/pk-apt-search-sqlite.c b/backends/apt/pk-apt-search-sqlite.c
deleted file mode 100644
index 88784b5..0000000
--- a/backends/apt/pk-apt-search-sqlite.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Ali Sabil <ali.sabil at gmail.com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include <gmodule.h>
-#include <glib.h>
-#include <string.h>
-#include <pk-backend.h>
-#include "pk-sqlite-pkg-cache.h"
-
-/**
- * backend_get_groups:
- */
-void
-backend_get_groups (PkBackend *backend, PkEnumList *elist)
-{
-	g_return_if_fail (backend != NULL);
-	pk_enum_list_append_multiple (elist,
-				      PK_GROUP_ENUM_ACCESSORIES,
-				      PK_GROUP_ENUM_GAMES,
-				      PK_GROUP_ENUM_GRAPHICS,
-				      PK_GROUP_ENUM_INTERNET,
-				      PK_GROUP_ENUM_OFFICE,
-				      PK_GROUP_ENUM_OTHER,
-				      PK_GROUP_ENUM_PROGRAMMING,
-				      PK_GROUP_ENUM_MULTIMEDIA,
-				      PK_GROUP_ENUM_SYSTEM,
-				      -1);
-}
-
-/**
- * backend_get_filters:
- */
-void
-backend_get_filters (PkBackend *backend, PkEnumList *elist)
-{
-	g_return_if_fail (backend != NULL);
-	pk_enum_list_append_multiple (elist,
-				      PK_FILTER_ENUM_GUI,
-				      PK_FILTER_ENUM_INSTALLED,
-				      PK_FILTER_ENUM_DEVELOPMENT,
-				      -1);
-}
-
-/**
- * backend_get_description:
- */
-
-void
-backend_get_description (PkBackend *backend, const gchar *package_id)
-{
-	sqlite_get_description(backend,package_id);
-}
-
-/**
- * backend_search_details:
- */
-
-void
-backend_search_details (PkBackend *backend, const gchar *filter, const gchar *search)
-{
-	sqlite_search_details(backend,filter,search);
-}
-
-/**
- * backend_search_name:
- */
-void
-backend_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
-{
-	sqlite_search_name(backend,filter,search);
-}
-
-/**
- * backend_search_group:
- */
-void
-backend_search_group (PkBackend *backend, const gchar *filter, const gchar *search)
-{
-	g_return_if_fail (backend != NULL);
-	pk_backend_allow_interrupt (backend, TRUE);
-	pk_backend_spawn_helper (backend, "search-group.py", filter, search, NULL);
-}
diff --git a/backends/apt/pk-apt-search-sqlite.cpp b/backends/apt/pk-apt-search-sqlite.cpp
new file mode 100644
index 0000000..ac3c83f
--- /dev/null
+++ b/backends/apt/pk-apt-search-sqlite.cpp
@@ -0,0 +1,130 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Ali Sabil <ali.sabil at gmail.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <gmodule.h>
+#include <glib.h>
+#include <string.h>
+#include <pk-backend.h>
+#include "pk-sqlite-pkg-cache.h"
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/init.h>
+#include "pk-apt-build-db.h"
+
+/**
+ * backend_get_groups:
+ */
+extern "C" void
+backend_get_groups (PkBackend *backend, PkEnumList *elist)
+{
+	g_return_if_fail (backend != NULL);
+	pk_enum_list_append_multiple (elist,
+				      PK_GROUP_ENUM_ACCESSORIES,
+				      PK_GROUP_ENUM_GAMES,
+				      PK_GROUP_ENUM_GRAPHICS,
+				      PK_GROUP_ENUM_INTERNET,
+				      PK_GROUP_ENUM_OFFICE,
+				      PK_GROUP_ENUM_OTHER,
+				      PK_GROUP_ENUM_PROGRAMMING,
+				      PK_GROUP_ENUM_MULTIMEDIA,
+				      PK_GROUP_ENUM_SYSTEM,
+				      -1);
+}
+
+/**
+ * backend_get_filters:
+ */
+extern "C" void
+backend_get_filters (PkBackend *backend, PkEnumList *elist)
+{
+	g_return_if_fail (backend != NULL);
+	pk_enum_list_append_multiple (elist,
+				      PK_FILTER_ENUM_GUI,
+				      PK_FILTER_ENUM_INSTALLED,
+				      PK_FILTER_ENUM_DEVELOPMENT,
+				      -1);
+}
+
+/**
+ * backend_get_description:
+ */
+
+extern "C" void
+backend_get_description (PkBackend *backend, const gchar *package_id)
+{
+	sqlite_get_description(backend,package_id);
+}
+
+/**
+ * backend_search_details:
+ */
+
+extern "C" void
+backend_search_details (PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	sqlite_search_details(backend,filter,search);
+}
+
+/**
+ * backend_search_name:
+ */
+extern "C" void
+backend_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	sqlite_search_name(backend,filter,search);
+}
+
+/**
+ * backend_search_group:
+ */
+extern "C" void
+backend_search_group (PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	g_return_if_fail (backend != NULL);
+	pk_backend_allow_interrupt (backend, TRUE);
+	pk_backend_spawn_helper (backend, "search-group.py", filter, search, NULL);
+}
+
+static gboolean inited = FALSE;
+
+#define APT_DB PK_DB_DIR "/apt.db"
+
+extern "C" void backend_init_search(PkBackend *backend)
+{
+	if (!inited)
+	{
+		gchar *apt_fname = NULL;
+		if (pkgInitConfig(*_config) == false)
+			pk_debug("pkginitconfig was false");
+		if (pkgInitSystem(*_config, _system) == false)
+			pk_debug("pkginitsystem was false");
+
+		apt_fname = g_strconcat(
+				_config->Find("Dir").c_str(),
+				_config->Find("Dir::Cache").c_str(),
+				_config->Find("Dir::Cache::pkgcache").c_str(),
+				NULL);
+
+		//sqlite_set_installed_check(is_installed);
+		sqlite_init_cache(backend, APT_DB, apt_fname, apt_build_db);
+		g_free(apt_fname);
+		inited = TRUE;
+	}
+}
diff --git a/backends/apt/pk-apt-search.h b/backends/apt/pk-apt-search.h
index a09f85d..645e03d 100644
--- a/backends/apt/pk-apt-search.h
+++ b/backends/apt/pk-apt-search.h
@@ -25,6 +25,8 @@
 #include <glib.h>
 #include <pk-backend.h>
 
+void backend_init_search(PkBackend *backend);
+
 void backend_get_description (PkBackend *backend, const gchar *package_id);
 void backend_search_details (PkBackend *backend, const gchar *filter, const gchar *search);
 void backend_search_name (PkBackend *backend, const gchar *filter, const gchar *search);
diff --git a/backends/apt/pk-backend-apt.c b/backends/apt/pk-backend-apt.c
index d5bacb3..191f756 100644
--- a/backends/apt/pk-backend-apt.c
+++ b/backends/apt/pk-backend-apt.c
@@ -63,7 +63,7 @@ backend_get_filters (PkBackend *backend, PkEnumList *elist)
 PK_BACKEND_OPTIONS (
 	"Apt",				/* description */
 	"Ali Sabil <ali.sabil at gmail.com>",	/* author */
-	NULL,					/* initalize */
+	backend_init_search,					/* initalize */
 	NULL,					/* destroy */
 	backend_get_groups,			/* get_groups */
 	backend_get_filters,			/* get_filters */
diff --git a/backends/apt/pk-sqlite-pkg-cache.c b/backends/apt/pk-sqlite-pkg-cache.c
deleted file mode 100644
index c81f668..0000000
--- a/backends/apt/pk-sqlite-pkg-cache.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include <glib.h>
-#include <glib/gstdio.h>
-#include "pk-sqlite-pkg-cache.h"
-
-static sqlite3 *db = NULL;
-static gboolean(*is_installed) (const PkPackageId *) = NULL;
-
-void sqlite_set_installed_check(gboolean(*func) (const PkPackageId *))
-{
-	is_installed = func;
-}
-
-typedef struct {
-	PkPackageId *pi;
-} desc_task;
-
-typedef struct {
-	gchar *search;
-	gchar *filter;
-	SearchDepth depth;
-} search_task;
-
-void
-sqlite_init_cache(PkBackend *backend, const char* dbname, const char *compare_fname, void (*build_db)(PkBackend *, sqlite3 *))
-{
-	int ret;
-	struct stat st;
-	time_t db_age;
-
-	ret = sqlite3_open (dbname, &db);
-	ret = sqlite3_exec(db,"PRAGMA synchronous = OFF",NULL,NULL,NULL);
-	g_assert(ret == SQLITE_OK);
-
-	g_stat(dbname, &st);
-	db_age = st.st_mtime;
-	g_stat(compare_fname, &st);
-	if (db_age>=st.st_mtime)
-	{
-		ret = sqlite3_exec(db, "select value from params where name = 'build_complete'", NULL, NULL, NULL);
-		if (ret != SQLITE_ERROR)
-			return;
-	}
-	ret = sqlite3_exec(db,"drop table packages",NULL,NULL,NULL); // wipe it!
-	//g_assert(ret == SQLITE_OK);
-	pk_debug("wiped db");
-	ret = sqlite3_exec(db,"create table packages (name text, version text, deps text, arch text, short_desc text, long_desc text, repo string, primary key(name,version,arch,repo))",NULL,NULL,NULL);
-	g_assert(ret == SQLITE_OK);
-
-	build_db(backend,db);
-
-	sqlite3_exec(db,"create table params (name text primary key, value integer)", NULL, NULL, NULL);
-	sqlite3_exec(db,"insert into params values ('build_complete',1)", NULL, NULL, NULL);
-}
-
-// sqlite_search_packages_thread
-static gboolean
-sqlite_search_packages_thread (PkBackend *backend, gpointer data)
-{
-	search_task *st = (search_task *) data;
-	int res;
-	gchar *sel;
-
-	pk_backend_change_status(backend, PK_STATUS_ENUM_QUERY);
-	pk_backend_no_percentage_updates(backend);
-
-	pk_debug("finding %s", st->search);
-
-	sqlite3_stmt *package = NULL;
-	g_strdelimit(st->search," ",'%');
-
-	if (st->depth == SEARCH_NAME)
-		sel = g_strdup_printf("select name,version,arch,repo,short_desc from packages where name like '%%%s%%'",st->search);
-	else if (st->depth == SEARCH_DETAILS)
-		sel = g_strdup_printf("select name,version,arch,repo,short_desc from packages where name like '%%%s%%' or short_desc like '%%%s%%' or long_desc like '%%%s%%'",st->search, st->search, st->search);
-	else
-	{
-		pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Unknown search task type");
-		goto end_search_packages;
-	}
-
-	pk_debug("statement is '%s'",sel);
-	res = sqlite3_prepare_v2(db,sel, -1, &package, NULL);
-	g_free(sel);
-	if (res!=SQLITE_OK)
-		pk_error("sqlite error during select prepare: %s", sqlite3_errmsg(db));
-	res = sqlite3_step(package);
-	while (res == SQLITE_ROW)
-	{
-		PkPackageId *pid = pk_package_id_new_from_list((const gchar*)sqlite3_column_text(package,0),
-				(const gchar*)sqlite3_column_text(package,1),
-				(const gchar*)sqlite3_column_text(package,2),
-				(const gchar*)sqlite3_column_text(package,3));
-
-		gchar *cpid = pk_package_id_to_string(pid);
-		PkInfoEnum pie = PK_INFO_ENUM_UNKNOWN;
-
-		if (is_installed != NULL)
-			pie = is_installed(pid)?PK_INFO_ENUM_INSTALLED:PK_INFO_ENUM_AVAILABLE;
-
-		pk_backend_package(backend, pie, cpid, (const gchar*)sqlite3_column_text(package,4));
-
-		g_free(cpid);
-		pk_package_id_free(pid);
-
-		if (res==SQLITE_ROW)
-			res = sqlite3_step(package);
-	}
-	if (res!=SQLITE_DONE)
-	{
-		pk_debug("sqlite error during step (%d): %s", res, sqlite3_errmsg(db));
-		g_assert(0);
-	}
-
-	end_search_packages:
-	g_free(st->search);
-	g_free(st);
-
-	return TRUE;
-}
-
-/**
- * backend_search_common
- **/
-void
-backend_search_common(PkBackend * backend, const gchar * filter, const gchar * search, SearchDepth which, PkBackendThreadFunc func)
-{
-	g_return_if_fail (backend != NULL);
-	search_task *data = g_new(search_task, 1);
-	if (data == NULL)
-	{
-		pk_backend_error_code(backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory for search task");
-		pk_backend_finished(backend);
-	}
-	else
-	{
-		data->search = g_strdup(search);
-		data->filter = g_strdup(filter);
-		data->depth = which;
-		pk_backend_thread_helper (backend, func, data);
-	}
-}
-
-/**
- * sqlite_search_details:
- */
-void
-sqlite_search_details (PkBackend *backend, const gchar *filter, const gchar *search)
-{
-	backend_search_common(backend, filter, search, SEARCH_DETAILS, sqlite_search_packages_thread);
-}
-
-/**
- * sqlite_search_name:
- */
-void
-sqlite_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
-{
-	backend_search_common(backend, filter, search, SEARCH_NAME, sqlite_search_packages_thread);
-}
-
-// sqlite_get_description_thread
-static gboolean sqlite_get_description_thread (PkBackend *backend, gpointer data)
-{
-	desc_task *dt = (desc_task *) data;
-	int res;
-
-	pk_backend_change_status(backend, PK_STATUS_ENUM_QUERY);
-	pk_backend_no_percentage_updates(backend);
-
-	pk_debug("finding %s", dt->pi->name);
-
-	sqlite3_stmt *package = NULL;
-	gchar *sel = g_strdup_printf("select long_desc from packages where name = '%s' and version = '%s' and repo = '%s'",dt->pi->name,dt->pi->version,dt->pi->data);
-	pk_debug("statement is '%s'",sel);
-	res = sqlite3_prepare_v2(db,sel, -1, &package, NULL);
-	g_free(sel);
-	if (res!=SQLITE_OK)
-		pk_error("sqlite error during select prepare: %s", sqlite3_errmsg(db));
-	res = sqlite3_step(package);
-	pk_backend_description(backend,dt->pi->name, "unknown", PK_GROUP_ENUM_OTHER,(const gchar*)sqlite3_column_text(package,0),"",0,"");
-	res = sqlite3_step(package);
-	if (res==SQLITE_ROW)
-		pk_error("multiple matches for that package!");
-	if (res!=SQLITE_DONE)
-	{
-		pk_debug("sqlite error during step (%d): %s", res, sqlite3_errmsg(db));
-		g_assert(0);
-	}
-
-	g_free(dt);
-
-	return TRUE;
-}
-
-/**
- * sqlite_get_description:
- */
-void
-sqlite_get_description (PkBackend *backend, const gchar *package_id)
-{
-	g_return_if_fail (backend != NULL);
-	desc_task *data = g_new(desc_task, 1);
-	if (data == NULL)
-	{
-		pk_backend_error_code(backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory for search task");
-		pk_backend_finished(backend);
-		return;
-	}
-
-	data->pi = pk_package_id_new_from_string(package_id);
-	if (data->pi == NULL)
-	{
-		pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
-		pk_backend_finished(backend);
-		return;
-	}
-
-	pk_backend_thread_helper (backend, sqlite_get_description_thread, data);
-	return;
-}
-
-
diff --git a/backends/apt/pk-sqlite-pkg-cache.cpp b/backends/apt/pk-sqlite-pkg-cache.cpp
new file mode 100644
index 0000000..55e4bfa
--- /dev/null
+++ b/backends/apt/pk-sqlite-pkg-cache.cpp
@@ -0,0 +1,245 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+#include <glib/gstdio.h>
+#include "pk-sqlite-pkg-cache.h"
+
+static sqlite3 *db = NULL;
+static gboolean(*is_installed) (const PkPackageId *) = NULL;
+
+void sqlite_set_installed_check(gboolean(*func) (const PkPackageId *))
+{
+	is_installed = func;
+}
+
+typedef struct {
+	PkPackageId *pi;
+} desc_task;
+
+typedef struct {
+	gchar *search;
+	gchar *filter;
+	SearchDepth depth;
+} search_task;
+
+void
+sqlite_init_cache(PkBackend *backend, const char* dbname, const char *compare_fname, void (*build_db)(PkBackend *, sqlite3 *))
+{
+	int ret;
+	struct stat st;
+	time_t db_age;
+
+	ret = sqlite3_open (dbname, &db);
+	g_assert(ret == SQLITE_OK);
+	g_assert(db!=NULL);
+	ret = sqlite3_exec(db,"PRAGMA synchronous = OFF",NULL,NULL,NULL);
+	g_assert(ret == SQLITE_OK);
+
+	g_stat(dbname, &st);
+	db_age = st.st_mtime;
+	g_stat(compare_fname, &st);
+	if (db_age>=st.st_mtime)
+	{
+		ret = sqlite3_exec(db, "select value from params where name = 'build_complete'", NULL, NULL, NULL);
+		if (ret != SQLITE_ERROR)
+			return;
+	}
+	ret = sqlite3_exec(db,"drop table packages",NULL,NULL,NULL); // wipe it!
+	//g_assert(ret == SQLITE_OK);
+	pk_debug("wiped db");
+	ret = sqlite3_exec(db,"create table packages (name text, version text, deps text, arch text, short_desc text, long_desc text, repo string, primary key(name,version,arch,repo))",NULL,NULL,NULL);
+	g_assert(ret == SQLITE_OK);
+
+	build_db(backend,db);
+
+	sqlite3_exec(db,"create table params (name text primary key, value integer)", NULL, NULL, NULL);
+	sqlite3_exec(db,"insert into params values ('build_complete',1)", NULL, NULL, NULL);
+}
+
+// sqlite_search_packages_thread
+static gboolean
+sqlite_search_packages_thread (PkBackend *backend, gpointer data)
+{
+	search_task *st = (search_task *) data;
+	int res;
+	gchar *sel;
+
+	pk_backend_change_status(backend, PK_STATUS_ENUM_QUERY);
+	pk_backend_no_percentage_updates(backend);
+
+	pk_debug("finding %s", st->search);
+
+	sqlite3_stmt *package = NULL;
+	g_strdelimit(st->search," ",'%');
+
+	if (st->depth == SEARCH_NAME)
+		sel = g_strdup_printf("select name,version,arch,repo,short_desc from packages where name like '%%%s%%'",st->search);
+	else if (st->depth == SEARCH_DETAILS)
+		sel = g_strdup_printf("select name,version,arch,repo,short_desc from packages where name like '%%%s%%' or short_desc like '%%%s%%' or long_desc like '%%%s%%'",st->search, st->search, st->search);
+	else
+	{
+		pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Unknown search task type");
+		goto end_search_packages;
+	}
+
+	pk_debug("statement is '%s'",sel);
+	res = sqlite3_prepare_v2(db,sel, -1, &package, NULL);
+	g_free(sel);
+	if (res!=SQLITE_OK)
+		pk_error("sqlite error during select prepare: %s", sqlite3_errmsg(db));
+	res = sqlite3_step(package);
+	while (res == SQLITE_ROW)
+	{
+		PkPackageId *pid = pk_package_id_new_from_list((const gchar*)sqlite3_column_text(package,0),
+				(const gchar*)sqlite3_column_text(package,1),
+				(const gchar*)sqlite3_column_text(package,2),
+				(const gchar*)sqlite3_column_text(package,3));
+
+		gchar *cpid = pk_package_id_to_string(pid);
+		PkInfoEnum pie = PK_INFO_ENUM_UNKNOWN;
+
+		if (is_installed != NULL)
+			pie = is_installed(pid)?PK_INFO_ENUM_INSTALLED:PK_INFO_ENUM_AVAILABLE;
+
+		pk_backend_package(backend, pie, cpid, (const gchar*)sqlite3_column_text(package,4));
+
+		g_free(cpid);
+		pk_package_id_free(pid);
+
+		if (res==SQLITE_ROW)
+			res = sqlite3_step(package);
+	}
+	if (res!=SQLITE_DONE)
+	{
+		pk_debug("sqlite error during step (%d): %s", res, sqlite3_errmsg(db));
+		g_assert(0);
+	}
+
+	end_search_packages:
+	g_free(st->search);
+	g_free(st);
+
+	return TRUE;
+}
+
+/**
+ * backend_search_common
+ **/
+void
+backend_search_common(PkBackend * backend, const gchar * filter, const gchar * search, SearchDepth which, PkBackendThreadFunc func)
+{
+	g_return_if_fail (backend != NULL);
+	search_task *data = g_new(search_task, 1);
+	if (data == NULL)
+	{
+		pk_backend_error_code(backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory for search task");
+		pk_backend_finished(backend);
+	}
+	else
+	{
+		data->search = g_strdup(search);
+		data->filter = g_strdup(filter);
+		data->depth = which;
+		pk_backend_thread_helper (backend, func, data);
+	}
+}
+
+/**
+ * sqlite_search_details:
+ */
+void
+sqlite_search_details (PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	backend_search_common(backend, filter, search, SEARCH_DETAILS, sqlite_search_packages_thread);
+}
+
+/**
+ * sqlite_search_name:
+ */
+void
+sqlite_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	backend_search_common(backend, filter, search, SEARCH_NAME, sqlite_search_packages_thread);
+}
+
+// sqlite_get_description_thread
+static gboolean sqlite_get_description_thread (PkBackend *backend, gpointer data)
+{
+	desc_task *dt = (desc_task *) data;
+	int res;
+
+	pk_backend_change_status(backend, PK_STATUS_ENUM_QUERY);
+	pk_backend_no_percentage_updates(backend);
+
+	pk_debug("finding %s", dt->pi->name);
+
+	sqlite3_stmt *package = NULL;
+	gchar *sel = g_strdup_printf("select long_desc from packages where name = '%s' and version = '%s' and repo = '%s'",dt->pi->name,dt->pi->version,dt->pi->data);
+	pk_debug("statement is '%s'",sel);
+	res = sqlite3_prepare_v2(db,sel, -1, &package, NULL);
+	g_free(sel);
+	if (res!=SQLITE_OK)
+		pk_error("sqlite error during select prepare: %s", sqlite3_errmsg(db));
+	res = sqlite3_step(package);
+	pk_backend_description(backend,dt->pi->name, "unknown", PK_GROUP_ENUM_OTHER,(const gchar*)sqlite3_column_text(package,0),"",0,"");
+	res = sqlite3_step(package);
+	if (res==SQLITE_ROW)
+		pk_error("multiple matches for that package!");
+	if (res!=SQLITE_DONE)
+	{
+		pk_debug("sqlite error during step (%d): %s", res, sqlite3_errmsg(db));
+		g_assert(0);
+	}
+
+	g_free(dt);
+
+	return TRUE;
+}
+
+/**
+ * sqlite_get_description:
+ */
+extern "C++" void
+sqlite_get_description (PkBackend *backend, const gchar *package_id)
+{
+	g_return_if_fail (backend != NULL);
+	desc_task *data = g_new(desc_task, 1);
+	if (data == NULL)
+	{
+		pk_backend_error_code(backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory for search task");
+		pk_backend_finished(backend);
+		return;
+	}
+
+	data->pi = pk_package_id_new_from_string(package_id);
+	if (data->pi == NULL)
+	{
+		pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
+		pk_backend_finished(backend);
+		return;
+	}
+
+	pk_backend_thread_helper (backend, sqlite_get_description_thread, data);
+	return;
+}
+
+
diff --git a/src/Makefile.am b/src/Makefile.am
index a6c98c2..1ee4df9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -99,13 +99,6 @@ packagekitd_LDADD += 					\
 	$(BOX_LIBS)
 endif
 
-if BACKEND_TYPE_APT
-INCLUDES +=						\
-	$(APT_CFLAGS)
-packagekitd_LDADD += 					\
-	$(APT_LIBS)
-endif
-
 BUILT_SOURCES = 					\
 	pk-marshal.c					\
 	pk-marshal.h					\
commit 85db361f9ac39fc5860e6f9b4667872ee5848bad
Author: Tom Parker <palfrey at tevp.net>
Date:   Thu Nov 15 19:40:32 2007 +0100

    Re-add sqlite searching to apt backend

diff --git a/backends/apt/Makefile.am b/backends/apt/Makefile.am
index 669a220..53285ef 100644
--- a/backends/apt/Makefile.am
+++ b/backends/apt/Makefile.am
@@ -5,7 +5,15 @@ libpk_backend_apt_la_SOURCES = pk-backend-apt.c
 libpk_backend_apt_la_LIBADD = @PK_PLUGIN_LIBS@
 libpk_backend_apt_la_LDFLAGS = -module -avoid-version
 libpk_backend_apt_la_CFLAGS = @PK_PLUGIN_CFLAGS@
+libpk_backend_apt_la_CXXFLAGS = @PK_PLUGIN_CFLAGS@
 
 if APT_SEARCH_PLAIN
 libpk_backend_apt_la_SOURCES += pk-apt-search-plain.c
 endif
+
+if APT_SEARCH_SQLITE
+libpk_backend_apt_la_SOURCES += pk-sqlite-pkg-cache.h	\
+								pk-sqlite-pkg-cache.c	\
+								pk-apt-build-db.cpp		\
+								pk-apt-search-sqlite.c
+endif
diff --git a/backends/apt/pk-apt-build-db.cpp b/backends/apt/pk-apt-build-db.cpp
new file mode 100644
index 0000000..38046f6
--- /dev/null
+++ b/backends/apt/pk-apt-build-db.cpp
@@ -0,0 +1,284 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+//#include "pk-backend-apt.h"
+#include <pk-backend.h>
+#include <apt-pkg/configuration.h>
+#include <sqlite3.h>
+
+typedef enum {FIELD_PKG=1,FIELD_VER,FIELD_DEPS,FIELD_ARCH,FIELD_SHORT,FIELD_LONG,FIELD_REPO} Fields;
+
+void apt_build_db(PkBackend * backend, sqlite3 *db)
+{
+	GMatchInfo *match_info;
+	GError *error = NULL;
+	gchar *contents = NULL;
+	gchar *sdir;
+	const gchar *fname;
+	GRegex *origin, *suite;
+	GDir *dir;
+	GHashTable *releases;
+	int res;
+	sqlite3_stmt *package = NULL;
+
+	pk_backend_change_status(backend, PK_STATUS_ENUM_QUERY);
+	pk_backend_no_percentage_updates(backend);
+
+	sdir = g_build_filename(_config->Find("Dir").c_str(),_config->Find("Dir::State").c_str(),_config->Find("Dir::State::lists").c_str(), NULL);
+	dir = g_dir_open(sdir,0,&error);
+	if (error!=NULL)
+	{
+		pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "can't open %s",dir);
+		g_error_free(error);
+		goto search_task_cleanup;
+	}
+
+	origin = g_regex_new("^Origin: (\\S+)",(GRegexCompileFlags)(G_REGEX_CASELESS|G_REGEX_OPTIMIZE|G_REGEX_MULTILINE),(GRegexMatchFlags)0,NULL);
+	suite = g_regex_new("^Suite: (\\S+)",(GRegexCompileFlags)(G_REGEX_CASELESS|G_REGEX_OPTIMIZE|G_REGEX_MULTILINE),(GRegexMatchFlags)0,NULL);
+
+	releases = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
+	while ((fname = g_dir_read_name(dir))!=NULL)
+	{
+		gchar *temp, *parsed_name;
+		gchar** items = g_strsplit(fname,"_",-1);
+		guint len = g_strv_length(items);
+		if(len<=3) // minimum is <source>_<type>_<group>
+		{
+			g_strfreev(items);
+			continue;
+		}
+
+		/* warning: nasty hack with g_strjoinv */
+		temp = items[len-2];
+		items[len-2] = NULL;
+		parsed_name = g_strjoinv("_",items);
+		items[len-2] = temp;
+
+		if (g_ascii_strcasecmp(items[len-1],"Release")==0 && g_ascii_strcasecmp(items[len-2],"source")!=0)
+		{
+			gchar * repo = NULL, *fullname;
+			fullname = g_build_filename(sdir,fname,NULL);
+			if (g_file_get_contents(fullname,&contents,NULL,NULL) == FALSE)
+			{
+				pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "error loading %s",fullname);
+				goto search_task_cleanup;
+			}
+			g_free(fullname);
+
+			g_regex_match (origin, contents, (GRegexMatchFlags)0, &match_info);
+			if (!g_match_info_matches(match_info))
+			{
+				pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "origin regex failure in %s",fname);
+				goto search_task_cleanup;
+			}
+			repo = g_match_info_fetch (match_info, 1);
+
+			g_regex_match (suite, contents, (GRegexMatchFlags)0, &match_info);
+			if (g_match_info_matches(match_info))
+			{
+				temp = g_strconcat(repo,"/",g_match_info_fetch (match_info, 1),NULL);
+				g_free(repo);
+				repo = temp;
+			}
+
+			temp = parsed_name;
+			parsed_name = g_strconcat(temp,"_",items[len-2],NULL);
+			g_free(temp);
+
+			pk_debug("type is %s, group is %s, parsed_name is %s",items[len-2],items[len-1],parsed_name);
+
+			g_hash_table_insert(releases, parsed_name, repo);
+			g_free(contents);
+			contents = NULL;
+		}
+		else
+			g_free(parsed_name);
+		g_strfreev(items);
+	}
+	g_dir_close(dir);
+
+	/* and then we need to do this again, but this time we're looking for the packages */
+	dir = g_dir_open(sdir,0,&error);
+	res = sqlite3_prepare_v2(db, "insert or replace into packages values (?,?,?,?,?,?,?)", -1, &package, NULL);
+	if (res!=SQLITE_OK)
+		pk_error("sqlite error during insert prepare: %s", sqlite3_errmsg(db));
+	else
+		pk_debug("insert prepare ok for %p",package);
+	while ((fname = g_dir_read_name(dir))!=NULL)
+	{
+		gchar** items = g_strsplit(fname,"_",-1);
+		guint len = g_strv_length(items);
+		if(len<=3) // minimum is <source>_<type>_<group>
+		{
+			g_strfreev(items);
+			continue;
+		}
+
+		if (g_ascii_strcasecmp(items[len-1],"Packages")==0)
+		{
+			const gchar *repo;
+			gchar *temp=NULL, *parsed_name=NULL;
+			gchar *fullname= NULL;
+			gchar *begin=NULL, *next=NULL, *description = NULL;
+			glong count = 0;
+			gboolean haspk = FALSE;
+
+			/* warning: nasty hack with g_strjoinv */
+			if (g_str_has_prefix(items[len-2],"binary-"))
+			{
+				temp = items[len-3];
+				items[len-3] = NULL;
+				parsed_name = g_strjoinv("_",items);
+				items[len-3] = temp;
+			}
+			else
+			{
+				temp = items[len-1];
+				items[len-1] = NULL;
+				parsed_name = g_strjoinv("_",items);
+				items[len-1] = temp;
+			}
+
+			pk_debug("type is %s, group is %s, parsed_name is %s",items[len-2],items[len-1],parsed_name);
+
+			repo = (const gchar *)g_hash_table_lookup(releases,parsed_name);
+			if (repo == NULL)
+			{
+				pk_debug("Can't find repo for %s, marking as \"unknown\"",parsed_name);
+				repo = g_strdup("unknown");
+				//g_assert(0);
+			}
+			else
+				pk_debug("repo for %s is %s",parsed_name,repo);
+			g_free(parsed_name);
+
+			fullname = g_build_filename(sdir,fname,NULL);
+			pk_debug("loading %s",fullname);
+			if (g_file_get_contents(fullname,&contents,NULL,NULL) == FALSE)
+			{
+				pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "error loading %s",fullname);
+				goto search_task_cleanup;
+			}
+			/*else
+				pk_debug("loaded");*/
+
+			res = sqlite3_bind_text(package,FIELD_REPO,repo,-1,SQLITE_TRANSIENT);
+			if (res!=SQLITE_OK)
+				pk_error("sqlite error during repo bind: %s", sqlite3_errmsg(db));
+			/*else
+				pk_debug("repo bind ok");*/
+
+			res = sqlite3_exec(db,"begin",NULL,NULL,NULL);
+			g_assert(res == SQLITE_OK);
+
+			begin = contents;
+
+			while (true)
+			{
+				next = strstr(begin,"\n");
+				if (next!=NULL)
+				{
+					next[0] = '\0';
+					next++;
+				}
+
+				if (begin[0]=='\0')
+				{
+					if (haspk)
+					{
+						if (description!=NULL)
+						{
+							res=sqlite3_bind_text(package,FIELD_LONG,description,-1,SQLITE_TRANSIENT);
+							if (res!=SQLITE_OK)
+								pk_error("sqlite error during description bind: %s", sqlite3_errmsg(db));
+							g_free(description);
+							description = NULL;
+						}
+						res = sqlite3_step(package);
+						if (res!=SQLITE_DONE)
+							pk_error("sqlite error during step: %s", sqlite3_errmsg(db));
+						sqlite3_reset(package);
+						//pk_debug("added package");
+						haspk = FALSE;
+					}
+					//g_assert(0);
+				}
+				else if (begin[0]==' ')
+				{
+					if (description == NULL)
+						description = g_strdup(&begin[1]);
+					else
+					{
+						gchar *oldval = description;
+						description = g_strconcat(oldval, "\n",&begin[1],NULL);
+						g_free(oldval);
+					}
+				}
+				else
+				{
+					gchar *colon = strchr(begin,':');
+					g_assert(colon!=NULL);
+					colon[0] = '\0';
+					colon+=2;
+					/*if (strlen(colon)>3000)
+						pk_error("strlen(colon) = %d\ncolon = %s",strlen(colon),colon);*/
+					//pk_debug("entry = '%s','%s'",begin,colon);
+					if (begin[0] == 'P' && g_strcasecmp("Package",begin)==0)
+					{
+						res=sqlite3_bind_text(package,FIELD_PKG,colon,-1,SQLITE_STATIC);
+						haspk = TRUE;
+						count++;
+						if (count%1000==0)
+							pk_debug("Package %ld (%s)",count,colon);
+					}
+					else if (begin[0] == 'V' && g_strcasecmp("Version",begin)==0)
+						res=sqlite3_bind_text(package,FIELD_VER,colon,-1,SQLITE_STATIC);
+					else if (begin[0] == 'D' && g_strcasecmp("Depends",begin)==0)
+						res=sqlite3_bind_text(package,FIELD_DEPS,colon,-1,SQLITE_STATIC);
+					else if (begin[0] == 'A' && g_strcasecmp("Architecture",begin)==0)
+						res=sqlite3_bind_text(package,FIELD_ARCH,colon,-1,SQLITE_STATIC);
+					else if (begin[0] == 'D' && g_strcasecmp("Description",begin)==0)
+						res=sqlite3_bind_text(package,FIELD_SHORT,colon,-1,SQLITE_STATIC);
+					if (res!=SQLITE_OK)
+						pk_error("sqlite error during %s bind: %s", begin, sqlite3_errmsg(db));
+				}
+				if (next == NULL)
+					break;
+				begin = next;
+			}
+			res = sqlite3_exec(db,"commit",NULL,NULL,NULL);
+			if (res!=SQLITE_OK)
+				pk_error("sqlite error during commit: %s", sqlite3_errmsg(db));
+			res = sqlite3_clear_bindings(package);
+			if (res!=SQLITE_OK)
+				pk_error("sqlite error during clear: %s", sqlite3_errmsg(db));
+			g_free(contents);
+			contents = NULL;
+		}
+	}
+	sqlite3_finalize(package);
+
+search_task_cleanup:
+	g_dir_close(dir);
+	g_free(sdir);
+	g_free(contents);
+}
+
diff --git a/backends/apt/pk-apt-search-sqlite.c b/backends/apt/pk-apt-search-sqlite.c
new file mode 100644
index 0000000..88784b5
--- /dev/null
+++ b/backends/apt/pk-apt-search-sqlite.c
@@ -0,0 +1,100 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Ali Sabil <ali.sabil at gmail.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <gmodule.h>
+#include <glib.h>
+#include <string.h>
+#include <pk-backend.h>
+#include "pk-sqlite-pkg-cache.h"
+
+/**
+ * backend_get_groups:
+ */
+void
+backend_get_groups (PkBackend *backend, PkEnumList *elist)
+{
+	g_return_if_fail (backend != NULL);
+	pk_enum_list_append_multiple (elist,
+				      PK_GROUP_ENUM_ACCESSORIES,
+				      PK_GROUP_ENUM_GAMES,
+				      PK_GROUP_ENUM_GRAPHICS,
+				      PK_GROUP_ENUM_INTERNET,
+				      PK_GROUP_ENUM_OFFICE,
+				      PK_GROUP_ENUM_OTHER,
+				      PK_GROUP_ENUM_PROGRAMMING,
+				      PK_GROUP_ENUM_MULTIMEDIA,
+				      PK_GROUP_ENUM_SYSTEM,
+				      -1);
+}
+
+/**
+ * backend_get_filters:
+ */
+void
+backend_get_filters (PkBackend *backend, PkEnumList *elist)
+{
+	g_return_if_fail (backend != NULL);
+	pk_enum_list_append_multiple (elist,
+				      PK_FILTER_ENUM_GUI,
+				      PK_FILTER_ENUM_INSTALLED,
+				      PK_FILTER_ENUM_DEVELOPMENT,
+				      -1);
+}
+
+/**
+ * backend_get_description:
+ */
+
+void
+backend_get_description (PkBackend *backend, const gchar *package_id)
+{
+	sqlite_get_description(backend,package_id);
+}
+
+/**
+ * backend_search_details:
+ */
+
+void
+backend_search_details (PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	sqlite_search_details(backend,filter,search);
+}
+
+/**
+ * backend_search_name:
+ */
+void
+backend_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	sqlite_search_name(backend,filter,search);
+}
+
+/**
+ * backend_search_group:
+ */
+void
+backend_search_group (PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	g_return_if_fail (backend != NULL);
+	pk_backend_allow_interrupt (backend, TRUE);
+	pk_backend_spawn_helper (backend, "search-group.py", filter, search, NULL);
+}
diff --git a/backends/apt/pk-sqlite-pkg-cache.c b/backends/apt/pk-sqlite-pkg-cache.c
new file mode 100644
index 0000000..c81f668
--- /dev/null
+++ b/backends/apt/pk-sqlite-pkg-cache.c
@@ -0,0 +1,243 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+#include <glib/gstdio.h>
+#include "pk-sqlite-pkg-cache.h"
+
+static sqlite3 *db = NULL;
+static gboolean(*is_installed) (const PkPackageId *) = NULL;
+
+void sqlite_set_installed_check(gboolean(*func) (const PkPackageId *))
+{
+	is_installed = func;
+}
+
+typedef struct {
+	PkPackageId *pi;
+} desc_task;
+
+typedef struct {
+	gchar *search;
+	gchar *filter;
+	SearchDepth depth;
+} search_task;
+
+void
+sqlite_init_cache(PkBackend *backend, const char* dbname, const char *compare_fname, void (*build_db)(PkBackend *, sqlite3 *))
+{
+	int ret;
+	struct stat st;
+	time_t db_age;
+
+	ret = sqlite3_open (dbname, &db);
+	ret = sqlite3_exec(db,"PRAGMA synchronous = OFF",NULL,NULL,NULL);
+	g_assert(ret == SQLITE_OK);
+
+	g_stat(dbname, &st);
+	db_age = st.st_mtime;
+	g_stat(compare_fname, &st);
+	if (db_age>=st.st_mtime)
+	{
+		ret = sqlite3_exec(db, "select value from params where name = 'build_complete'", NULL, NULL, NULL);
+		if (ret != SQLITE_ERROR)
+			return;
+	}
+	ret = sqlite3_exec(db,"drop table packages",NULL,NULL,NULL); // wipe it!
+	//g_assert(ret == SQLITE_OK);
+	pk_debug("wiped db");
+	ret = sqlite3_exec(db,"create table packages (name text, version text, deps text, arch text, short_desc text, long_desc text, repo string, primary key(name,version,arch,repo))",NULL,NULL,NULL);
+	g_assert(ret == SQLITE_OK);
+
+	build_db(backend,db);
+
+	sqlite3_exec(db,"create table params (name text primary key, value integer)", NULL, NULL, NULL);
+	sqlite3_exec(db,"insert into params values ('build_complete',1)", NULL, NULL, NULL);
+}
+
+// sqlite_search_packages_thread
+static gboolean
+sqlite_search_packages_thread (PkBackend *backend, gpointer data)
+{
+	search_task *st = (search_task *) data;
+	int res;
+	gchar *sel;
+
+	pk_backend_change_status(backend, PK_STATUS_ENUM_QUERY);
+	pk_backend_no_percentage_updates(backend);
+
+	pk_debug("finding %s", st->search);
+
+	sqlite3_stmt *package = NULL;
+	g_strdelimit(st->search," ",'%');
+
+	if (st->depth == SEARCH_NAME)
+		sel = g_strdup_printf("select name,version,arch,repo,short_desc from packages where name like '%%%s%%'",st->search);
+	else if (st->depth == SEARCH_DETAILS)
+		sel = g_strdup_printf("select name,version,arch,repo,short_desc from packages where name like '%%%s%%' or short_desc like '%%%s%%' or long_desc like '%%%s%%'",st->search, st->search, st->search);
+	else
+	{
+		pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Unknown search task type");
+		goto end_search_packages;
+	}
+
+	pk_debug("statement is '%s'",sel);
+	res = sqlite3_prepare_v2(db,sel, -1, &package, NULL);
+	g_free(sel);
+	if (res!=SQLITE_OK)
+		pk_error("sqlite error during select prepare: %s", sqlite3_errmsg(db));
+	res = sqlite3_step(package);
+	while (res == SQLITE_ROW)
+	{
+		PkPackageId *pid = pk_package_id_new_from_list((const gchar*)sqlite3_column_text(package,0),
+				(const gchar*)sqlite3_column_text(package,1),
+				(const gchar*)sqlite3_column_text(package,2),
+				(const gchar*)sqlite3_column_text(package,3));
+
+		gchar *cpid = pk_package_id_to_string(pid);
+		PkInfoEnum pie = PK_INFO_ENUM_UNKNOWN;
+
+		if (is_installed != NULL)
+			pie = is_installed(pid)?PK_INFO_ENUM_INSTALLED:PK_INFO_ENUM_AVAILABLE;
+
+		pk_backend_package(backend, pie, cpid, (const gchar*)sqlite3_column_text(package,4));
+
+		g_free(cpid);
+		pk_package_id_free(pid);
+
+		if (res==SQLITE_ROW)
+			res = sqlite3_step(package);
+	}
+	if (res!=SQLITE_DONE)
+	{
+		pk_debug("sqlite error during step (%d): %s", res, sqlite3_errmsg(db));
+		g_assert(0);
+	}
+
+	end_search_packages:
+	g_free(st->search);
+	g_free(st);
+
+	return TRUE;
+}
+
+/**
+ * backend_search_common
+ **/
+void
+backend_search_common(PkBackend * backend, const gchar * filter, const gchar * search, SearchDepth which, PkBackendThreadFunc func)
+{
+	g_return_if_fail (backend != NULL);
+	search_task *data = g_new(search_task, 1);
+	if (data == NULL)
+	{
+		pk_backend_error_code(backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory for search task");
+		pk_backend_finished(backend);
+	}
+	else
+	{
+		data->search = g_strdup(search);
+		data->filter = g_strdup(filter);
+		data->depth = which;
+		pk_backend_thread_helper (backend, func, data);
+	}
+}
+
+/**
+ * sqlite_search_details:
+ */
+void
+sqlite_search_details (PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	backend_search_common(backend, filter, search, SEARCH_DETAILS, sqlite_search_packages_thread);
+}
+
+/**
+ * sqlite_search_name:
+ */
+void
+sqlite_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	backend_search_common(backend, filter, search, SEARCH_NAME, sqlite_search_packages_thread);
+}
+
+// sqlite_get_description_thread
+static gboolean sqlite_get_description_thread (PkBackend *backend, gpointer data)
+{
+	desc_task *dt = (desc_task *) data;
+	int res;
+
+	pk_backend_change_status(backend, PK_STATUS_ENUM_QUERY);
+	pk_backend_no_percentage_updates(backend);
+
+	pk_debug("finding %s", dt->pi->name);
+
+	sqlite3_stmt *package = NULL;
+	gchar *sel = g_strdup_printf("select long_desc from packages where name = '%s' and version = '%s' and repo = '%s'",dt->pi->name,dt->pi->version,dt->pi->data);
+	pk_debug("statement is '%s'",sel);
+	res = sqlite3_prepare_v2(db,sel, -1, &package, NULL);
+	g_free(sel);
+	if (res!=SQLITE_OK)
+		pk_error("sqlite error during select prepare: %s", sqlite3_errmsg(db));
+	res = sqlite3_step(package);
+	pk_backend_description(backend,dt->pi->name, "unknown", PK_GROUP_ENUM_OTHER,(const gchar*)sqlite3_column_text(package,0),"",0,"");
+	res = sqlite3_step(package);
+	if (res==SQLITE_ROW)
+		pk_error("multiple matches for that package!");
+	if (res!=SQLITE_DONE)
+	{
+		pk_debug("sqlite error during step (%d): %s", res, sqlite3_errmsg(db));
+		g_assert(0);
+	}
+
+	g_free(dt);
+
+	return TRUE;
+}
+
+/**
+ * sqlite_get_description:
+ */
+void
+sqlite_get_description (PkBackend *backend, const gchar *package_id)
+{
+	g_return_if_fail (backend != NULL);
+	desc_task *data = g_new(desc_task, 1);
+	if (data == NULL)
+	{
+		pk_backend_error_code(backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory for search task");
+		pk_backend_finished(backend);
+		return;
+	}
+
+	data->pi = pk_package_id_new_from_string(package_id);
+	if (data->pi == NULL)
+	{
+		pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
+		pk_backend_finished(backend);
+		return;
+	}
+
+	pk_backend_thread_helper (backend, sqlite_get_description_thread, data);
+	return;
+}
+
+
diff --git a/backends/apt/pk-sqlite-pkg-cache.h b/backends/apt/pk-sqlite-pkg-cache.h
new file mode 100644
index 0000000..e568411
--- /dev/null
+++ b/backends/apt/pk-sqlite-pkg-cache.h
@@ -0,0 +1,40 @@
+#ifndef SQLITE_PKT_CACHE
+#define SQLITE_PKT_CACHE
+
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+typedef enum {
+	SEARCH_NAME = 1,
+	SEARCH_DETAILS,
+	SEARCH_FILE
+} SearchDepth;
+
+#include <pk-backend.h>
+#include <sqlite3.h>
+
+void sqlite_init_cache(PkBackend *backend, const char* dbname, const char* compare_fname, void (*build_db)(PkBackend *, sqlite3 *db));
+void sqlite_search_details (PkBackend *backend, const gchar *filter, const gchar *search);
+void sqlite_search_name (PkBackend *backend, const gchar *filter, const gchar *search);
+void backend_search_common(PkBackend * backend, const gchar * filter, const gchar * search, SearchDepth which, PkBackendThreadFunc func);
+void sqlite_get_description (PkBackend *backend, const gchar *package_id);
+
+#endif
diff --git a/configure.ac b/configure.ac
index ef864ba..f612e52 100755
--- a/configure.ac
+++ b/configure.ac
@@ -337,15 +337,18 @@ AC_DEFUN([APT_BACKEND],
 if test x$with_default_backend = xapt; then
 	PY_CHECK_MOD([apt_pkg],,,AC_MSG_ERROR([Apt backend needs python-apt]))
 
-	AC_ARG_WITH([aptsearch],
+	AC_ARG_WITH([apt_search],
 	    AS_HELP_STRING([--with-apt-search=<option>],
-			   [Apt search type to use - plain (plain)]))
-	if test x$with_aptsearch = x; then
-		with_aptsearch=plain
+			   [Apt search type to use - plain,sqlite (plain)]))
+
+	if test x$with_apt_search = x; then
+		with_apt_search=plain
 	fi
-	AC_DEFINE_UNQUOTED(APT_SEARCH, "$with_aptsearch", [apt search type])
-	AC_SUBST(APT_SEARCH, "$with_aptsearch")
-	AM_CONDITIONAL(APT_SEARCH_PLAIN, [test x$with_aptsearch = xplain], [using plain apt search])
+    AC_MSG_NOTICE([using $with_apt_search for apt searching])
+	AC_DEFINE_UNQUOTED(APT_SEARCH, "$with_apt_search", [apt search type])
+	AC_SUBST(APT_SEARCH, $with_apt_search)
+	AM_CONDITIONAL(APT_SEARCH_PLAIN, [test x$with_apt_search = xplain], [using plain apt search])
+	AM_CONDITIONAL(APT_SEARCH_SQLITE, [test x$with_apt_search = xsqlite], [using sqlite apt search])
 
    AC_ARG_WITH(libapt-pkg-lib,
 	 AC_HELP_STRING([--with-libapt-pkg-lib=DIR],[look for the libapt-pkg library in DIR]),
@@ -411,6 +414,7 @@ if test x$with_default_backend = xapt; then
 	AC_SUBST(APT_PKG_TYPE)
 else
 	AM_CONDITIONAL(APT_SEARCH_PLAIN, [false])
+	AM_CONDITIONAL(APT_SEARCH_SQLITE, [false])
 fi
 
 if test x$with_default_backend = xbox; then
commit a1def4542b5bfb80dbf19b9ab3c8b24df7c04910
Author: Tom Parker <palfrey at tevp.net>
Date:   Thu Nov 15 19:39:01 2007 +0100

    Remove some of the old crap in apt.old

diff --git a/backends/apt.old/helpers/.gitignore b/backends/apt.old/helpers/.gitignore
deleted file mode 100644
index d18402d..0000000
--- a/backends/apt.old/helpers/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-*.pyc
-.*.swp
diff --git a/backends/apt.old/helpers/Makefile.am b/backends/apt.old/helpers/Makefile.am
deleted file mode 100644
index c14397e..0000000
--- a/backends/apt.old/helpers/Makefile.am
+++ /dev/null
@@ -1,16 +0,0 @@
-
-helperdir = $(datadir)/PackageKit/helpers/apt
-
-NULL =
-
-dist_helper_DATA = 			\
-	refresh-cache.py		\
-	aptBackend.py			\
-	$(NULL)
-
-install-data-hook:
-	chmod a+rx $(DESTDIR)$(helperdir)/*.py
-
-clean-local :
-	rm -f *~
-
diff --git a/backends/apt.old/helpers/aptBackend.py b/backends/apt.old/helpers/aptBackend.py
deleted file mode 100644
index d0f370a..0000000
--- a/backends/apt.old/helpers/aptBackend.py
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/usr/bin/python
-
-# 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
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Library General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
-
-from packagekit.backend import *
-import apt
-
-class PackageKitProgress(apt.progress.OpProgress, apt.progress.FetchProgress):
-	def __init__(self, backend):
-		self.backend = backend
-
-	# OpProgress callbacks
-	def update(self, percent):
-		self.backend.percentage(percent)
-
-	def done(self):
-		self.backend.percentage(50.0)
-
-	# FetchProgress callbacks
-	def pulse(self):
-		apt.progress.FetchProgress.pulse(self)
-		self.backend.percentage(self.percent)
-
-	def stop(self):
-		print "self.inc (stop)"
-		self.backend.percentage(100)
-
-	def mediaChange(self, medium, drive):
-		self.backend.error(ERROR_INTERNAL_ERROR, "Needed to do a medium change!")
-
-class PackageKitAptBackend(PackageKitBaseBackend):
-	def refresh_cache(self):
-		'''
-		Implement the {backend}-refresh_cache functionality
-		'''
-		self.percentage(0)
-		pkp = PackageKitProgress(self)
-		cache = apt.Cache(pkp)
-		if cache.update(pkp) == False:
-			self.error(ERROR_INTERNAL_ERROR,"Fetch failure")
-
diff --git a/backends/apt.old/helpers/refresh-cache.py b/backends/apt.old/helpers/refresh-cache.py
deleted file mode 100755
index 5feb6e5..0000000
--- a/backends/apt.old/helpers/refresh-cache.py
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/python
-#
-# Apt refresh-cache handler. Modified from the yum handler
-#
-# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
-# Copyright (C) 2007 Red Hat Inc, Seth Vidal <skvidal at fedoraproject.org>
-# Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
-#
-# Licensed under the GNU General Public License Version 2
-#
-# 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
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-
-import sys
-
-from aptBackend import PackageKitAptBackend
-
-backend = PackageKitAptBackend(sys.argv[1:])
-backend.refresh_cache()
-sys.exit(0)
diff --git a/backends/apt.old/pk-python-backend-common.c b/backends/apt.old/pk-python-backend-common.c
deleted file mode 100644
index 41b3788..0000000
--- a/backends/apt.old/pk-python-backend-common.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include <pk-backend.h>
-
-/**
- * python_refresh_cache:
- **/
-void python_refresh_cache(PkBackend * backend, gboolean force)
-{
-	/* check network state */
-	if (pk_backend_network_is_online(backend) == FALSE)
-	{
-		pk_backend_error_code(backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot refresh cache whilst offline");
-		pk_backend_finished(backend);
-		return;
-	}
-
-	pk_backend_spawn_helper (backend, "refresh-cache.py", NULL);
-}
-
diff --git a/backends/apt.old/pk-python-backend-common.h b/backends/apt.old/pk-python-backend-common.h
deleted file mode 100644
index a0b56bd..0000000
--- a/backends/apt.old/pk-python-backend-common.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef PYTHON_BACKEND_COMMON_H
-#define PYTHON_BACKEND_COMMON_H
-
-void python_refresh_cache(PkBackend * backend, gboolean force);
-
-#endif
-
commit b8bf638248106f2c236ee12c060b31f5f4720866
Author: Tom Parker <palfrey at tevp.net>
Date:   Wed Nov 7 19:27:47 2007 +0100

    Initial work with get depends

diff --git a/backends/apt/helpers/aptBackend.py b/backends/apt/helpers/aptBackend.py
index 7ec925c..7a31786 100644
--- a/backends/apt/helpers/aptBackend.py
+++ b/backends/apt/helpers/aptBackend.py
@@ -1,5 +1,8 @@
 #
+# vim: ts=4 et sts=4
+#
 # Copyright (C) 2007 Ali Sabil <ali.sabil at gmail.com>
+# Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
 #
 # Licensed under the GNU General Public License Version 2
 #
@@ -225,7 +228,17 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         pkg = Package(self._apt_cache[name], self)
         self._emit_package(pkg)
 
-    ### Helpers ###
+    def get_depends(self,package):
+        '''
+        Implement the {backend}-get-depends functionality
+        '''
+        name, version, arch, data = self.get_package_from_id(package)
+        pkg = Package(self._apt_cache[name], self)
+        print dir(pkg)
+        print dir(pkg._depcache)
+        raise Exception
+
+  ### Helpers ###
     def _emit_package(self, package):
         id = self.get_package_id(package.name,
                 package.installed_version or package.candidate_version,
diff --git a/backends/apt/helpers/get-depends.py b/backends/apt/helpers/get-depends.py
new file mode 100755
index 0000000..b586a18
--- /dev/null
+++ b/backends/apt/helpers/get-depends.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+#
+# Licensed under the GNU General Public License Version 2
+#
+# 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+import sys
+
+from aptBackend import PackageKitAptBackend
+package=sys.argv[1]
+backend = PackageKitAptBackend(sys.argv[1:])
+backend.get_depends(package)
+sys.exit(0)
commit a4ef3337e5439a2115522385b7282a2ba610faa2
Author: Luke Macken <lmacken at redhat.com>
Date:   Sun Dec 16 18:26:42 2007 -0500

    Remove some unused variables from the yumBackend

diff --git a/backends/yum/helpers/yumBackend.py b/backends/yum/helpers/yumBackend.py
index 4a8efc6..f89f95a 100644
--- a/backends/yum/helpers/yumBackend.py
+++ b/backends/yum/helpers/yumBackend.py
@@ -527,7 +527,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.allow_interrupt(True)
         self.percentage(None)
         self.status(STATUS_INFO)
-        name = package.split(';')[0]
         pkg,inst = self._findPackage(package)
         pkgs = self.yumbase.rpmdb.searchRequires(pkg.name)
         for pkg in pkgs:
@@ -1085,7 +1084,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.allow_interrupt(True)
         self.percentage(None)
         self.status(STATUS_INFO)
-        name = package.split(';')[0]
         pkg,inst = self._findPackage(package)
         update = self._get_updated(pkg)
         obsolete = self._get_obsoleted(pkg.name)



More information about the PackageKit mailing list