[PackageKit-commit] packagekit: Branch 'master' - 3 commits
Richard Hughes
hughsient at kemper.freedesktop.org
Tue May 6 15:21:14 PDT 2008
backends/alpm/pk-backend-alpm.c | 116 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 112 insertions(+), 4 deletions(-)
New commits:
commit 33ab2b21854778b0b1f64326e77bbc7dcc14e3ad
Merge: 0136fd1... 0036049...
Author: Valeriy Lyasotskiy <onestep at ukr.net>
Date: Wed May 7 01:02:37 2008 +0300
Merge branch 'master' of git+ssh://onestep_ua@git.packagekit.org/srv/git/PackageKit
diff --cc configure.ac
index df2c2e0,32f85bb..32f85bb
mode 100644,100755..100644
--- a/configure.ac
+++ b/configure.ac
commit 0136fd10e65baeb67d8568033babf96cb095d7af
Author: Valeriy Lyasotskiy <onestep at ukr.net>
Date: Wed May 7 01:02:06 2008 +0300
configure: change modes for .ac and .m4 stuff
diff --git a/acinclude.m4 b/acinclude.m4
old mode 100755
new mode 100644
diff --git a/configure.ac b/configure.ac
old mode 100755
new mode 100644
commit aecaf3417e73dfecb63806fe7f38050cf0e93bbe
Author: Valeriy Lyasotskiy <onestep at ukr.net>
Date: Wed May 7 01:00:34 2008 +0300
alpm: added backend_search_group
diff --git a/backends/alpm/pk-backend-alpm.c b/backends/alpm/pk-backend-alpm.c
index 3f3db24..ffe9b98 100644
--- a/backends/alpm/pk-backend-alpm.c
+++ b/backends/alpm/pk-backend-alpm.c
@@ -47,6 +47,8 @@ static int progress_percentage;
static int subprogress_percentage;
PkBackend *install_backend = NULL;
+static GHashTable *group_mapping;
+
typedef struct _PackageSource
{
pmpkg_t *pkg;
@@ -255,10 +257,10 @@ find_packages_by_name (const gchar *name, pmdb_t *db, gboolean exact)
// determine repository name
const gchar *repo = alpm_db_get_name (db);
// get list of packages in repository
- alpm_list_t *cache = alpm_db_getpkgcache (db);
+ alpm_list_t *pkgcache = alpm_db_getpkgcache (db);
alpm_list_t *iterator;
- for (iterator = cache; iterator; iterator = alpm_list_next (iterator)) {
+ for (iterator = pkgcache; iterator; iterator = alpm_list_next (iterator)) {
pmpkg_t *pkg = alpm_list_getdata (iterator);
gboolean match;
@@ -282,6 +284,56 @@ find_packages_by_name (const gchar *name, pmdb_t *db, gboolean exact)
}
alpm_list_t *
+find_packages_by_group (const gchar *name, pmdb_t *db)
+{
+ if (db == NULL || name == NULL)
+ return NULL;
+
+ alpm_list_t *result = NULL;
+
+ // determine if repository is local
+ gboolean repo_is_local = (db == alpm_option_get_localdb ());
+ // determine if we are searching for packages which belong to an unmapped group
+ gboolean search_other = (strcmp("other", name) == 0);
+ // determine repository name
+ const gchar *repo = alpm_db_get_name (db);
+ // get list of packages in repository
+ alpm_list_t *pkgcache = alpm_db_getpkgcache (db);
+
+ // we will iterate on the whole package cache - this can be slow
+ // other way is to iterate on group cache
+ alpm_list_t *iterator;
+ for (iterator = pkgcache; iterator; iterator = alpm_list_next (iterator)) {
+ pmpkg_t *pkg = alpm_list_getdata (iterator);
+
+ gboolean match = FALSE;
+
+ // iterate on groups list
+ alpm_list_t *group_iterator;
+ for (group_iterator = alpm_pkg_get_groups (pkg); group_iterator; group_iterator = alpm_list_next (group_iterator)) {
+ gchar *mapped_group = (gchar *) g_hash_table_lookup (group_mapping, (char *) alpm_list_getdata (group_iterator));
+ // if we hit unknown group, we can treat it as "other"
+ if ((mapped_group == NULL && search_other) || (mapped_group != NULL && strcmp (mapped_group, name) == 0)) {
+ match = TRUE;
+ break;
+ }
+ }
+
+ if (match) {
+ PackageSource *source = g_malloc (sizeof (PackageSource));
+
+ source->pkg = (pmpkg_t *) pkg;
+ source->repo = (gchar *) repo;
+ source->installed = repo_is_local;
+
+ result = alpm_list_add (result, (PackageSource *) source);
+ }
+ }
+
+ return result;
+}
+
+alpm_list_t *
get_packages (pmdb_t *db)
{
if (db == NULL)
@@ -640,6 +692,21 @@ backend_initialize (PkBackend *backend)
alpm_option_set_dlcb (cb_dl_progress);
+ /* fill in group mapping */
+ group_mapping = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (group_mapping, "gnome", "desktop-gnome");
+ g_hash_table_insert (group_mapping, "gnome-extra", "desktop-gnome");
+ g_hash_table_insert (group_mapping, "compiz-gnome", "desktop-gnome");
+ g_hash_table_insert (group_mapping, "kde", "desktop-kde");
+ g_hash_table_insert (group_mapping, "compiz-kde", "desktop-kde");
+ g_hash_table_insert (group_mapping, "compiz-fusion-kde", "desktop-kde");
+ g_hash_table_insert (group_mapping, "lxde", "desktop-other");
+ g_hash_table_insert (group_mapping, "rox-desktop", "desktop-other");
+ g_hash_table_insert (group_mapping, "xfce4", "desktop-xfce");
+ g_hash_table_insert (group_mapping, "xfce4-goodies", "desktop-xfce");
+ g_hash_table_insert (group_mapping, "base-devel", "programming");
+ g_hash_table_insert (group_mapping, "base", "system");
+
pk_debug ("alpm: ready to go");
}
@@ -649,6 +716,8 @@ backend_initialize (PkBackend *backend)
static void
backend_destroy (PkBackend *backend)
{
+ g_hash_table_destroy (group_mapping);
+
if (alpm_release () == -1) {
pk_backend_error_code (backend, PK_ERROR_ENUM_FAILED_FINALISE, "Failed to release package manager");
pk_debug ("alpm: %s", alpm_strerror (pm_errno));
@@ -662,7 +731,13 @@ static PkGroupEnum
backend_get_groups (PkBackend *backend)
{
// TODO: Provide support for groups in alpm
- return PK_GROUP_ENUM_OTHER;
+ return (PK_GROUP_ENUM_DESKTOP_GNOME |
+ PK_GROUP_ENUM_DESKTOP_KDE |
+ PK_GROUP_ENUM_DESKTOP_OTHER |
+ PK_GROUP_ENUM_DESKTOP_XFCE |
+ PK_GROUP_ENUM_OTHER |
+ PK_GROUP_ENUM_PROGRAMMING |
+ PK_GROUP_ENUM_SYSTEM);
}
/**
@@ -1075,6 +1150,39 @@ backend_search_details (PkBackend *backend, PkFilterEnum filters, const gchar *s
}
/**
+ * backend_search_group:
+ */
+static void
+backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *search)
+{
+ alpm_list_t *result = NULL;
+
+ pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
+
+ gboolean search_installed = pk_enums_contain (filters, PK_FILTER_ENUM_INSTALLED);
+ gboolean search_not_installed = pk_enums_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED);
+
+ if (!search_not_installed) {
+ // Search in local db
+ result = alpm_list_join (result, find_packages_by_group (search, alpm_option_get_localdb ()));
+ }
+
+ if (!search_installed) {
+ // Search in sync dbs
+ alpm_list_t *iterator;
+ for (iterator = alpm_option_get_syncdbs (); iterator; iterator = alpm_list_next (iterator))
+ result = alpm_list_join (result, find_packages_by_group (search, (pmdb_t *) alpm_list_getdata(iterator)));
+ }
+
+ add_packages_from_list (backend, alpm_list_first (result));
+
+ alpm_list_free_inner (result, (alpm_list_fn_free) package_source_free);
+ alpm_list_free (result);
+
+ pk_backend_finished (backend);
+}
+
+/**
* backend_search_name:
*/
static void
@@ -1144,7 +1252,7 @@ PK_BACKEND_OPTIONS (
NULL, /* rollback */
backend_search_details, /* search_details */
NULL, /* search_file */
- NULL, /* search_group */
+ backend_search_group, /* search_group */
backend_search_name, /* search_name */
NULL, /* service_pack */
backend_update_packages, /* update_packages */
More information about the PackageKit-commit
mailing list