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

Richard Hughes hughsient at kemper.freedesktop.org
Tue Dec 11 09:16:41 PST 2007


 backends/apt/helpers/aptBackend.py |  122 +-----------
 backends/zypp/pk-backend-zypp.cpp  |  355 ++++++++++++++++++++++++++++++++++---
 backends/zypp/zypp-utils.cpp       |   33 +++
 backends/zypp/zypp-utils.h         |    9 
 configure.ac                       |    6 
 src/pk-security-polkit.c           |    2 
 6 files changed, 395 insertions(+), 132 deletions(-)

New commits:
commit 45e9c01bff7ed4aefef810ae897fc3b9662210fa
Author: S.Çağlar Onur <caglar at pardus.org.tr>
Date:   Mon Dec 10 13:30:10 2007 +0200

    FROM: Matthias Clasen <matthias.clasen at gmail.com>
    
    Thanks to the wonders of -Werror, PackageKit won't build against PolicyKit 0.7 cause "polkit_context_can_caller_do_action" is deprecated.

diff --git a/configure.ac b/configure.ac
index a15e478..fb7b697 100755
--- a/configure.ac
+++ b/configure.ac
@@ -57,8 +57,8 @@ GLIB_REQUIRED=2.14.0
 DBUS_REQUIRED=1.1.1
 DBUS_GLIB_REQUIRED=0.73
 LIBNM_GLIB_REQUIRED=0.6.4
-POLKIT_DBUS_REQUIRED=0.5
-POLKIT_GRANT_REQUIRED=0.5
+POLKIT_DBUS_REQUIRED=0.7
+POLKIT_GRANT_REQUIRED=0.7
 
 dnl ---------------------------------------------------------------------------
 dnl - Make above strings available for packaging files (e.g. rpm spec files)
@@ -229,7 +229,7 @@ AC_ARG_WITH([security_framework],
 			   [Default security framework to use polkit,dummy]))
 # try and guess this if nothing is listed
 if test x$with_security_framework = x; then
-	if test -f /usr/bin/polkit-list-actions ; then
+	if test -f /usr/bin/polkit-action ; then
 		with_security_framework=polkit
 	else
 		AC_MSG_ERROR([--with-security-framework explicitly required when not using PolicyKit or RBAC])
diff --git a/src/pk-security-polkit.c b/src/pk-security-polkit.c
index 971e43c..27c4442 100644
--- a/src/pk-security-polkit.c
+++ b/src/pk-security-polkit.c
@@ -84,7 +84,7 @@ pk_security_can_do_action (PkSecurity *security, const gchar *dbus_sender, const
 		return POLKIT_RESULT_NO;
 	}
 
-	pk_result = polkit_context_can_caller_do_action (security->priv->pk_context, pk_action, pk_caller);
+	pk_result = polkit_context_is_caller_authorized (security->priv->pk_context, pk_action, pk_caller, TRUE, NULL);
 	pk_debug ("PolicyKit result = '%s'", polkit_result_to_string_representation (pk_result));
 
 	polkit_action_unref (pk_action);
commit d3c2a626d301a129b79d5ce2e4e78255c161868c
Author: Boyd Timothy <boyd at bht-lenovo.provo.novell.com>
Date:   Fri Dec 7 10:55:20 2007 -0700

    Added a bunch of code to kind of pull off backend_get_depends() for zypp backend.

diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp
index 78c9541..df9bcee 100644
--- a/backends/zypp/pk-backend-zypp.cpp
+++ b/backends/zypp/pk-backend-zypp.cpp
@@ -57,6 +57,11 @@ enum PkgSearchType {
 	SEARCH_TYPE_RESOLVE = 3
 };
 
+enum DepsType {
+	DEPS_TYPE_DEPENDS = 0,
+	DEPS_TYPE_REQUIRES = 1
+};
+
 enum DepsBehavior {
 	DEPS_ALLOW = 0,
 	DEPS_NO_ALLOW = 1
@@ -120,6 +125,205 @@ fprintf (stderr, "\n\n*** zypp_backend_destroy ***\n\n");
 	}
 }
 
+/**
+ * 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_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,
+				      PK_GROUP_ENUM_PUBLISHING,
+				      PK_GROUP_ENUM_SERVERS,
+				      PK_GROUP_ENUM_FONTS,
+				      PK_GROUP_ENUM_ADMIN_TOOLS,
+				      PK_GROUP_ENUM_LOCALIZATION,
+				      PK_GROUP_ENUM_SECURITY,
+				      -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_get_depends_thread (PkBackend *backend, gpointer data)
+{
+	// Note: I talked with duncanmv in #zypp and he suggested the
+	// way we could suppor this method would be to mark the desired
+	// package to be installed, run the dependency solver, and then
+	// check the other packages that got marked to install:
+/*
+08:55 < duncanmv> run the solver
+08:56 < duncanmv> and then iterate the poll and look packages which status isBySolver() true
+08:56 < duncanmv> which are the packages marked by the solver
+08:56 < duncanmv> you can say that status toBeInstalled() and bySolver are requires
+*/
+	ThreadData *d = (ThreadData*) data;
+
+	pk_backend_change_status (backend, PK_STATUS_ENUM_QUERY);
+	pk_backend_change_percentage (backend, 0);
+
+	PkPackageId *pi = pk_package_id_new_from_string (d->package_id);
+        if (pi == NULL) {
+                pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
+		g_free (d->package_id);
+		g_free (d);
+		pk_backend_finished (backend);
+                return FALSE;
+        }
+
+	zypp::ZYpp::Ptr zypp;
+	zypp = get_zypp ();
+
+	// Load resolvables from all the enabled repositories
+	zypp::RepoManager manager;
+	std::list <zypp::RepoInfo> repos;
+	try
+	{
+		// TODO: Split the code up so it's not all just in one bit try/catch
+
+		repos = manager.knownRepositories();
+		for (std::list <zypp::RepoInfo>::iterator it = repos.begin(); it != repos.end(); it++) {
+			zypp::RepoInfo repo (*it);
+
+			// skip disabled repos
+			if (repo.enabled () == false)
+				continue;
+
+			zypp::Repository repository = manager.createFromCache (*it);
+			zypp->addResolvables (repository.resolvables ());
+		}
+
+		zypp::PoolItem_Ref pool_item;
+		gboolean pool_item_found = FALSE;
+		// Iterate over the resolvables and mark the one we want to check its dependencies
+		for (zypp::ResPoolProxy::const_iterator it = zypp->poolProxy().byKindBegin <zypp::Package>();
+				it != zypp->poolProxy().byKindEnd <zypp::Package>(); it++) {
+			zypp::ui::Selectable::Ptr selectable = *it;
+			if (strcmp (selectable->name().c_str(), pi->name) == 0) {
+				// This package matches the name we're looking for and
+				// is available for update/install.
+				zypp::ResObject::constPtr installable = selectable->candidateObj();
+				const char *edition_str = installable->edition().asString().c_str();
+
+				if (strcmp (edition_str, pi->version) == 0) {
+					// this is the one, mark it to be installed
+					selectable->set_status (zypp::ui::S_Install);
+fprintf (stderr, "\n\n *** marked a package!!! ***\n\n");
+					pool_item = selectable->candidatePoolItem ();
+					pool_item_found = TRUE;
+					break; // Found it, get out of the for loop
+				}
+			}
+		}
+
+		pk_backend_change_percentage (backend, 40);
+
+		if (pool_item_found == FALSE) {
+			pk_backend_error_code (backend, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, "Did not find the specified package.");
+			g_free (d->package_id);
+			g_free (d);
+			pk_backend_finished (backend);
+        	        return FALSE;
+		}
+
+//printf ("Resolving dependencies...\n");
+		// Gather up any dependencies
+		pk_backend_change_status (backend, PK_STATUS_ENUM_DEP_RESOLVE);
+		if (zypp->resolver ()->resolvePool () == FALSE) {
+			// Manual intervention required to resolve dependencies
+			// TODO: Figure out what we need to do with PackageKit
+			// to pull off interactive problem solving.
+			pk_backend_error_code (backend, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, "Couldn't resolve the package dependencies.");
+			g_free (d->package_id);
+			g_free (d);
+			pk_package_id_free (pi);
+			pk_backend_finished (backend);
+			return FALSE;
+		}
+
+		pk_backend_change_percentage (backend, 60);
+
+		zypp::solver::detail::ItemCapKindList installList = zypp->resolver ()->installs (pool_item);
+		for (zypp::solver::detail::ItemCapKindList::const_iterator it = installList.begin ();
+				it != installList.end ();
+				++it) {
+			gchar *package_id;
+			package_id = pk_package_id_build (it->item->name ().c_str (),
+							  it->item->edition ().asString ().c_str (),
+							  it->item->arch ().asString ().c_str (),
+							  "opensuse");
+			pk_backend_package (backend,
+				PK_INFO_ENUM_AVAILABLE, // TODO: Figure out how to determine whether a package is installed or not
+				package_id,
+				"TODO: Figure out how to get a package description here.");
+			g_free (package_id);
+		}
+
+		pk_backend_change_percentage (backend, 100);
+	} catch (const zypp::repo::RepoNotFoundException &ex) {
+		// TODO: make sure this dumps out the right sring.
+		pk_backend_error_code (backend, PK_ERROR_ENUM_REPO_NOT_FOUND, ex.asUserString().c_str() );
+		g_free (d->package_id);
+		g_free (d);
+		pk_package_id_free (pi);
+		pk_backend_finished (backend);
+		return FALSE;
+	} catch (const zypp::Exception &ex) {
+		//pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Error enumerating repositories");
+		pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asUserString().c_str() );
+		g_free (d->package_id);
+		g_free (d);
+		pk_package_id_free (pi);
+		pk_backend_finished (backend);
+		return FALSE;
+	}
+
+	g_free (d->package_id);
+	g_free (d);
+	pk_backend_finished (backend);
+	return TRUE;
+}
+
+
+/**
+ * backend_get_depends:
+ */
+static void
+backend_get_depends (PkBackend *backend, const gchar *package_id, gboolean recursive)
+{
+	g_return_if_fail (backend != NULL);
+	ThreadData *data = g_new0(ThreadData, 1);
+	if (data == NULL) {
+		pk_backend_error_code (backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory");
+		pk_backend_finished (backend);
+		return;
+	}
+
+	data->package_id = g_strdup (package_id);
+	data->type = DEPS_TYPE_DEPENDS;
+	pk_backend_thread_create (backend, backend_get_depends_thread, data);
+}
+
 static gboolean
 backend_get_description_thread (PkBackend *backend, gpointer data)
 {
@@ -831,10 +1035,10 @@ extern "C" PK_BACKEND_OPTIONS (
 	"Boyd Timothy <btimothy at gmail.com>, Scott Reeves <sreeves at novell.com>",	/* author */
 	backend_initialize,			/* initalize */
 	backend_destroy,			/* destroy */
-	NULL,					/* get_groups */
-	NULL,					/* get_filters */
+	backend_get_groups,			/* get_groups */
+	backend_get_filters,			/* get_filters */
 	NULL,					/* cancel */
-	NULL,					/* get_depends */
+	backend_get_depends,			/* get_depends */
 	backend_get_description,		/* get_description */
 	NULL,					/* get_files */
 	NULL,					/* get_requires */
diff --git a/backends/zypp/zypp-utils.cpp b/backends/zypp/zypp-utils.cpp
index f4e5667..43e85b9 100644
--- a/backends/zypp/zypp-utils.cpp
+++ b/backends/zypp/zypp-utils.cpp
@@ -112,10 +112,35 @@ zypp_get_packages_by_name (const gchar *package_name, gboolean include_local)
 	return v;
 }
 
-/**
- * Build a package_id from the specified resolvable.  The returned
- * gchar * should be freed with g_free ().
- */
+zypp::Resolvable::constPtr
+zypp_get_package_by_id (const gchar *package_id)
+{
+	PkPackageId *pi;
+	pi = pk_package_id_new_from_string (package_id);
+	if (pi == NULL) {
+		// TODO: Do we need to do something more for this error?
+		return NULL;
+	}
+
+	std::vector<zypp::PoolItem> *v = zypp_get_packages_by_name (pi->name, TRUE);
+	if (v == NULL)
+		return NULL;
+
+	zypp::ResObject::constPtr package = NULL;
+	for (std::vector<zypp::PoolItem>::iterator it = v->begin ();
+			it != v->end (); it++) {
+		zypp::ResObject::constPtr pkg = (*it);
+		const char *version = pkg->edition ().asString ().c_str ();
+		if (strcmp (pi->version, version) == 0) {
+			package = pkg;
+			break;
+		}
+	}
+
+	delete (v);
+	return package;
+}
+
 gchar *
 zypp_build_package_id_from_resolvable (zypp::Resolvable::constPtr resolvable)
 {
diff --git a/backends/zypp/zypp-utils.h b/backends/zypp/zypp-utils.h
index a68834e..7e96c6e 100644
--- a/backends/zypp/zypp-utils.h
+++ b/backends/zypp/zypp-utils.h
@@ -38,6 +38,15 @@ zypp::ResPool zypp_build_pool (gboolean include_local);
  */
 std::vector<zypp::PoolItem> * zypp_get_packages_by_name (const gchar *package_name, gboolean include_local);
 
+/**
+ * Returns the Resolvable for the specified package_id.
+ */
+zypp::Resolvable::constPtr zypp_get_package_by_id (const gchar *package_id);
+
+/**
+ * Build a package_id from the specified resolvable.  The returned
+ * gchar * should be freed with g_free ().
+ */
 gchar * zypp_build_package_id_from_resolvable (zypp::Resolvable::constPtr resolvable);
 
 void zypp_emit_packages_in_list (PkBackend *backend, std::vector<zypp::PoolItem> *v);
commit f3a30fc34790fa4f8ddcb7ab7c1cd291c269f081
Author: Boyd Timothy <btimothy at gmail.com>
Date:   Tue Dec 4 10:54:44 2007 -0700

    Added initial version of backend_remove_package() for zypp backend.

diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp
index 58be21f..78c9541 100644
--- a/backends/zypp/pk-backend-zypp.cpp
+++ b/backends/zypp/pk-backend-zypp.cpp
@@ -57,6 +57,11 @@ enum PkgSearchType {
 	SEARCH_TYPE_RESOLVE = 3
 };
 
+enum DepsBehavior {
+	DEPS_ALLOW = 0,
+	DEPS_NO_ALLOW = 1
+};
+
 typedef struct {
 	gchar *search;
 	gchar *filter;
@@ -68,23 +73,6 @@ typedef struct {
 	gchar *filter;
 } ResolveData;
 
-/* make sure and keep the struct in sync with the enum */
-enum SqlQuerySchema {
-	SQL_NAME = 0,
-	SQL_VERSION,
-	SQL_RELEASE,
-	SQL_REPO,
-	SQL_ARCH
-};
-
-typedef struct {
-	gchar *name;
-	gchar *version;
-	gchar *release;
-	gchar *repo;
-	gchar *arch;
-} SQLData;
-
 typedef struct {
 	gchar *package_id;
 	gint type;
@@ -94,6 +82,11 @@ typedef struct {
 	gboolean force;
 } RefreshData;
 
+typedef struct {
+	gchar *package_id;
+	gint deps_behavior;
+} RemovePackageData;
+
 /**
  * A map to keep track of the EventDirector objects for
  * each zypp backend that is created.
@@ -425,6 +418,122 @@ fprintf (stderr, "\n\n *** Building cache ***\n\n");
 	return TRUE;
 }
 
+static gboolean
+backend_remove_package_thread (PkBackend *backend, gpointer data)
+{
+	RemovePackageData *d = (RemovePackageData *)data;
+	PkPackageId *pi;
+
+	pk_backend_change_status (backend, PK_STATUS_ENUM_REMOVE);
+	pk_backend_change_percentage (backend, 0);
+
+	pi = pk_package_id_new_from_string (d->package_id);
+	if (pi == NULL) {
+		pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
+		g_free (d->package_id);
+		g_free (d);
+		pk_backend_finished (backend);
+		return FALSE;
+	}
+
+	zypp::Target_Ptr target;
+
+	zypp::ZYpp::Ptr zypp;
+	zypp = get_zypp ();
+
+	target = zypp->target ();
+
+	// Load all the local system "resolvables" (packages)
+	zypp->addResolvables (target->resolvables(), TRUE);
+	pk_backend_change_percentage (backend, 10);
+
+	zypp::RepoManager manager;
+	std::list <zypp::RepoInfo> repos;
+	try
+	{
+		// Iterate over the resolvables and mark the ones we want to remove
+		//zypp->start ();
+		for (zypp::ResPoolProxy::const_iterator it = zypp->poolProxy().byKindBegin <zypp::Package>();
+				it != zypp->poolProxy().byKindEnd <zypp::Package>(); it++) {
+			zypp::ui::Selectable::Ptr selectable = *it;
+			if (strcmp (selectable->name().c_str(), pi->name) == 0) {
+				if (selectable->status () == zypp::ui::S_KeepInstalled) {
+					selectable->set_status (zypp::ui::S_Del);
+					break;
+				}
+			}
+		}
+
+		pk_backend_change_percentage (backend, 40);
+
+//printf ("Resolving dependencies...\n");
+// TODO: Figure out what to do about d->deps_behavior
+		// Gather up any dependencies
+		pk_backend_change_status (backend, PK_STATUS_ENUM_DEP_RESOLVE);
+		if (zypp->resolver ()->resolvePool () == FALSE) {
+			// Manual intervention required to resolve dependencies
+			// TODO: Figure out what we need to do with PackageKit
+			// to pull off interactive problem solving.
+			pk_backend_error_code (backend, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, "Couldn't resolve the package dependencies.");
+			g_free (d->package_id);
+			g_free (d);
+			pk_package_id_free (pi);
+			pk_backend_finished (backend);
+			return FALSE;
+		}
+
+		pk_backend_change_percentage (backend, 60);
+
+		zypp::ZYppCommitPolicy policy;
+		zypp::ZYppCommitResult result = zypp->commit (policy);
+printf ("Finished the removal.\n");
+
+		pk_backend_change_percentage (backend, 100);
+
+		// TODO: Check result for success
+	} catch (const zypp::repo::RepoNotFoundException &ex) {
+		// TODO: make sure this dumps out the right sring.
+		pk_backend_error_code (backend, PK_ERROR_ENUM_REPO_NOT_FOUND, ex.asUserString().c_str() );
+		g_free (d->package_id);
+		g_free (d);
+		pk_package_id_free (pi);
+		pk_backend_finished (backend);
+		return FALSE;
+	} catch (const zypp::Exception &ex) {
+		//pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Error enumerating repositories");
+		pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asUserString().c_str() );
+		g_free (d->package_id);
+		g_free (d);
+		pk_package_id_free (pi);
+		pk_backend_finished (backend);
+		return FALSE;
+	}
+
+	
+
+	g_free (d->package_id);
+	g_free (d);
+	pk_package_id_free (pi);
+	pk_backend_finished (backend);
+	return TRUE;
+}
+
+
+/**
+ * backend_remove_package:
+ */
+static void
+backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean allow_deps)
+{
+	g_return_if_fail (backend != NULL);
+
+	RemovePackageData *data = g_new0 (RemovePackageData, 1);
+	data->package_id = g_strdup (package_id);
+	data->deps_behavior = allow_deps == TRUE ? DEPS_ALLOW : DEPS_NO_ALLOW;
+
+	pk_backend_thread_create (backend, backend_remove_package_thread, data);
+}
+
 /**
  * backend_refresh_cache
  */
@@ -734,7 +843,7 @@ extern "C" PK_BACKEND_OPTIONS (
 	backend_install_package,		/* install_package */
 	NULL,					/* install_file */
 	backend_refresh_cache,			/* refresh_cache */
-	NULL,					/* remove_package */
+	backend_remove_package,			/* remove_package */
 	backend_resolve,			/* resolve */
 	NULL,					/* rollback */
 	NULL,					/* search_details */
commit 279c02428837750693a16bc382f94a1936d73d63
Author: Tom Parker <palfrey at tevp.net>
Date:   Tue Dec 4 13:07:42 2007 +0100

    Commit Michael Vogt's cleanup patch for apt backend

diff --git a/backends/apt/helpers/aptBackend.py b/backends/apt/helpers/aptBackend.py
index 269dc6e..7ec925c 100644
--- a/backends/apt/helpers/aptBackend.py
+++ b/backends/apt/helpers/aptBackend.py
@@ -24,61 +24,30 @@ _HYPHEN_PATTERN = re.compile(r'(\s|_)+')
 class Package(object):
     def __init__(self, pkg, backend):
         self._pkg = pkg
-        self._cache = backend._apt_cache
-        self._depcache = backend._apt_dep_cache
-        self._records = backend._apt_records
 
     @property
     def id(self):
-        return self._pkg.ID
+        return self._pkg.id
 
     @property
     def name(self):
-        return self._pkg.Name
+        return self._pkg.name
 
     @property
     def summary(self):
-        if not self._seek_records():
-            return ""
-        ver = self._depcache.GetCandidateVer(self._pkg)
-        desc_iter = ver.TranslatedDescription
-        self._records.Lookup(desc_iter.FileList.pop(0))
-        return self._records.ShortDesc
+        return self._pkg.summary
 
     @property
     def description(self):
-        if not self._seek_records():
-            return ""
-        # get the translated description
-        ver = self._depcache.GetCandidateVer(self._pkg)
-        desc_iter = ver.TranslatedDescription
-        self._records.Lookup(desc_iter.FileList.pop(0))
-        desc = ""
-        try:
-            s = unicode(self._records.LongDesc,"utf-8")
-        except UnicodeDecodeError, e:
-            s = _("Invalid unicode in description for '%s' (%s). "
-                  "Please report.") % (self.name, e)
-        for line in s.splitlines():
-                tmp = line.strip()
-                if tmp == ".":
-                    desc += "\n"
-                else:
-                    desc += tmp + "\n"
-        return desc
+        return self._pkg.description
 
     @property
     def architecture(self):
-        if not self._seek_records():
-            return None
-        sec = apt_pkg.ParseSection(self._records.Record)
-        if sec.has_key("Architecture"):
-            return sec["Architecture"]
-        return None
+        return self._pkg.architecture
 
     @property
     def section(self):
-        return self._pkg.Section
+        return self._pkg.section
 
     @property
     def group(self):
@@ -109,27 +78,19 @@ class Package(object):
 
     @property
     def installed_version(self):
-        version = self._pkg.CurrentVer
-        if version != None:
-            return version.VerStr
-        else:
-            return None
+        return self._pkg.installedVersion
 
     @property
     def candidate_version(self):
-        version = self._depcache.GetCandidateVer(self._pkg)
-        if version != None:
-            return version.VerStr
-        else:
-            return None
+        return self._pkg.candidateVersion
 
     @property
     def is_installed(self):
-        return (self._pkg.CurrentVer != None)
+        return self._pkg.isInstalled
 
     @property
     def is_upgradable(self):
-        return self.is_installed and self._depcache.IsUpgradable(self._pkg)
+        return self._pkg.isUpgradable
 
     @property
     def is_development(self):
@@ -168,20 +129,6 @@ class Package(object):
             return True
         return False
 
-    ### Helpers ###
-    def _seek_records(self, use_candidate=True):
-        if use_candidate:
-            version = self._depcache.GetCandidateVer(self._pkg)
-        else:
-            version = self._pkg.CurrentVer
-
-        # check if we found a version
-        if version == None or version.FileList == None:
-            return False
-        self._records.Lookup(version.FileList.pop(0))
-        return True
-
-
 class PackageKitProgress(apt.progress.OpProgress, apt.progress.FetchProgress):
     def __init__(self, backend):
         self._backend = backend
@@ -212,11 +159,7 @@ class PackageKitProgress(apt.progress.OpProgress, apt.progress.FetchProgress):
 class PackageKitAptBackend(PackageKitBaseBackend):
     def __init__(self, args):
         PackageKitBaseBackend.__init__(self, args)
-        self._apt_cache = apt_pkg.GetCache(PackageKitProgress(self))
-        self._apt_dep_cache = apt_pkg.GetDepCache(self._apt_cache)
-        self._apt_records = apt_pkg.GetPkgRecords(self._apt_cache)
-        self._apt_list = apt_pkg.GetPkgSourceList()
-        self._apt_list.ReadMainList()
+        self._apt_cache = apt.Cache(PackageKitProgress(self))
 
     def search_name(self, filters, key):
         '''
@@ -259,19 +202,12 @@ class PackageKitAptBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-refresh_cache functionality
         '''
-        lockfile = apt_pkg.Config.FindDir("Dir::State::Lists") + "lock"
-        lock = apt_pkg.GetLock(lockfile)
-        if lock < 0:
-            self.error(ERROR_INTERNAL_ERROR,
-                    "Failed to acquire the lock")
-
         try:
-            fetcher = apt_pkg.GetAcquire(PackageKitProgress(self))
-            # this can throw a exception
-            self._apt_list.GetIndexes(fetcher)
-            self._do_fetch(fetcher)
-        finally:
-            os.close(lock)
+            res = self._apt_cache.update(PackageKitProgress(self))
+        except Exception, error_message:
+             self.error(ERROR_INTERNAL_ERROR,
+                        "Failed to fetch the following items:\n%s" % error_message)
+        return res
 
     def get_description(self, package):
         '''
@@ -304,9 +240,9 @@ class PackageKitAptBackend(PackageKitBaseBackend):
 
     def _do_search(self, filters, condition):
         filters = filters.split(';')
-        size = len(self._apt_cache.Packages)
+        size = len(self._apt_cache)
         percentage = 0
-        for i, pkg in enumerate(self._apt_cache.Packages):
+        for i, pkg in enumerate(self._apt_cache):
             new_percentage = i / float(size) * 100
             if new_percentage - percentage >= 5:
                 percentage = new_percentage
@@ -322,26 +258,6 @@ class PackageKitAptBackend(PackageKitBaseBackend):
             yield package
         self.percentage(100)
 
-    def _do_fetch(self, fetcher):
-        result = fetcher.Run()
-        failed = False
-        transient = False
-        error_message = ""
-        for item in fetcher.Items:
-            if item.Status == item.StatDone:
-                continue
-            if item.StatIdle:
-                transient = True
-                continue
-            error_message += "%s %s\n" % \
-                    (item.DescURI, item.ErrorText)
-            failed = True
-
-        # we raise a exception if the download failed or it was cancelt
-        if failed:
-            self.error(ERROR_INTERNAL_ERROR,
-                    "Failed to fetch the following items:\n%s" % error_message)
-        return (result == fetcher.ResultContinue)
 
     def _do_filtering(self, package, filters):
         if len(filters) == 0 or filters == ['none']:
@@ -358,5 +274,5 @@ class PackageKitAptBackend(PackageKitBaseBackend):
             return False
         if (FILTER_NOT_DEVELOPMENT in filters) and package.is_development:
             return False
-        return TRUE
+        return True
 



More information about the PackageKit mailing list