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

Richard Hughes hughsient at kemper.freedesktop.org
Thu Jan 24 11:11:05 PST 2008


 backends/Makefile.am          |    6 +
 backends/apt/pk-backend-apt.c |  193 +++++++++++++++++++++++++++++++++++++++---
 configure.ac                  |   65 ++++++++++----
 libpackagekit/pk-enum-list.c  |   71 +++++++++++++++
 libpackagekit/pk-enum-list.h  |    2 
 5 files changed, 305 insertions(+), 32 deletions(-)

New commits:
commit 8682523b2f80681f875c34b9920e1087ccdddcaf
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Jan 24 19:10:05 2008 +0000

    allow building more than one backend

diff --git a/backends/Makefile.am b/backends/Makefile.am
index 3bddec6..4bbba4c 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = dummy test
+SUBDIRS = test
 
 if BACKEND_TYPE_ALPM
 SUBDIRS += alpm
@@ -16,6 +16,10 @@ if BACKEND_TYPE_CONARY
 SUBDIRS += conary
 endif
 
+if BACKEND_TYPE_DUMMY
+SUBDIRS += dummy
+endif
+
 if BACKEND_TYPE_OPKG
 SUBDIRS += opkg
 endif
diff --git a/configure.ac b/configure.ac
index f9bdf3a..954efaf 100755
--- a/configure.ac
+++ b/configure.ac
@@ -143,7 +143,31 @@ dnl ---------------------------------------------------------------------------
 AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests],[enable unit test code]),enable_tests=$enableval,enable_tests=$USE_MAINTAINER_MODE)
 AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov],[compile with coverage profiling instrumentation (gcc only)]),enable_gcov=$enableval,enable_gcov=no)
 AC_ARG_ENABLE(gprof, AS_HELP_STRING([--enable-gprof],[compile with gprof support (gcc only)]),enable_gprof=$enableval,enable_gprof=no)
-AC_ARG_ENABLE(local, AS_HELP_STRING([--enable-local],[enable running in local checkout]),enable_tests=$enableval,enable_tests=$USE_MAINTAINER_MODE)
+AC_ARG_ENABLE(local, AS_HELP_STRING([--enable-local],[enable running in local checkout]),enable_local=$enableval,enable_local=$USE_MAINTAINER_MODE)
+
+# backends
+AC_ARG_ENABLE(alpm, AS_HELP_STRING([--enable-alpm],[use the ALPM backend]),enable_alpm=$enableval,enable_alpm=no)
+AC_ARG_ENABLE(apt, AS_HELP_STRING([--enable-apt],[use the APT backend]),enable_apt=$enableval,enable_apt=no)
+AC_ARG_ENABLE(box, AS_HELP_STRING([--enable-box],[use the BOX backend]),enable_box=$enableval,enable_box=no)
+AC_ARG_ENABLE(conary, AS_HELP_STRING([--enable-conary],[use the CONARY backend]),enable_conary=$enableval,enable_conary=no)
+AC_ARG_ENABLE(dummy, AS_HELP_STRING([--enable-dummy],[use the dummy backend]),enable_dummy=$enableval,enable_dummy=yes)
+AC_ARG_ENABLE(opkg, AS_HELP_STRING([--enable-opkg],[use the OPKG backend]),enable_opkg=$enableval,enable_opkg=no)
+AC_ARG_ENABLE(pisi, AS_HELP_STRING([--enable-pisi],[use the PiSi backend]),enable_pisi=$enableval,enable_pisi=no)
+AC_ARG_ENABLE(smart, AS_HELP_STRING([--enable-smart],[use the SMART backend]),enable_smart=$enableval,enable_smart=no)
+AC_ARG_ENABLE(yum, AS_HELP_STRING([--enable-yum],[use the YUM backend]),enable_yum=$enableval,enable_yum=no)
+AC_ARG_ENABLE(zypp, AS_HELP_STRING([--enable-zypp],[use the Zypp backend]),enable_zypp=$enableval,enable_zypp=no)
+
+# export to Makefile.am's
+AM_CONDITIONAL(BACKEND_TYPE_ALPM, [test x$enable_alpm = xyes], [using ALPM backend])
+AM_CONDITIONAL(BACKEND_TYPE_APT, [test x$enable_apt = xyes], [using APT backend])
+AM_CONDITIONAL(BACKEND_TYPE_BOX, [test x$enable_box = xyes], [using BOX backend])
+AM_CONDITIONAL(BACKEND_TYPE_CONARY, [test x$enable_conary = xyes], [using CONARY backend])
+AM_CONDITIONAL(BACKEND_TYPE_DUMMY, [test x$enable_dummy = xyes], [using dummy backend])
+AM_CONDITIONAL(BACKEND_TYPE_OPKG, [test x$enable_opkg = xyes], [using OPKG backend])
+AM_CONDITIONAL(BACKEND_TYPE_PISI, [test x$enable_pisi = xyes], [using PiSi backend])
+AM_CONDITIONAL(BACKEND_TYPE_SMART, [test x$enable_smart = xyes], [using SMART backend])
+AM_CONDITIONAL(BACKEND_TYPE_YUM, [test x$enable_yum = xyes], [using YUM backend])
+AM_CONDITIONAL(BACKEND_TYPE_ZYPP, [test x$enable_zypp = xyes], [using Zypp backend])
 
 AM_CONDITIONAL(PK_BUILD_TESTS, test x$enable_tests = xyes)
 if test x$enable_tests = xyes; then
@@ -342,7 +366,7 @@ AC_DEFUN([APT_BACKEND],
  	fi
 ])
 
-if test x$with_default_backend = xapt; then
+if test x$enable_apt = xyes; then
 	PY_CHECK_MOD([apt_pkg],,,AC_MSG_ERROR([Apt backend needs python-apt]))
 
 	AC_ARG_WITH([apt_search],
@@ -425,19 +449,19 @@ else
 	AM_CONDITIONAL(APT_SEARCH_SQLITE, [false])
 fi
 
-if test x$with_default_backend = xbox; then
+if test x$enable_box = xyes; then
 	PKG_CHECK_MODULES(BOX, libbox >= 0.1.2 )
 	AC_SUBST(BOX_CFLAGS)
 	AC_SUBST(BOX_LIBS)
 fi
 
-if test x$with_default_backend = xopkg; then
+if test x$enable_opkg = xyes; then
 	PKG_CHECK_MODULES(OPKG, libopkg)
 	AC_SUBST(OPKG_CFLAGS)
 	AC_SUBST(OPKG_LIBS)
 fi
 
-if test x$with_default_backend = xalpm; then
+if test x$enable_alpm = xyes; then
 	with_default_backend=dummy
 	AC_MSG_WARN([The alpm backend doesn't work at all!])
 	AC_CHECK_HEADER([alpm.h],
@@ -445,7 +469,7 @@ if test x$with_default_backend = xalpm; then
 			[AC_MSG_WARN([No alpm headers found - falling back to dummy backend])])
 fi
 
-if test x$with_default_backend = xzypp; then
+if test x$enable_zypp = xyes; then
 	PKG_CHECK_MODULES(ZYPP, libzypp)
 	AC_SUBST(ZYPP_CFLAGS)
 	AC_SUBST(ZYPP_LIBS)
@@ -457,17 +481,6 @@ AC_SUBST(PK_PLUGIN_DIR, "\$(libdir)/packagekit-backend")
 AC_SUBST(PK_PLUGIN_CFLAGS, "-I\$(top_srcdir)/src -I\$(top_srcdir)/libpackagekit $GLIB_CFLAGS $DBUS_CFLAGS $GMODULE_CFLAGS")
 AC_SUBST(PK_PLUGIN_LIBS, "$GLIB_LIBS $DBUS_LIBS $GMODULE_LIBS")
 
-AM_CONDITIONAL(BACKEND_TYPE_DUMMY, [test x$with_default_backend = xdummy], [using dummy backend])
-AM_CONDITIONAL(BACKEND_TYPE_APT, [test x$with_default_backend = xapt], [using APT backend])
-AM_CONDITIONAL(BACKEND_TYPE_YUM, [test x$with_default_backend = xyum], [using YUM backend])
-AM_CONDITIONAL(BACKEND_TYPE_CONARY, [test x$with_default_backend = xconary], [using CONARY backend])
-AM_CONDITIONAL(BACKEND_TYPE_BOX, [test x$with_default_backend = xbox], [using BOX backend])
-AM_CONDITIONAL(BACKEND_TYPE_OPKG, [test x$with_default_backend = xopkg], [using OPKG backend])
-AM_CONDITIONAL(BACKEND_TYPE_ALPM, [test x$with_default_backend = xalpm], [using ALPM backend])
-AM_CONDITIONAL(BACKEND_TYPE_SMART, [test x$with_default_backend = xsmart], [using SMART backend])
-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)"
@@ -534,11 +547,25 @@ echo "
         Able to run locally:       ${enable_local}
         GCC coverage profiling:    ${enable_gcov}
         GCC time profiling:        ${enable_gprof}
-        Default backend:           ${with_default_backend}
-        Security Framework:        ${with_security_framework}
+        Security framework:        ${with_security_framework}
         Networking stack:          ${with_networking_stack}
+
+        Backends:
+        ALPM backend:              ${enable_alpm}
+        APT backend:               ${enable_apt}
+        BOX backend:               ${enable_box}
+        CONARY backend:            ${enable_conary}
+        dummy backend:             ${enable_dummy}
+        OPKG backend:              ${enable_opkg}
+        PiSi backend:              ${enable_pisi}
+        SMART backend:             ${enable_smart}
+        YUM backend:               ${enable_yum}
+        Zypp backend:              ${enable_zypp}
+        Default backend:           ${with_default_backend}
 "
 
+
+
 # warn that dummy is basically broken
 if test x$with_security_framework = xdummy; then
 	echo "*******************************************************************"
commit 75f39e5711bb6dd2df603ef265a8584e89cb394f
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Jan 24 18:41:35 2008 +0000

    make the apt backend compile

diff --git a/backends/apt/pk-backend-apt.c b/backends/apt/pk-backend-apt.c
index 0346a58..a477137 100644
--- a/backends/apt/pk-backend-apt.c
+++ b/backends/apt/pk-backend-apt.c
@@ -23,11 +23,45 @@
 #include <gmodule.h>
 #include <glib.h>
 #include <string.h>
+#include <pk-network.h>
 #include <pk-backend.h>
-#include <pk-backend-python.h>
+#include <pk-backend-spawn.h>
 #include "pk-apt-search.h"
 #include "config.h"
 
+static PkBackendSpawn *spawn;
+static PkNetwork *network;
+
+/**
+ * backend_initalize:
+ * This should only be run once per backend load, i.e. not every transaction
+ */
+static void
+backend_initalize (PkBackend *backend)
+{
+	g_return_if_fail (backend != NULL);
+	pk_debug ("FILTER: initalize");
+	network = pk_network_new ();
+	spawn = pk_backend_spawn_new ();
+	pk_backend_spawn_set_name (spawn, "yum");
+	backend_init_search (backend);
+}
+
+/**
+ * backend_destroy:
+ * This should only be run once per backend load, i.e. not every transaction
+ */
+static void
+backend_destroy (PkBackend *backend)
+{
+	g_return_if_fail (backend != NULL);
+	g_return_if_fail (spawn != NULL);
+	pk_debug ("FILTER: destroy");
+	backend_finish_search (backend);
+	g_object_unref (network);
+	g_object_unref (spawn);
+}
+
 /**
  * backend_get_groups:
  */
@@ -62,33 +96,168 @@ backend_get_filters (PkBackend *backend, PkEnumList *elist)
 				      -1);
 }
 
+/**
+ * pk_backend_bool_to_text:
+ */
+static const gchar *
+pk_backend_bool_to_text (gboolean value)
+{
+	if (value == TRUE) {
+		return "yes";
+	}
+	return "no";
+}
+
+/**
+ * backend_get_depends:
+ */
+static void
+backend_get_depends (PkBackend *backend, const gchar *package_id, gboolean recursive)
+{
+	g_return_if_fail (backend != NULL);
+	g_return_if_fail (spawn != NULL);
+	pk_backend_spawn_helper (spawn, "get-depends.py", package_id, pk_backend_bool_to_text (recursive), NULL);
+}
+
+/**
+ * backend_get_updates:
+ */
+static void
+backend_get_updates (PkBackend *backend)
+{
+	g_return_if_fail (backend != NULL);
+	g_return_if_fail (spawn != NULL);
+	pk_backend_spawn_helper (spawn, "get-updates.py", NULL);
+}
+
+/**
+ * backend_install_package:
+ */
+static void
+backend_install_package (PkBackend *backend, const gchar *package_id)
+{
+	g_return_if_fail (backend != NULL);
+	g_return_if_fail (spawn != NULL);
+
+	/* check network state */
+	if (pk_network_is_online (network) == FALSE) {
+		pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot install when offline");
+		pk_backend_finished (backend);
+		return;
+	}
+
+	pk_backend_spawn_helper (spawn, "install.py", package_id, NULL);
+}
+
+/**
+ * backend_refresh_cache:
+ */
+static void
+backend_refresh_cache (PkBackend *backend, gboolean force)
+{
+	g_return_if_fail (backend != NULL);
+	g_return_if_fail (spawn != NULL);
+
+	/* check network state */
+	if (pk_network_is_online (network) == 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 (spawn, "refresh-cache.py", NULL);
+}
+
+/**
+ * pk_backend_remove_package:
+ */
+static void
+backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean allow_deps)
+{
+	g_return_if_fail (backend != NULL);
+	g_return_if_fail (spawn != NULL);
+	pk_backend_spawn_helper (spawn, "remove.py", pk_backend_bool_to_text (allow_deps), package_id, NULL);
+}
+
+/**
+ * pk_backend_update_package:
+ */
+static void
+backend_update_package (PkBackend *backend, const gchar *package_id)
+{
+	g_return_if_fail (backend != NULL);
+	g_return_if_fail (spawn != NULL);
+
+	/* check network state */
+	if (pk_network_is_online (network) == FALSE) {
+		pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot install when offline");
+		pk_backend_finished (backend);
+		return;
+	}
+
+	pk_backend_spawn_helper (spawn, "update.py", package_id, NULL);
+}
+
+/**
+ * pk_backend_update_system:
+ */
+static void
+backend_update_system (PkBackend *backend)
+{
+	g_return_if_fail (backend != NULL);
+	g_return_if_fail (spawn != NULL);
+	pk_backend_spawn_helper (spawn, "update-system.py", NULL);
+}
+
+/**
+ * pk_backend_resolve:
+ */
+static void
+backend_resolve (PkBackend *backend, const gchar *filter, const gchar *package_id)
+{
+	g_return_if_fail (backend != NULL);
+	g_return_if_fail (spawn != NULL);
+	pk_backend_spawn_helper (spawn, "resolve.py", filter, package_id, NULL);
+}
+
+/**
+ * pk_backend_get_repo_list:
+ */
+static void
+backend_get_repo_list (PkBackend *backend)
+{
+	g_return_if_fail (backend != NULL);
+	g_return_if_fail (spawn != NULL);
+	pk_backend_spawn_helper (spawn, "get-repo-list.py", NULL);
+}
+
 PK_BACKEND_OPTIONS (
 	"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_initalize,			/* initalize */
+	backend_destroy,			/* destroy */
 	backend_get_groups,			/* get_groups */
 	backend_get_filters,			/* get_filters */
 	NULL,					/* cancel */
-	pk_backend_python_get_depends,					/* get_depends */
+	backend_get_depends,			/* get_depends */
 	backend_get_description,		/* get_description */
 	NULL,					/* get_files */
 	NULL,					/* get_requires */
 	NULL,					/* get_update_detail */
-	pk_backend_python_get_updates,			/* get_updates */
-	pk_backend_python_install_package,		/* install_package */
+	backend_get_updates,			/* get_updates */
+	backend_install_package,		/* install_package */
 	NULL,					/* install_file */
-	pk_backend_python_refresh_cache,			/* refresh_cache */
-	pk_backend_python_remove_package,			/* remove_package */
-	pk_backend_python_resolve,					/* resolve */
+	backend_refresh_cache,			/* refresh_cache */
+	backend_remove_package,			/* remove_package */
+	backend_resolve,			/* resolve */
 	NULL,					/* rollback */
 	backend_search_details,			/* search_details */
 	NULL,					/* search_file */
 	backend_search_group,			/* search_group */
 	backend_search_name,			/* search_name */
-	pk_backend_python_update_package,			/* update_package */
-	pk_backend_python_update_system,			/* update_system */
-	pk_backend_python_get_repo_list,					/* get_repo_list */
+	backend_update_package,			/* update_package */
+	backend_update_system,			/* update_system */
+	backend_get_repo_list,			/* get_repo_list */
 	NULL,					/* repo_enable */
 	NULL					/* repo_set_data */
 );
commit 901aa64d94342f980bcf2f774c6b6f17bf879a72
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Jan 24 18:06:44 2008 +0000

    add a pk_enum_list_contains_priority method that lets us search for items in an enumerated list with a priority

diff --git a/libpackagekit/pk-enum-list.c b/libpackagekit/pk-enum-list.c
index f5472ae..91343c5 100644
--- a/libpackagekit/pk-enum-list.c
+++ b/libpackagekit/pk-enum-list.c
@@ -120,6 +120,49 @@ pk_enum_list_append_multiple (PkEnumList *elist, gint value, ...)
 	return TRUE;
 }
 
+/**
+ * pk_enum_list_contains_priority:
+ * @elist: a valid #PkEnumList instance
+ * @value: the values we are searching for
+ *
+ * Finds elements in a list, but with priority going to the preceeding entry
+ *
+ * Return value: The return enumerated type, or -1 if none are found
+ **/
+gint
+pk_enum_list_contains_priority (PkEnumList *elist, gint value, ...)
+{
+	va_list args;
+	guint i;
+	guint value_temp;
+	gint retval = -1;
+
+	g_return_val_if_fail (elist != NULL, FALSE);
+	g_return_val_if_fail (PK_IS_ENUM_LIST (elist), FALSE);
+
+	/* we must query at least one thing */
+	if (pk_enum_list_contains (elist, value) == TRUE) {
+		return value;
+	}
+
+	/* process the valist */
+	va_start (args, value);
+	for (i=0;; i++) {
+		value_temp = va_arg (args, gint);
+		/* do we have this one? */
+		if (pk_enum_list_contains (elist, value_temp) == TRUE) {
+			retval = value_temp;
+			break;
+		}
+		/* end of the list */
+		if (value_temp == -1) {
+			break;
+		}
+	}
+	va_end (args);
+
+	return retval;
+}
 
 /**
  * pk_enum_list_from_string:
@@ -556,6 +599,34 @@ libst_enum_list (LibSelfTest *test)
 		libst_failed (test, "invalid size %i, should be 3", value);
 	}
 
+
+	/************************************************************/
+	libst_title (test, "priority check missing");
+	value = pk_enum_list_contains_priority (elist, PK_ROLE_ENUM_SEARCH_FILE, -1);
+	if (value == -1) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "returned priority %i when should be missing", value);
+	}
+
+	/************************************************************/
+	libst_title (test, "priority check first");
+	value = pk_enum_list_contains_priority (elist, PK_ROLE_ENUM_SEARCH_GROUP, -1);
+	if (value == PK_ROLE_ENUM_SEARCH_GROUP) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "returned wrong value; %i", value);
+	}
+
+	/************************************************************/
+	libst_title (test, "priority check second, correct");
+	value = pk_enum_list_contains_priority (elist, PK_ROLE_ENUM_SEARCH_FILE, PK_ROLE_ENUM_SEARCH_GROUP, -1);
+	if (value == PK_ROLE_ENUM_SEARCH_GROUP) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "returned wrong value; %i", value);
+	}
+
 	/************************************************************/
 	libst_title (test, "get multiple list");
 	text = pk_enum_list_to_string (elist);
diff --git a/libpackagekit/pk-enum-list.h b/libpackagekit/pk-enum-list.h
index 2d00962..481b708 100644
--- a/libpackagekit/pk-enum-list.h
+++ b/libpackagekit/pk-enum-list.h
@@ -67,6 +67,8 @@ guint		 pk_enum_list_get_item			(PkEnumList	*elist,
 							 guint		 item);
 gboolean	 pk_enum_list_contains			(PkEnumList	*elist,
 							 guint		 value);
+gint		 pk_enum_list_contains_priority		(PkEnumList	*elist,
+							 gint		 value, ...);
 gboolean	 pk_enum_list_append			(PkEnumList	*elist,
 							 guint		 value);
 gboolean	 pk_enum_list_remove			(PkEnumList	*elist,



More information about the PackageKit mailing list