[gnome-software/wip/rancell/ubuntu-provenance] Add a plugin to set Ubuntu provenance
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/rancell/ubuntu-provenance] Add a plugin to set Ubuntu provenance
- Date: Tue, 23 Feb 2016 03:08:56 +0000 (UTC)
commit f2c142b2544143622854e9f75c6b754c69c33ca4
Author: Robert Ancell <robert ancell canonical com>
Date: Fri Feb 12 11:13:50 2016 +1300
Add a plugin to set Ubuntu provenance
src/plugins/Makefile.am | 6 ++
src/plugins/gs-plugin-ubuntu-provenance.c | 136 +++++++++++++++++++++++++++++
2 files changed, 142 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index ed90743..c092346 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -41,6 +41,7 @@ plugin_LTLIBRARIES = \
libgs_plugin_fedora_provenance.la \
libgs_plugin_fedora_tagger_ratings.la \
libgs_plugin_fedora_tagger_usage.la \
+ libgs_plugin_ubuntu_provenance.la \
libgs_plugin_epiphany.la \
libgs_plugin_icons.la
@@ -114,6 +115,11 @@ libgs_plugin_appstream_la_LIBADD = $(GS_PLUGIN_LIBS) $(APPSTREAM_LIBS)
libgs_plugin_appstream_la_LDFLAGS = -module -avoid-version
libgs_plugin_appstream_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+libgs_plugin_ubuntu_provenance_la_SOURCES = gs-plugin-ubuntu-provenance.c
+libgs_plugin_ubuntu_provenance_la_LIBADD = $(GS_PLUGIN_LIBS)
+libgs_plugin_ubuntu_provenance_la_LDFLAGS = -module -avoid-version
+libgs_plugin_ubuntu_provenance_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+
if HAVE_LIMBA
libgs_plugin_limba_la_SOURCES = gs-plugin-limba.c
libgs_plugin_limba_la_LIBADD = $(GS_PLUGIN_LIBS) $(LIMBA_LIBS)
diff --git a/src/plugins/gs-plugin-ubuntu-provenance.c b/src/plugins/gs-plugin-ubuntu-provenance.c
new file mode 100644
index 0000000..b890244
--- /dev/null
+++ b/src/plugins/gs-plugin-ubuntu-provenance.c
@@ -0,0 +1,136 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 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 <gs-plugin.h>
+
+/*
+ * SECTION:
+ * Sets the package provanance to TRUE if installed by an official
+ * Ubuntu repo.
+ *
+ * It will self-disable if not run on a Ubuntu system.
+ */
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+ return "ubuntu-provenance";
+}
+
+/**
+ * gs_plugin_initialize:
+ */
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+ /* check that we are running on Ubuntu */
+ if (!gs_plugin_check_distro_id (plugin, "ubuntu")) {
+ gs_plugin_set_enabled (plugin, FALSE);
+ g_debug ("disabling '%s' as we're not Ubuntu", plugin->name);
+ return;
+ }
+}
+
+/**
+ * gs_plugin_get_deps:
+ */
+const gchar **
+gs_plugin_get_deps (GsPlugin *plugin)
+{
+ static const gchar *deps[] = {
+ "appstream", /* after the package origin is set */
+ NULL };
+ return deps;
+}
+
+/**
+ * gs_plugin_destroy:
+ */
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+}
+
+/**
+ * gs_plugin_ubuntu_provenance_refine_app:
+ */
+static void
+gs_plugin_ubuntu_provenance_refine_app (GsApp *app)
+{
+ const gchar *origin;
+ const gchar *releases[] = { "precise",
+ "trusty",
+ "vivid",
+ "wily",
+ "xenial",
+ NULL };
+ const gchar *repositories[] = { "main",
+ "universe",
+ "restricted",
+ "multiverse",
+ "updates",
+ "security",
+ "proposed",
+ "backports",
+ NULL };
+ gchar **tokens;
+
+ origin = gs_app_get_origin (app);
+ if (origin == NULL)
+ return;
+
+ tokens = g_strsplit (origin, "-", 2);
+ if (g_strv_length (tokens) == 2 && g_strv_contains (releases, tokens[0]) && g_strv_contains
(repositories, tokens[1]))
+ gs_app_set_provenance (app, TRUE);
+ g_strfreev (tokens);
+}
+
+/**
+ * gs_plugin_refine:
+ */
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GList **list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GList *l;
+ GsApp *app;
+
+ /* not required */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
+ return TRUE;
+
+ /* refine apps */
+ for (l = *list; l != NULL; l = l->next) {
+ app = GS_APP (l->data);
+ if (gs_app_get_provenance (app))
+ continue;
+ gs_plugin_ubuntu_provenance_refine_app (app);
+ }
+ return TRUE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]