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

Richard Hughes hughsient at kemper.freedesktop.org
Mon Feb 4 14:17:01 PST 2008


 backends/yum/helpers/yumBackend.py |    4 
 client/.gitignore                  |    1 
 client/Makefile.am                 |   13 ++
 client/pk-import-common.c          |   38 ++++++++
 client/pk-import-common.h          |    1 
 client/pk-import-desktop.c         |   19 +++-
 client/pk-import-specspo.c         |  171 +++++++++++++++++++++++++++++++++++++
 libpackagekit/pk-extra-obj.c       |   49 +++++++++-
 libpackagekit/pk-extra.c           |  169 +++++++++++++++++-------------------
 libpackagekit/pk-extra.h           |    8 -
 libpackagekit/pk-self-test.c       |    2 
 11 files changed, 371 insertions(+), 104 deletions(-)

New commits:
commit 273ac5a6b51aab4d7402d09caab31ea32e9913d1
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Feb 4 21:26:56 2008 +0000

    make pk-import-specspo less crashy

diff --git a/client/pk-import-common.c b/client/pk-import-common.c
index 3740773..d5c22e2 100644
--- a/client/pk-import-common.c
+++ b/client/pk-import-common.c
@@ -64,7 +64,7 @@ pk_import_get_package_list (void)
 
 	/* generate package list */
 //	system ("rpm -qa --qf \"%{NAME}\n\" > /tmp/list.txt");
-
+//	system ("yum list all | cut -f1 -d\" \" | cut -f1 -d\".\"");
 	package_array = g_ptr_array_new ();
 
 	ret = g_file_get_contents ("/tmp/list.txt", &contents, NULL, NULL);
diff --git a/libpackagekit/pk-extra.c b/libpackagekit/pk-extra.c
index b1be63f..3090cf7 100644
--- a/libpackagekit/pk-extra.c
+++ b/libpackagekit/pk-extra.c
@@ -149,7 +149,7 @@ pk_extra_get_localised_detail (PkExtra *extra, const gchar *package, gchar **sum
 	rc = sqlite3_exec (extra->priv->db, statement, pk_extra_detail_localised_callback, extra, &error_msg);
 	g_free (statement);
 	if (rc != SQLITE_OK) {
-		pk_error ("SQL error: %s\n", error_msg);
+		pk_warning ("SQL error: %s\n", error_msg);
 		sqlite3_free (error_msg);
 		return FALSE;
 	}
@@ -218,7 +218,7 @@ pk_extra_get_package_detail (PkExtra *extra, const gchar *package, gchar **icon,
 	statement = g_strdup_printf ("SELECT icon, exec FROM data WHERE package = '%s'", package);
 	rc = sqlite3_exec (extra->priv->db, statement, pk_extra_detail_package_callback, extra, &error_msg);
 	if (rc != SQLITE_OK) {
-		pk_error ("SQL error: %s\n", error_msg);
+		pk_warning ("SQL error: %s\n", error_msg);
 		sqlite3_free (error_msg);
 		return FALSE;
 	}
@@ -269,7 +269,7 @@ pk_extra_set_localised_detail (PkExtra *extra, const gchar *package, const gchar
 	statement = g_strdup_printf ("DELETE FROM localised WHERE "
 				     "package = '%s' AND locale = '%s'",
 				     package, extra->priv->locale);
-//	sqlite3_exec (extra->priv->db, statement, NULL, extra, NULL);
+	sqlite3_exec (extra->priv->db, statement, NULL, extra, NULL);
 	g_free (statement);
 
 	/* prepare the query, as we don't escape it */
@@ -277,20 +277,20 @@ pk_extra_set_localised_detail (PkExtra *extra, const gchar *package, const gchar
 				 "INSERT INTO localised (package, locale, summary) "
 				 "VALUES (?, ?, ?)", -1, &sql_statement, NULL);
 	if (rc != SQLITE_OK) {
-		pk_error ("SQL failed to prepare");
+		pk_warning ("SQL failed to prepare");
 		return FALSE;
 	}
 
 	/* add data */
-	sqlite3_bind_text(sql_statement, 1, package, -1, SQLITE_STATIC);
-	sqlite3_bind_text(sql_statement, 2, extra->priv->locale, -1, SQLITE_STATIC);
-	sqlite3_bind_text(sql_statement, 3, summary, -1, SQLITE_STATIC);
+	sqlite3_bind_text (sql_statement, 1, package, -1, SQLITE_STATIC);
+	sqlite3_bind_text (sql_statement, 2, extra->priv->locale, -1, SQLITE_STATIC);
+	sqlite3_bind_text (sql_statement, 3, summary, -1, SQLITE_STATIC);
 
 	/* save this */
-	sqlite3_step(sql_statement);
-	rc = sqlite3_finalize(sql_statement);
+	sqlite3_step (sql_statement);
+	rc = sqlite3_finalize (sql_statement);
 	if (rc != SQLITE_OK) {
-		pk_error ("SQL error: %s\n", error_msg);
+		pk_warning ("SQL error: %s\n", error_msg);
 		sqlite3_free (error_msg);
 		return FALSE;
 	}
@@ -332,20 +332,20 @@ pk_extra_set_package_detail (PkExtra *extra, const gchar *package, const gchar *
 	rc = sqlite3_prepare_v2 (extra->priv->db, "INSERT INTO data (package, icon, exec) "
 				 "VALUES (?, ?, ?)", -1, &sql_statement, NULL);
 	if (rc != SQLITE_OK) {
-		pk_error ("SQL failed to prepare");
+		pk_warning ("SQL failed to prepare");
 		return FALSE;
 	}
 
 	/* add data */
-	sqlite3_bind_text(sql_statement, 1, package, -1, SQLITE_STATIC);
-	sqlite3_bind_text(sql_statement, 2, icon, -1, SQLITE_STATIC);
-	sqlite3_bind_text(sql_statement, 3, exec, -1, SQLITE_STATIC);
+	sqlite3_bind_text (sql_statement, 1, package, -1, SQLITE_STATIC);
+	sqlite3_bind_text (sql_statement, 2, icon, -1, SQLITE_STATIC);
+	sqlite3_bind_text (sql_statement, 3, exec, -1, SQLITE_STATIC);
 
 	/* save this */
-	sqlite3_step(sql_statement);
-	rc = sqlite3_finalize(sql_statement);
+	sqlite3_step (sql_statement);
+	rc = sqlite3_finalize (sql_statement);
 	if (rc != SQLITE_OK) {
-		pk_error ("SQL error: %s\n", error_msg);
+		pk_warning ("SQL error: %s\n", error_msg);
 		sqlite3_free (error_msg);
 		return FALSE;
 	}
@@ -403,7 +403,7 @@ pk_extra_set_database (PkExtra *extra, const gchar *filename)
 				    "summary TEXT);";
 			rc = sqlite3_exec (extra->priv->db, statement, NULL, 0, &error_msg);
 			if (rc != SQLITE_OK) {
-				pk_error ("SQL error: %s\n", error_msg);
+				pk_warning ("SQL error: %s\n", error_msg);
 				sqlite3_free (error_msg);
 			}
 			statement = "CREATE TABLE data ("
@@ -413,7 +413,7 @@ pk_extra_set_database (PkExtra *extra, const gchar *filename)
 				    "exec TEXT);";
 			rc = sqlite3_exec (extra->priv->db, statement, NULL, 0, &error_msg);
 			if (rc != SQLITE_OK) {
-				pk_error ("SQL error: %s\n", error_msg);
+				pk_warning ("SQL error: %s\n", error_msg);
 				sqlite3_free (error_msg);
 			}
 		}
commit a68653074a418339c9db57da24d8dc761bf34c92
Merge: 24c4ef9... 1ade93d...
Author: Tim Lauridsen <tim at naboo.local>
Date:   Mon Feb 4 22:01:46 2008 +0100

    Merge branch 'master' of ssh+git://timlau@git.packagekit.org/srv/git/PackageKit

commit 24c4ef91fa884a9bbc9d65d560ded2cd001baf31
Author: Tim Lauridsen <tim at naboo.local>
Date:   Mon Feb 4 22:00:48 2008 +0100

    yum: more utf-98 encoding fixes

diff --git a/backends/yum/helpers/yumBackend.py b/backends/yum/helpers/yumBackend.py
index ea5ed95..394f671 100644
--- a/backends/yum/helpers/yumBackend.py
+++ b/backends/yum/helpers/yumBackend.py
@@ -219,6 +219,8 @@ class PackageKitYumBackend(PackageKitBaseBackend):
               "glibc", "hal", "dbus", "xen")
 
     def __init__(self,args,lock=True):
+        import codecs
+        sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
         signal.signal(signal.SIGQUIT, sigquit)
         PackageKitBaseBackend.__init__(self,args)
         self.yumbase = PackageKitYumBase()
commit 1ade93dcb340dc981d9af9933a44081509889d2d
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Feb 4 20:46:09 2008 +0000

    add some more PkExtraObj checks

diff --git a/libpackagekit/pk-extra-obj.c b/libpackagekit/pk-extra-obj.c
index 69058e8..ef713bf 100644
--- a/libpackagekit/pk-extra-obj.c
+++ b/libpackagekit/pk-extra-obj.c
@@ -206,12 +206,30 @@ libst_extra_obj (LibSelfTest *test)
 	}
 
 	/************************************************************/
-	libst_title (test, "got an icon");
-	if (eobj->icon != NULL) {
-		libst_success (test, "got %s", eobj->icon);
+	libst_title (test, "make sure we don't get a summary for a wrong locale");
+	if (eobj->summary == NULL) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "got %s", eobj->summary);
+	}
+
+	/************************************************************/
+	libst_title (test, "get an wrong object");
+	eobj = pk_extra_obj_new_from_package_id ("gnome-baz-manager;0.0.1;i386;fedora");
+	if (eobj != NULL) {
+		libst_success (test, NULL);
 	} else {
 		libst_failed (test, NULL);
 	}
+
+	/************************************************************/
+	libst_title (test, "make sure we don't get a summary for a wrong package");
+	if (eobj->summary == NULL) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "got %s", eobj->summary);
+	}
+
 	pk_extra_obj_free (eobj);
 
 	libst_end (test);
commit 8f95bd62a9f71e11e67150823bf804956f330deb
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Feb 4 20:33:21 2008 +0000

    add some more PkExtra checks

diff --git a/libpackagekit/pk-extra.c b/libpackagekit/pk-extra.c
index ac2904d..b1be63f 100644
--- a/libpackagekit/pk-extra.c
+++ b/libpackagekit/pk-extra.c
@@ -582,12 +582,43 @@ libst_extra (LibSelfTest *test)
 	/************************************************************/
 	libst_title (test, "retrieve package data");
 	ret = pk_extra_get_package_detail (extra, "gnome-power-manager", &icon, &exec);
-	if (ret == TRUE) {
+	if (ret == TRUE &&
+	    pk_strequal (icon, "gpm-main.png") == TRUE &&
+	    pk_strequal (exec, "gnome-power-manager") == TRUE) {
 		libst_success (test, "%s:%s", icon, exec);
 	} else {
+		libst_failed (test, "%s:%s", icon, exec);
+	}
+
+	/************************************************************/
+	libst_title (test, "insert new package data");
+	ret = pk_extra_set_package_detail (extra, "gnome-power-manager", "gpm-prefs.png", "gnome-power-preferences");
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
 		libst_failed (test, "failed!");
 	}
 
+	/************************************************************/
+	libst_title (test, "retrieve new package data");
+	ret = pk_extra_get_package_detail (extra, "gnome-power-manager", &icon, &exec);
+	if (ret == TRUE &&
+	    pk_strequal (icon, "gpm-prefs.png") == TRUE &&
+	    pk_strequal (exec, "gnome-power-preferences") == TRUE) {
+		libst_success (test, "%s:%s", icon, exec);
+	} else {
+		libst_failed (test, "%s:%s", icon, exec);
+	}
+
+	/************************************************************/
+	libst_title (test, "retrieve missing package data");
+	ret = pk_extra_get_package_detail (extra, "gnome-moo-manager", &icon, &exec);
+	if (ret == TRUE && icon == NULL && exec == NULL) {
+		libst_success (test, "passed");
+	} else {
+		libst_failed (test, "%s:%s", icon, exec);
+	}
+
 	g_object_unref (extra);
 
 	libst_end (test);
commit 55e084ee783ae56acac10c059ad1676c0dca47b7
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Feb 4 20:26:31 2008 +0000

    add a specspo import utility

diff --git a/client/.gitignore b/client/.gitignore
index c944fb0..fe9d600 100644
--- a/client/.gitignore
+++ b/client/.gitignore
@@ -8,6 +8,7 @@ pkmon
 pk-update-icon
 pk-application
 pk-import-desktop
+pk-import-specspo
 *.glade.bak
 *.gladep
 *.gladep.bak
diff --git a/client/Makefile.am b/client/Makefile.am
index 622e8de..4d01db3 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -30,6 +30,7 @@ bin_PROGRAMS =						\
 	pkcon						\
 	pkmon						\
 	pk-import-desktop				\
+	pk-import-specspo				\
 	$(NULL)
 
 pkcon_SOURCES =						\
@@ -66,6 +67,18 @@ pk_import_desktop_LDADD =				\
 	$(PK_LIBS)					\
 	$(NULL)
 
+pk_import_specspo_SOURCES =				\
+	pk-import-common.c				\
+	pk-import-common.h				\
+	pk-import-specspo.c				\
+	$(NULL)
+
+pk_import_specspo_LDADD =				\
+	$(GLIB_LIBS)					\
+	$(SQLITE_LIBS)					\
+	$(PK_LIBS)					\
+	$(NULL)
+
 clean-local:
 	rm -f *~
 	rm -f *.out
diff --git a/client/pk-import-specspo.c b/client/pk-import-specspo.c
new file mode 100644
index 0000000..a5df69d
--- /dev/null
+++ b/client/pk-import-specspo.c
@@ -0,0 +1,171 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 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.
+ *
+ * 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 "config.h"
+
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <libintl.h>
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+
+#include <pk-debug.h>
+#include <pk-client.h>
+#include <pk-common.h>
+#include <pk-package-id.h>
+#include <pk-extra.h>
+
+#include "pk-import-common.h"
+
+#define PK_SPECSPO_DOMAIN 	"redhat-dist"
+
+static PkClient *client = NULL;
+static PkExtra *extra = NULL;
+static GPtrArray *locale_array = NULL;
+static GPtrArray *package_array = NULL;
+
+/**
+ * pk_import_specspo_get_summary:
+ **/
+static const gchar *
+pk_import_specspo_get_summary (const gchar *name)
+{
+	guint size;
+	PkPackageItem *item;
+
+	pk_client_reset (client);
+	pk_client_set_use_buffer (client, TRUE);
+	pk_client_set_synchronous (client, TRUE);
+	pk_client_resolve (client, "none", name);
+
+	/* check that we only matched one package */
+	size = pk_client_package_buffer_get_size (client);
+	if (size != 1) {
+		pk_warning ("not correct size, %i", size);
+		return NULL;
+	}
+
+	/* get the item */
+	item = pk_client_package_buffer_get_item (client, 0);
+	if (item == NULL) {
+		pk_error ("cannot get item");
+		return NULL;
+	}
+
+	return item->summary;
+}
+
+/**
+ * pk_import_specspo_do_package:
+ **/
+static void
+pk_import_specspo_do_package (const gchar *package_name)
+{
+	const gchar *summary;
+	const gchar *locale;
+	char *trans;
+	char *set_locale;
+	guint j;
+
+	summary = pk_import_specspo_get_summary (package_name);
+	if (summary == NULL) {
+		g_print ("no summary for %s\n", package_name);
+		return;
+	}
+	g_print ("processing %s [", package_name);
+//	g_print ("%s,", summary);
+
+	for (j=0; j<locale_array->len; j++) {
+		locale = g_ptr_array_index (locale_array, j);
+		set_locale = setlocale (LC_ALL, locale);
+		if (pk_strequal (set_locale, locale) == TRUE) {
+			/* get the translation */
+			trans = gettext (summary);
+
+			/* if different, then save */
+			if (pk_strequal (summary, trans) == FALSE) {
+				g_print (" %s", locale);
+//				g_print (" %s", trans);
+				pk_extra_set_locale (extra, locale);
+				pk_extra_set_localised_detail (extra, package_name, trans);
+			}
+		}
+	}
+	g_print ("]\n");
+}
+
+/**
+ * main:
+ **/
+int
+main (int argc, char *argv[])
+{
+	GOptionContext *context;
+	gboolean verbose = FALSE;
+	gchar *database_location = NULL;
+	const gchar *package;
+	guint i;
+
+	const GOptionEntry options[] = {
+		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
+			"Show extra debugging information", NULL },
+		{ "database-location", '\0', 0, G_OPTION_ARG_STRING, &database_location,
+			"Database location (default set from daemon)", NULL },
+		{ NULL}
+	};
+
+	g_type_init ();
+
+	context = g_option_context_new ("pk-import-specspo");
+	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_parse (context, &argc, &argv, NULL);
+	g_option_context_free (context);
+
+	pk_debug_init (verbose);
+
+	client = pk_client_new ();
+	locale_array = pk_import_get_locale_list ();
+	package_array = pk_import_get_package_list ();
+
+	extra = pk_extra_new ();
+	pk_extra_set_database (extra, database_location);
+
+	/* set the gettext bits */
+	textdomain (PK_SPECSPO_DOMAIN);
+	bindtextdomain (PK_SPECSPO_DOMAIN, PK_IMPORT_LOCALEDIR);
+	bind_textdomain_codeset (PK_SPECSPO_DOMAIN, "UTF-8");
+
+	/* for each locale */
+	for (i=0; i<package_array->len; i++) {
+		package = g_ptr_array_index (package_array, i);
+		pk_import_specspo_do_package (package);
+	}
+
+	g_object_unref (client);
+	g_object_unref (extra);
+	g_ptr_array_free (package_array, TRUE);
+	g_ptr_array_free (locale_array, TRUE);
+
+	return 0;
+}
+
commit 6905f78097cb7c0b0d9c0b47099c4c630f18d5fc
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Feb 4 20:24:45 2008 +0000

    don't fail the transaction if we failed the delete

diff --git a/libpackagekit/pk-extra.c b/libpackagekit/pk-extra.c
index d27f7a0..ac2904d 100644
--- a/libpackagekit/pk-extra.c
+++ b/libpackagekit/pk-extra.c
@@ -251,7 +251,7 @@ pk_extra_set_localised_detail (PkExtra *extra, const gchar *package, const gchar
 {
 	gchar *statement;
 	gchar *error_msg = NULL;
-	sqlite3_stmt *sql_statement;
+	sqlite3_stmt *sql_statement = NULL;
 	gint rc;
 
 	g_return_val_if_fail (extra != NULL, FALSE);
@@ -269,21 +269,15 @@ pk_extra_set_localised_detail (PkExtra *extra, const gchar *package, const gchar
 	statement = g_strdup_printf ("DELETE FROM localised WHERE "
 				     "package = '%s' AND locale = '%s'",
 				     package, extra->priv->locale);
-	rc = sqlite3_exec (extra->priv->db, statement, NULL, extra, &error_msg);
+//	sqlite3_exec (extra->priv->db, statement, NULL, extra, NULL);
 	g_free (statement);
-	if (rc != SQLITE_OK) {
-		pk_error ("SQL error: %s\n", error_msg);
-		sqlite3_free (error_msg);
-		return FALSE;
-	}
 
 	/* prepare the query, as we don't escape it */
 	rc = sqlite3_prepare_v2 (extra->priv->db,
 				 "INSERT INTO localised (package, locale, summary) "
-				 "VALUES (?, ?, ?)", -1, &sql_statement, 0);
+				 "VALUES (?, ?, ?)", -1, &sql_statement, NULL);
 	if (rc != SQLITE_OK) {
-		pk_error ("SQL error: %s\n", error_msg);
-		sqlite3_free (error_msg);
+		pk_error ("SQL failed to prepare");
 		return FALSE;
 	}
 
@@ -315,6 +309,7 @@ pk_extra_set_package_detail (PkExtra *extra, const gchar *package, const gchar *
 {
 	gchar *statement;
 	gchar *error_msg = NULL;
+	sqlite3_stmt *sql_statement = NULL;
 	gint rc;
 
 	g_return_val_if_fail (extra != NULL, FALSE);
@@ -330,20 +325,14 @@ pk_extra_set_package_detail (PkExtra *extra, const gchar *package, const gchar *
 
 	/* the row might already exist */
 	statement = g_strdup_printf ("DELETE FROM data WHERE package = '%s'", package);
-	rc = sqlite3_exec (extra->priv->db, statement, NULL, extra, &error_msg);
+	sqlite3_exec (extra->priv->db, statement, NULL, extra, NULL);
 	g_free (statement);
-	if (rc != SQLITE_OK) {
-		pk_error ("SQL error: %s\n", error_msg);
-		sqlite3_free (error_msg);
-		return FALSE;
-	}
 
-	sqlite3_stmt *sql_statement;
 	/* prepare the query, as we don't escape it */
-	rc = sqlite3_prepare_v2 (extra->priv->db, "INSERT INTO data (package, icon, exec) VALUES (?, ?, ?)", -1, &sql_statement, 0);
+	rc = sqlite3_prepare_v2 (extra->priv->db, "INSERT INTO data (package, icon, exec) "
+				 "VALUES (?, ?, ?)", -1, &sql_statement, NULL);
 	if (rc != SQLITE_OK) {
-		pk_error ("SQL error: %s\n", error_msg);
-		sqlite3_free (error_msg);
+		pk_error ("SQL failed to prepare");
 		return FALSE;
 	}
 
commit b5939d3aa68d947b39621d02fec4ce32d8297bb5
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Feb 4 19:25:47 2008 +0000

    only save the localised summary, not every field in the desktop file

diff --git a/client/pk-import-desktop.c b/client/pk-import-desktop.c
index 753e9e8..0605f39 100644
--- a/client/pk-import-desktop.c
+++ b/client/pk-import-desktop.c
@@ -117,11 +117,22 @@ pk_desktop_process_desktop (const gchar *package_name, const gchar *filename)
 		/* if different, then save */
 		if (pk_strequal (name_unlocalised, name) == FALSE) {
 			g_print (" %s", locale);
-			comment = g_key_file_get_locale_string (key, G_KEY_FILE_DESKTOP_GROUP, "Comment", locale, NULL);
-			genericname = g_key_file_get_locale_string (key, G_KEY_FILE_DESKTOP_GROUP, "GenericName", locale, NULL);
-			pk_debug ("PackageName=%s, Locale=%s, Name=%s, GenericName=%s, Comment=%s", package_name, locale, name, genericname, comment);
+			comment = g_key_file_get_locale_string (key, G_KEY_FILE_DESKTOP_GROUP,
+								"Comment", locale, NULL);
+			genericname = g_key_file_get_locale_string (key, G_KEY_FILE_DESKTOP_GROUP,
+								    "GenericName", locale, NULL);
+			pk_debug ("PackageName=%s, Locale=%s, Name=%s, GenericName=%s, Comment=%s",
+				  package_name, locale, name, genericname, comment);
 			pk_extra_set_locale (extra, locale);
-			pk_extra_set_localised_detail (extra, package_name, name, genericname, comment);
+
+			/* save in order of priority */
+			if (comment != NULL) {
+				pk_extra_set_localised_detail (extra, package_name, comment);
+			} else if (genericname != NULL) {
+				pk_extra_set_localised_detail (extra, package_name, genericname);
+			} else {
+				pk_extra_set_localised_detail (extra, package_name, name);
+			}
 			g_free (comment);
 			g_free (genericname);
 		}
diff --git a/libpackagekit/pk-extra-obj.c b/libpackagekit/pk-extra-obj.c
index 0d6c095..69058e8 100644
--- a/libpackagekit/pk-extra-obj.c
+++ b/libpackagekit/pk-extra-obj.c
@@ -78,7 +78,7 @@ pk_extra_obj_new_from_package_id (const gchar *package_id)
 
 	extra = pk_extra_new ();
 	pk_debug ("getting localised for %s", eobj->id->name);
-	pk_extra_get_localised_detail (extra, eobj->id->name, &eobj->summary, NULL, NULL);
+	pk_extra_get_localised_detail (extra, eobj->id->name, &eobj->summary);
 	pk_extra_get_package_detail (extra, eobj->id->name, &eobj->icon, &eobj->exec);
 	g_object_unref (extra);
 
@@ -146,8 +146,10 @@ libst_extra_obj (LibSelfTest *test)
 
 	/* should be single instance */
 	extra = pk_extra_new ();
-	pk_extra_set_database (extra, PK_EXTRA_DEFAULT_DATABASE);
-	pk_extra_set_locale (extra, "fr");
+	pk_extra_set_database (extra, "extra.db");
+
+	/* set correct locale */
+	pk_extra_set_locale (extra, "en_GB");
 
 	/************************************************************/
 	libst_title (test, "get an extra_obj object");
@@ -175,7 +177,7 @@ libst_extra_obj (LibSelfTest *test)
 	}
 
 	/************************************************************/
-	libst_title (test, "got an summary");
+	libst_title (test, "got a summary");
 	if (eobj->summary != NULL) {
 		libst_success (test, "got %s", eobj->summary);
 	} else {
@@ -191,6 +193,27 @@ libst_extra_obj (LibSelfTest *test)
 		libst_failed (test, NULL);
 	}
 
+	/* set incorrect locale */
+	pk_extra_set_locale (extra, "fr_GB");
+
+	/************************************************************/
+	libst_title (test, "get an extra_obj object");
+	eobj = pk_extra_obj_new_from_package_id ("gnome-power-manager;0.0.1;i386;fedora");
+	if (eobj != NULL) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	/************************************************************/
+	libst_title (test, "got an icon");
+	if (eobj->icon != NULL) {
+		libst_success (test, "got %s", eobj->icon);
+	} else {
+		libst_failed (test, NULL);
+	}
+	pk_extra_obj_free (eobj);
+
 	libst_end (test);
 }
 #endif
diff --git a/libpackagekit/pk-extra.c b/libpackagekit/pk-extra.c
index 1df07fb..d27f7a0 100644
--- a/libpackagekit/pk-extra.c
+++ b/libpackagekit/pk-extra.c
@@ -53,11 +53,9 @@ struct PkExtraPrivate
 {
 	gchar			*database;
 	gchar			*locale;
-	gchar			*name;
 	gchar			*icon;
 	gchar			*exec;
-	gchar			*genericname;
-	gchar			*comment;
+	gchar			*summary;
 	sqlite3			*db;
 };
 
@@ -108,12 +106,8 @@ pk_extra_detail_localised_callback (void *data, gint argc, gchar **argv, gchar *
 	for (i=0; i<argc; i++) {
 		col = col_name[i];
 		value = argv[i];
-		if (pk_strequal (col, "name") == TRUE) {
-			extra->priv->name = g_strdup (value);
-		} else if (pk_strequal (col, "genericname") == TRUE) {
-			extra->priv->genericname = g_strdup (value);
-		} else if (pk_strequal (col, "comment") == TRUE) {
-			extra->priv->comment = g_strdup (value);
+		if (pk_strequal (col, "summary") == TRUE) {
+			extra->priv->summary = g_strdup (value);
 		} else if (pk_strequal (col, "locale") == TRUE) {
 			pk_debug ("locale: %s", value);
 		} else if (pk_strequal (col, "package") == TRUE) {
@@ -132,7 +126,7 @@ pk_extra_detail_localised_callback (void *data, gint argc, gchar **argv, gchar *
  * Return value: the current locale
  **/
 gboolean
-pk_extra_get_localised_detail (PkExtra *extra, const gchar *package, gchar **name, gchar **genericname, gchar **comment)
+pk_extra_get_localised_detail (PkExtra *extra, const gchar *package, gchar **summary)
 {
 	gchar *statement;
 	gchar *error_msg = NULL;
@@ -149,8 +143,8 @@ pk_extra_get_localised_detail (PkExtra *extra, const gchar *package, gchar **nam
 		return FALSE;
 	}
 
-	statement = g_strdup_printf ("SELECT package, name, genericname, comment, locale "
-				     "FROM localised WHERE package = '%s' AND locale = '%s'",
+	statement = g_strdup_printf ("SELECT package, summary, locale FROM localised "
+				     "WHERE package = '%s' AND locale = '%s'",
 				     package, extra->priv->locale);
 	rc = sqlite3_exec (extra->priv->db, statement, pk_extra_detail_localised_callback, extra, &error_msg);
 	g_free (statement);
@@ -160,25 +154,12 @@ pk_extra_get_localised_detail (PkExtra *extra, const gchar *package, gchar **nam
 		return FALSE;
 	}
 
-	/* report back */
-	if (name != NULL) {
-		*name = extra->priv->name;
-	} else {
-		g_free (extra->priv->name);
-	}
-	if (genericname != NULL) {
-		*genericname = extra->priv->genericname;
+	if (summary != NULL) {
+		*summary = extra->priv->summary;
 	} else {
-		g_free (extra->priv->genericname);
+		g_free (extra->priv->summary);
 	}
-	if (comment != NULL) {
-		*comment = extra->priv->comment;
-	} else {
-		g_free (extra->priv->comment);
-	}
-	extra->priv->name = NULL;
-	extra->priv->genericname = NULL;
-	extra->priv->comment = NULL;
+	extra->priv->summary = NULL;
 	return TRUE;
 }
 
@@ -266,7 +247,7 @@ pk_extra_get_package_detail (PkExtra *extra, const gchar *package, gchar **icon,
  * Return value: the current locale
  **/
 gboolean
-pk_extra_set_localised_detail (PkExtra *extra, const gchar *package, const gchar *name, const gchar *genericname, const gchar *comment)
+pk_extra_set_localised_detail (PkExtra *extra, const gchar *package, const gchar *summary)
 {
 	gchar *statement;
 	gchar *error_msg = NULL;
@@ -285,7 +266,9 @@ pk_extra_set_localised_detail (PkExtra *extra, const gchar *package, const gchar
 	}
 
 	/* the row might already exist */
-	statement = g_strdup_printf ("DELETE FROM localised WHERE package = '%s' AND locale = '%s'", package, extra->priv->locale);
+	statement = g_strdup_printf ("DELETE FROM localised WHERE "
+				     "package = '%s' AND locale = '%s'",
+				     package, extra->priv->locale);
 	rc = sqlite3_exec (extra->priv->db, statement, NULL, extra, &error_msg);
 	g_free (statement);
 	if (rc != SQLITE_OK) {
@@ -296,8 +279,8 @@ pk_extra_set_localised_detail (PkExtra *extra, const gchar *package, const gchar
 
 	/* prepare the query, as we don't escape it */
 	rc = sqlite3_prepare_v2 (extra->priv->db,
-				 "INSERT INTO localised (package, locale, name, genericname, comment) "
-				 "VALUES (?, ?, ?, ?, ?)", -1, &sql_statement, 0);
+				 "INSERT INTO localised (package, locale, summary) "
+				 "VALUES (?, ?, ?)", -1, &sql_statement, 0);
 	if (rc != SQLITE_OK) {
 		pk_error ("SQL error: %s\n", error_msg);
 		sqlite3_free (error_msg);
@@ -307,9 +290,7 @@ pk_extra_set_localised_detail (PkExtra *extra, const gchar *package, const gchar
 	/* add data */
 	sqlite3_bind_text(sql_statement, 1, package, -1, SQLITE_STATIC);
 	sqlite3_bind_text(sql_statement, 2, extra->priv->locale, -1, SQLITE_STATIC);
-	sqlite3_bind_text(sql_statement, 3, name, -1, SQLITE_STATIC);
-	sqlite3_bind_text(sql_statement, 4, genericname, -1, SQLITE_STATIC);
-	sqlite3_bind_text(sql_statement, 5, comment, -1, SQLITE_STATIC);
+	sqlite3_bind_text(sql_statement, 3, summary, -1, SQLITE_STATIC);
 
 	/* save this */
 	sqlite3_step(sql_statement);
@@ -430,9 +411,7 @@ pk_extra_set_database (PkExtra *extra, const gchar *filename)
 				    "id INTEGER PRIMARY KEY,"
 				    "package TEXT,"
 				    "locale TEXT,"
-				    "name TEXT,"
-				    "genericname TEXT,"
-				    "comment TEXT);";
+				    "summary TEXT);";
 			rc = sqlite3_exec (extra->priv->db, statement, NULL, 0, &error_msg);
 			if (rc != SQLITE_OK) {
 				pk_error ("SQL error: %s\n", error_msg);
@@ -473,11 +452,9 @@ pk_extra_init (PkExtra *extra)
 	extra->priv = PK_EXTRA_GET_PRIVATE (extra);
 	extra->priv->database = NULL;
 	extra->priv->locale = NULL;
-	extra->priv->name = NULL;
 	extra->priv->icon = NULL;
 	extra->priv->exec = NULL;
-	extra->priv->genericname = NULL;
-	extra->priv->comment = NULL;
+	extra->priv->summary = NULL;
 }
 
 /**
@@ -494,9 +471,7 @@ pk_extra_finalize (GObject *object)
 
 	g_free (extra->priv->icon);
 	g_free (extra->priv->exec);
-	g_free (extra->priv->name);
-	g_free (extra->priv->genericname);
-	g_free (extra->priv->comment);
+	g_free (extra->priv->summary);
 	g_free (extra->priv->locale);
 	sqlite3_close (extra->priv->db);
 
@@ -583,18 +558,14 @@ libst_extra (LibSelfTest *test)
 		libst_failed (test, "locale was %s", text);
 	}
 
-	gchar *name;
-	gchar *genericname;
 	gchar *icon;
 	gchar *exec;
-	gchar *comment;
+	gchar *summary;
 
 	/************************************************************/
 	libst_title (test, "insert localised data");
 	ret = pk_extra_set_localised_detail (extra, "gnome-power-manager",
-					    "GNOMEY Power Managerer",
-					    "Power's Managerer",
-					    "Power manager for the GNOME Ddesktop");
+					     "Power manager for the GNOME's desktop");
 	if (ret == TRUE) {
 		libst_success (test, NULL);
 	} else {
@@ -603,16 +574,16 @@ libst_extra (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "retrieve localised data");
-	ret = pk_extra_get_localised_detail (extra, "gnome-power-manager", &name, &genericname, &comment);
+	ret = pk_extra_get_localised_detail (extra, "gnome-power-manager", &summary);
 	if (ret == TRUE) {
-		libst_success (test, "%s:%s:%s", name, genericname, comment);
+		libst_success (test, "%s", summary);
 	} else {
 		libst_failed (test, "failed!");
 	}
 
 	/************************************************************/
 	libst_title (test, "insert package data");
-	ret = pk_extra_set_package_detail (extra, "gnome-power-manager", "gpm-main.png", "gnome-'power'-manager");
+	ret = pk_extra_set_package_detail (extra, "gnome-power-manager", "gpm-main.png", "gnome-power-manager");
 	if (ret == TRUE) {
 		libst_success (test, NULL);
 	} else {
diff --git a/libpackagekit/pk-extra.h b/libpackagekit/pk-extra.h
index 493a8da..0dcf8a4 100644
--- a/libpackagekit/pk-extra.h
+++ b/libpackagekit/pk-extra.h
@@ -61,14 +61,10 @@ gboolean	 pk_extra_set_database			(PkExtra	*extra,
 							 const gchar	*filename);
 gboolean	 pk_extra_get_localised_detail		(PkExtra	*extra,
 							 const gchar	*package,
-							 gchar		**name,
-							 gchar		**genericname,
-							 gchar		**comment);
+							 gchar		**summary);
 gboolean	 pk_extra_set_localised_detail		(PkExtra	*extra,
 							 const gchar	*package,
-							 const gchar	*name,
-							 const gchar	*genericname,
-							 const gchar	*comment);
+							 const gchar	*summary);
 gboolean	 pk_extra_get_package_detail		(PkExtra	*extra,
 							 const gchar	*package,
 							 gchar		**icon,
commit a7277f00eeb323cd8d950421ffc68e51ab34384d
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Feb 4 19:24:06 2008 +0000

    turn on debugging on the libpackagekit code

diff --git a/libpackagekit/pk-self-test.c b/libpackagekit/pk-self-test.c
index 626e17a..e077bcb 100644
--- a/libpackagekit/pk-self-test.c
+++ b/libpackagekit/pk-self-test.c
@@ -24,6 +24,7 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <libselftest.h>
+#include <pk-debug.h>
 
 /* prototypes */
 void libst_package_id (LibSelfTest *test);
@@ -41,6 +42,7 @@ main (int argc, char **argv)
 
 	g_type_init ();
 	libst_init (&test);
+	pk_debug_init (TRUE);
 
 	/* tests go here */
 	libst_common (&test);
commit a6039d556d9a723733d229ac29204b37c654c886
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Feb 4 19:22:14 2008 +0000

    add a helper function pk_import_get_package_list

diff --git a/client/pk-import-common.c b/client/pk-import-common.c
index 5a37f51..3740773 100644
--- a/client/pk-import-common.c
+++ b/client/pk-import-common.c
@@ -23,6 +23,7 @@
 #include <glib.h>
 
 #include <pk-debug.h>
+#include <pk-common.h>
 #include "pk-import-common.h"
 
 GPtrArray *
@@ -49,3 +50,40 @@ pk_import_get_locale_list (void)
 	return locale_array;
 }
 
+/**
+ * pk_import_get_package_list:
+ **/
+GPtrArray *
+pk_import_get_package_list (void)
+{
+	gboolean ret;
+	gchar **lines;
+	gchar *contents;
+	guint i;
+	GPtrArray *package_array;
+
+	/* generate package list */
+//	system ("rpm -qa --qf \"%{NAME}\n\" > /tmp/list.txt");
+
+	package_array = g_ptr_array_new ();
+
+	ret = g_file_get_contents ("/tmp/list.txt", &contents, NULL, NULL);
+	if (ret == FALSE) {
+		pk_error ("failed to open file");
+	}
+
+	lines = g_strsplit (contents, "\n", -1);
+	g_free (contents);
+
+	i = 0;
+	do {
+		if (pk_strzero (lines[i]) == FALSE) {
+			g_ptr_array_add (package_array, g_strdup (lines[i]));;
+		}
+	} while (lines[++i] != NULL);
+
+	/* delete the file */
+	//g_unlink ("/tmp/list.txt");
+	return package_array;
+}
+
diff --git a/client/pk-import-common.h b/client/pk-import-common.h
index 72ab48f..6ce8ed1 100644
--- a/client/pk-import-common.h
+++ b/client/pk-import-common.h
@@ -26,5 +26,6 @@
 #define PK_IMPORT_LOCALEDIR			"/usr/share/locale"
 
 GPtrArray	*pk_import_get_locale_list	(void);
+GPtrArray	*pk_import_get_package_list	(void);
 
 #endif /* __PK_IMPORT_COMMON_H */
commit 85a1e31b8ff5442cf2ad21dce277593300b660d9
Merge: 85638b1... bf8f0d8...
Author: Tim Lauridsen <tim at naboo.local>
Date:   Mon Feb 4 18:35:26 2008 +0100

    Merge branch 'master' of ssh+git://timlau@git.packagekit.org/srv/git/PackageKit

commit 85638b1a58702e704dcdd2783683cb16bf62d6d0
Author: Tim Lauridsen <tim at naboo.local>
Date:   Mon Feb 4 18:33:51 2008 +0100

    yum: solve UnicodeEncodeError is string contains non ascii char in C locale

diff --git a/backends/yum/helpers/yumBackend.py b/backends/yum/helpers/yumBackend.py
index 6f1c093..ea5ed95 100644
--- a/backends/yum/helpers/yumBackend.py
+++ b/backends/yum/helpers/yumBackend.py
@@ -261,7 +261,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
                 rc = unicode( txt, 'utf-8' )
             except UnicodeDecodeError, e:
                 rc = unicode( txt, 'iso-8859-1' )
-            return rc
+            return rc.encode('utf-8')
 
     def doLock(self):
         ''' Lock Yum'''



More information about the PackageKit mailing list