[gnome-software/wip/rancell/ubuntu-3-20-5: 17/44] 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-5: 17/44] Add a dpkg plugin
- Date: Sat, 17 Jun 2017 12:26:39 +0000 (UTC)
commit 20c465f0ad4601a3916874d6cba74efc9b1a62fc
Author: Robert Ancell <robert ancell canonical com>
Date: Thu Apr 7 09:19:27 2016 +0100
Add a dpkg plugin
This commit is a combination of many changes by many people.
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 | 34 +++++++
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, 203 insertions(+), 0 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 2d6d390..7bee6e1 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -22,6 +22,7 @@
#include "config.h"
#include <glib-object.h>
+#include <glib/gstdio.h>
#include <stdlib.h>
#include "gs-app.h"
@@ -462,6 +463,37 @@ gs_auth_secret_func (void)
g_assert_cmpstr (gs_auth_get_metadata_item (auth2, "day"), ==, "monday");
}
+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;
+ g_autoptr(GFile) file = NULL;
+
+ /* load local file */
+ fn = gs_test_get_filename ("tests/chiron-1.1-1.deb");
+ g_assert (fn != NULL);
+ file = g_file_new_for_path (fn);
+ app = gs_plugin_loader_file_to_app (plugin_loader,
+ file,
+ 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.");
+ g_assert (gs_app_get_local_file (app) != NULL);
+}
+
int
main (int argc, char **argv)
{
@@ -472,6 +504,7 @@ main (int argc, char **argv)
g_autoptr(GsPluginLoader) plugin_loader = NULL;
const gchar *whitelist[] = {
"appstream",
+ "dpkg",
"dummy",
"epiphany",
"hardcoded-blacklist",
@@ -587,6 +620,7 @@ main (int argc, char **argv)
g_test_add_data_func ("/gnome-software/plugin-loader{distro-upgrades}",
plugin_loader,
(GTestDataFunc) gs_plugin_loader_distro_upgrades_func);
+
return g_test_run ();
}
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 616a062..de9a7e3 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -29,6 +29,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 \
@@ -77,6 +78,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 0ab2584..b1d6b96 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -87,6 +87,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 afe99d5..2b1c5f2 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]