[gnome-software/wip/rancell/ubuntu-3-20-rebase: 20/29] Add a dpkg plugin
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/rancell/ubuntu-3-20-rebase: 20/29] Add a dpkg plugin
- Date: Sat, 17 Jun 2017 07:48:48 +0000 (UTC)
commit a4305fa7087c79ff1dc0d993af0f96d1b446f4fd
Author: Robert Ancell <robert ancell canonical com>
Date: Thu Apr 7 09:19:27 2016 +0100
Add a dpkg plugin
data/tests/build-deb.sh | 1 +
data/tests/chiron-1.1-1.deb | Bin 0 -> 806 bytes
data/tests/debian/DEBIAN/control | 13 +++
src/gs-self-test.c | 52 ++++++++++-
src/plugins/Makefile.am | 6 +
src/plugins/gs-plugin-appstream.c | 1 +
src/plugins/gs-plugin-dpkg.c | 137 ++++++++++++++++++++++++++++
src/plugins/gs-plugin-packagekit-refresh.c | 11 ++
8 files changed, 219 insertions(+), 2 deletions(-)
---
diff --git a/data/tests/build-deb.sh b/data/tests/build-deb.sh
new file mode 100755
index 0000000..cbf50f6
--- /dev/null
+++ b/data/tests/build-deb.sh
@@ -0,0 +1 @@
+dpkg-deb --build debian chiron-1.1-1.deb
diff --git a/data/tests/chiron-1.1-1.deb b/data/tests/chiron-1.1-1.deb
new file mode 100644
index 0000000..f4f921a
Binary files /dev/null and b/data/tests/chiron-1.1-1.deb differ
diff --git a/data/tests/debian/DEBIAN/control b/data/tests/debian/DEBIAN/control
new file mode 100644
index 0000000..ad5d9c6
--- /dev/null
+++ b/data/tests/debian/DEBIAN/control
@@ -0,0 +1,13 @@
+Package: chiron
+Version: 1.1-1
+Section: base
+Priority: optional
+Architecture: all
+Homepage: http://127.0.0.1/
+Maintainer: Richard Hughes <richard hughsie com>
+Description: Single line synopsis
+ This is the first
+ paragraph in the example package
+ control file.
+ .
+ This is the second paragraph.
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 443dc78..22dcfbb 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -23,7 +23,6 @@
#include <glib.h>
#include <glib-object.h>
-#include <gtk/gtk.h>
#include <glib/gstdio.h>
#include "gs-app.h"
@@ -679,10 +678,58 @@ gs_plugin_loader_webapps_func (void)
g_unlink (path);
}
+static void
+gs_plugin_loader_dpkg_func (GsPluginLoader *plugin_loader)
+{
+ g_autoptr(GsApp) app = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autofree gchar *fn = NULL;
+
+ /* no dpkg, abort */
+ if (!gs_plugin_loader_get_enabled (plugin_loader, "dpkg"))
+ return;
+
+ /* load local file */
+ fn = gs_test_get_filename ("tests/chiron-1.1-1.deb");
+ g_assert (fn != NULL);
+ app = gs_plugin_loader_filename_to_app (plugin_loader,
+ fn,
+ GS_PLUGIN_REFINE_FLAGS_DEFAULT,
+ NULL,
+ &error);
+ g_assert_no_error (error);
+ g_assert (app != NULL);
+ g_assert_cmpstr (gs_app_get_id (app), ==, NULL);
+ g_assert_cmpstr (gs_app_get_source_default (app), ==, "chiron");
+ g_assert_cmpstr (gs_app_get_url (app, AS_URL_KIND_HOMEPAGE), ==, "http://127.0.0.1/");
+ g_assert_cmpstr (gs_app_get_name (app), ==, "chiron");
+ g_assert_cmpstr (gs_app_get_version (app), ==, "1.1-1");
+ g_assert_cmpstr (gs_app_get_summary (app), ==, "Single line synopsis");
+ g_assert_cmpstr (gs_app_get_description (app), ==,
+ "This is the first paragraph in the example "
+ "package control file.\nThis is the second paragraph.");
+}
+
int
main (int argc, char **argv)
{
- gtk_init (&argc, &argv);
+ gboolean ret;
+ g_autofree gchar *fn = NULL;
+ g_autofree gchar *xml = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GsPluginLoader) plugin_loader = NULL;
+ const gchar *whitelist[] = {
+ "appstream",
+ "dpkg",
+ "dummy",
+ "epiphany",
+ "hardcoded-blacklist",
+ "icons",
+ "menu-spec-refine",
+ "provenance",
+ NULL
+ };
+
g_test_init (&argc, &argv, NULL);
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
g_setenv ("GNOME_SOFTWARE_SELF_TEST", "1", TRUE);
@@ -701,6 +748,7 @@ main (int argc, char **argv)
g_test_add_func ("/gnome-software/plugin-loader{dedupe}", gs_plugin_loader_dedupe_func);
if(0)g_test_add_func ("/gnome-software/plugin-loader", gs_plugin_loader_func);
if(0)g_test_add_func ("/gnome-software/plugin-loader{webapps}", gs_plugin_loader_webapps_func);
+ if(0)g_test_add_func ("/gnome-software/plugin-loader{dpkg}", gs_plugin_loader_dpkg_func);
return g_test_run ();
}
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 684375c..f02d101 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -32,6 +32,7 @@ plugin_LTLIBRARIES = \
libgs_plugin_appstream.la \
libgs_plugin_dummy.la \
libgs_plugin_hardcoded-featured.la \
+ libgs_plugin_dpkg.la \
libgs_plugin_hardcoded-blacklist.la \
libgs_plugin_moduleset.la \
libgs_plugin_menu-spec-categories.la \
@@ -76,6 +77,11 @@ libgs_plugin_dummy_la_LIBADD = $(GS_PLUGIN_LIBS)
libgs_plugin_dummy_la_LDFLAGS = -module -avoid-version
libgs_plugin_dummy_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+libgs_plugin_dpkg_la_SOURCES = gs-plugin-dpkg.c
+libgs_plugin_dpkg_la_LIBADD = $(GS_PLUGIN_LIBS)
+libgs_plugin_dpkg_la_LDFLAGS = -module -avoid-version
+libgs_plugin_dpkg_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+
libgs_plugin_fedora_distro_upgrades_la_SOURCES = gs-plugin-fedora-distro-upgrades.c
libgs_plugin_fedora_distro_upgrades_la_LIBADD = $(GS_PLUGIN_LIBS) $(JSON_GLIB_LIBS) $(SOUP_LIBS)
libgs_plugin_fedora_distro_upgrades_la_LDFLAGS = -module -avoid-version
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 357e390..3e6a287 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -90,6 +90,7 @@ gs_plugin_order_after (GsPlugin *plugin)
{
static const gchar *deps[] = {
"menu-spec-categories", /* need category list */
+ "dpkg", /* need package name */
NULL };
return deps;
}
diff --git a/src/plugins/gs-plugin-dpkg.c b/src/plugins/gs-plugin-dpkg.c
new file mode 100644
index 0000000..b5005fc
--- /dev/null
+++ b/src/plugins/gs-plugin-dpkg.c
@@ -0,0 +1,137 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011-2013 Richard Hughes <richard 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+
+#include <gs-plugin.h>
+#include <gs-utils.h>
+
+#define DPKG_DEB_BINARY "/usr/bin/dpkg-deb"
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+ return "dpkg";
+}
+
+/**
+ * gs_plugin_initialize:
+ */
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+ if (!g_file_test (DPKG_DEB_BINARY, G_FILE_TEST_EXISTS)) {
+ g_debug ("disabling '%s' as no %s available",
+ plugin->name, DPKG_DEB_BINARY);
+ gs_plugin_set_enabled (plugin, FALSE);
+ }
+}
+
+/**
+ * gs_plugin_file_to_app:
+ */
+gboolean
+gs_plugin_file_to_app (GsPlugin *plugin,
+ GList **list,
+ GFile *file,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsApp *app;
+ guint i;
+ g_autofree gchar *content_type = NULL;
+ g_autofree gchar *output = NULL;
+ g_auto(GStrv) argv = NULL;
+ g_auto(GStrv) tokens = NULL;
+ g_autoptr(GString) str = NULL;
+ const gchar *mimetypes[] = {
+ "application/vnd.debian.binary-package",
+ NULL };
+
+ /* does this match any of the mimetypes we support */
+ content_type = gs_utils_get_content_type (file, cancellable, error);
+ if (content_type == NULL)
+ return FALSE;
+ if (!g_strv_contains (mimetypes, content_type))
+ return TRUE;
+
+ /* exec sync */
+ argv = g_new0 (gchar *, 5);
+ argv[0] = g_strdup (DPKG_DEB_BINARY);
+ argv[1] = g_strdup ("--showformat=${Package}\\n"
+ "${Version}\\n"
+ "${Installed-Size}\\n"
+ "${Homepage}\\n"
+ "${Description}");
+ argv[2] = g_strdup ("-W");
+ argv[3] = g_file_get_path (file);
+ if (!g_spawn_sync (NULL, argv, NULL,
+ G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
+ NULL, NULL, &output, NULL, NULL, error))
+ return FALSE;
+
+ /* parse output */
+ tokens = g_strsplit (output, "\n", 0);
+ if (g_strv_length (tokens) < 5) {
+ g_set_error (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_FAILED,
+ "dpkg-deb output format incorrect:\n\"%s\"\n", output);
+ return FALSE;
+ }
+
+ /* create app */
+ app = gs_app_new (NULL);
+ gs_app_set_state (app, AS_APP_STATE_AVAILABLE_LOCAL);
+ gs_app_add_source (app, tokens[0]);
+ gs_app_set_name (app, GS_APP_QUALITY_LOWEST, tokens[0]);
+ gs_app_set_version (app, tokens[1]);
+ gs_app_set_size (app, 1024 * atoi (tokens[2]));
+ gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, tokens[3]);
+ gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, tokens[4]);
+ gs_app_set_kind (app, AS_APP_KIND_GENERIC);
+ gs_app_set_management_plugin (app, "apt");
+
+ /* multiline text */
+ str = g_string_new ("");
+ for (i = 5; tokens[i] != NULL; i++) {
+ if (g_strcmp0 (tokens[i], " .") == 0) {
+ if (str->len > 0)
+ g_string_truncate (str, str->len - 1);
+ g_string_append (str, "\n");
+ continue;
+ }
+ g_strstrip (tokens[i]);
+ g_string_append_printf (str, "%s ", tokens[i]);
+ }
+ if (str->len > 0)
+ g_string_truncate (str, str->len - 1);
+ gs_app_set_description (app, GS_APP_QUALITY_LOWEST, str->str);
+
+ /* success */
+ gs_plugin_add_app (list, app);
+ return TRUE;
+}
diff --git a/src/plugins/gs-plugin-packagekit-refresh.c b/src/plugins/gs-plugin-packagekit-refresh.c
index 38b6b4a..afb2f78 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -50,6 +50,17 @@ gs_plugin_get_name (void)
}
/**
+ * gs_plugin_get_conflicts:
+ */
+const gchar **
+gs_plugin_get_conflicts (GsPlugin *plugin)
+{
+ static const gchar *deps[] = {
+ NULL };
+ return deps;
+}
+
+/**
* gs_plugin_initialize:
*/
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]