[gnome-software] Add a plugin to auto-add some license information
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Add a plugin to auto-add some license information
- Date: Tue, 26 Apr 2016 18:11:21 +0000 (UTC)
commit 2be2c2b9d1715c4b4df521454acd24843a3d4703
Author: Richard Hughes <richard hughsie com>
Date: Tue Apr 26 19:06:17 2016 +0100
Add a plugin to auto-add some license information
For some distos we can infer that because an application has been installed
from a specific origin that it has to be free software. This means we can show
something relevant in the license field rather than declaring the application
as non-free.
It is of course better to ship an AppData file with the exact SPDX license
string but this information is not always available.
Distros will have to set the default values of the new GSettings keys, for
instance using 'debian-*-main' and 'https://www.debian.org/social_contract'
Based on a patch by Matthias Klumpp <mak debian org>, many thanks.
data/org.gnome.software.gschema.xml | 8 ++
src/gs-self-test.c | 7 +
src/plugins/Makefile.am | 6 +
src/plugins/gs-plugin-dummy.c | 8 +-
src/plugins/gs-plugin-provenance-license.c | 167 ++++++++++++++++++++++++++++
src/plugins/gs-plugin-provenance.c | 1 +
6 files changed, 196 insertions(+), 1 deletions(-)
---
diff --git a/data/org.gnome.software.gschema.xml b/data/org.gnome.software.gschema.xml
index 39752dc..1bb32b7 100644
--- a/data/org.gnome.software.gschema.xml
+++ b/data/org.gnome.software.gschema.xml
@@ -58,6 +58,14 @@
<default>[]</default>
<summary>A list of official sources that should not be considered 3rd party</summary>
</key>
+ <key name="free-sources" type="as">
+ <default>[]</default>
+ <summary>A list of official sources that should be considered free software</summary>
+ </key>
+ <key name="free-sources-url" type="s">
+ <default>''</default>
+ <summary>The licence URL to use when an application should be considered free software</summary>
+ </key>
<key name="show-folder-management" type="b">
<default>true</default>
<summary>Show the folder management UI</summary>
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 1388cb5..f634308 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -356,6 +356,8 @@ gs_plugin_loader_installed_func (GsPluginLoader *plugin_loader)
/* get installed packages */
list = gs_plugin_loader_get_installed (plugin_loader,
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN |
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_ADDONS |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE,
@@ -402,6 +404,8 @@ gs_plugin_loader_installed_func (GsPluginLoader *plugin_loader)
g_assert_cmpint (gs_app_get_state (addon), ==, AS_APP_STATE_UNKNOWN);
g_assert_cmpstr (gs_app_get_name (addon), ==, "Spell Check");
g_assert_cmpstr (gs_app_get_source_default (addon), ==, "zeus-spell");
+ g_assert_cmpstr (gs_app_get_license (addon), ==,
+ "<a href=\"https://www.debian.org/\">Free Software</a>");
g_assert (gs_app_get_pixbuf (addon) == NULL);
}
@@ -536,6 +540,7 @@ main (int argc, char **argv)
"menu-spec-refine",
"key-colors",
"provenance",
+ "provenance-license",
"packagekit-local",
NULL
};
@@ -547,6 +552,8 @@ main (int argc, char **argv)
g_setenv ("GS_SELF_TEST_LOCALE", "en_GB", TRUE);
g_setenv ("GS_SELF_TEST_DUMMY_ENABLE", "1", TRUE);
g_setenv ("GS_SELF_TEST_PROVENANCE_SOURCES", "london*,boston", TRUE);
+ g_setenv ("GS_SELF_TEST_PROVENANCE_LICENSE_SOURCES", "london*,boston", TRUE);
+ g_setenv ("GS_SELF_TEST_PROVENANCE_LICENSE_URL", "https://www.debian.org/", TRUE);
fn = gs_test_get_filename ("icons/hicolor/48x48/org.gnome.Software.png");
g_assert (fn != NULL);
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index ea8d975..bc36b73 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -36,6 +36,7 @@ plugin_LTLIBRARIES = \
libgs_plugin_menu-spec-refine.la \
libgs_plugin_fedora_distro_upgrades.la \
libgs_plugin_provenance.la \
+ libgs_plugin_provenance-license.la \
libgs_plugin_fedora_tagger_usage.la \
libgs_plugin_epiphany.la \
libgs_plugin_icons.la
@@ -122,6 +123,11 @@ libgs_plugin_provenance_la_LIBADD = $(GS_PLUGIN_LIBS)
libgs_plugin_provenance_la_LDFLAGS = -module -avoid-version
libgs_plugin_provenance_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+libgs_plugin_provenance_license_la_SOURCES = gs-plugin-provenance-license.c
+libgs_plugin_provenance_license_la_LIBADD = $(GS_PLUGIN_LIBS)
+libgs_plugin_provenance_license_la_LDFLAGS = -module -avoid-version
+libgs_plugin_provenance_license_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+
libgs_plugin_fedora_tagger_usage_la_SOURCES = gs-plugin-fedora-tagger-usage.c
libgs_plugin_fedora_tagger_usage_la_LIBADD = $(GS_PLUGIN_LIBS) $(SOUP_LIBS) $(SQLITE_LIBS)
libgs_plugin_fedora_tagger_usage_la_LDFLAGS = -module -avoid-version
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index e5c0115..a07ba7b 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -394,7 +394,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE) {
if (g_strcmp0 (gs_app_get_id (app), "chiron.desktop") == 0 ||
g_strcmp0 (gs_app_get_id (app), "zeus.desktop") == 0)
- gs_app_set_license (app, GS_APP_QUALITY_NORMAL, "GPL-2.0+");
+ gs_app_set_license (app, GS_APP_QUALITY_HIGHEST, "GPL-2.0+");
}
/* homepage */
@@ -405,6 +405,12 @@ gs_plugin_refine_app (GsPlugin *plugin,
}
}
+ /* origin */
+ if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN) {
+ if (g_strcmp0 (gs_app_get_id (app), "zeus-spell.addon") == 0)
+ gs_app_set_origin (app, "london-east");
+ }
+
/* description */
if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_DESCRIPTION) {
if (g_strcmp0 (gs_app_get_id (app), "chiron.desktop") == 0) {
diff --git a/src/plugins/gs-plugin-provenance-license.c b/src/plugins/gs-plugin-provenance-license.c
new file mode 100644
index 0000000..ec59c6f
--- /dev/null
+++ b/src/plugins/gs-plugin-provenance-license.c
@@ -0,0 +1,167 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2016 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2016 Matthias Klumpp <mak debian org>
+ *
+ * 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>
+#include <gs-utils.h>
+
+/*
+ * SECTION:
+ * Marks the application as Free Software if it comes from an origin
+ * that is recognized as being DFSGish-free.
+ */
+
+struct GsPluginData {
+ GSettings *settings;
+ gchar **sources;
+ gchar *license_id;
+};
+
+/**
+ * gs_plugin_provenance_license_get_sources:
+ */
+static gchar **
+gs_plugin_provenance_license_get_sources (GsPlugin *plugin)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ const gchar *tmp;
+
+ tmp = g_getenv ("GS_SELF_TEST_PROVENANCE_LICENSE_SOURCES");
+ if (tmp != NULL) {
+ g_debug ("using custom provenance_license sources of %s", tmp);
+ return g_strsplit (tmp, ",", -1);
+ }
+ return g_settings_get_strv (priv->settings, "free-sources");
+}
+
+/**
+ * gs_plugin_provenance_license_get_id:
+ */
+static gchar *
+gs_plugin_provenance_license_get_id (GsPlugin *plugin)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ const gchar *tmp;
+ g_autofree gchar *url = NULL;
+
+ tmp = g_getenv ("GS_SELF_TEST_PROVENANCE_LICENSE_URL");
+ if (tmp != NULL) {
+ g_debug ("using custom license generic sources of %s", tmp);
+ url = g_strdup (tmp);
+ } else {
+ url = g_settings_get_string (priv->settings, "free-sources-url");
+ if (url == NULL)
+ return g_strdup ("LicenseRef-free");
+ }
+ return g_strdup_printf ("LicenseRef-free=%s", url);
+}
+
+/**
+ * gs_plugin_provenance_license_changed_cb:
+ */
+static void
+gs_plugin_provenance_license_changed_cb (GSettings *settings,
+ const gchar *key,
+ GsPlugin *plugin)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ if (g_strcmp0 (key, "free-sources") == 0) {
+ g_strfreev (priv->sources);
+ priv->sources = gs_plugin_provenance_license_get_sources (plugin);
+ }
+ if (g_strcmp0 (key, "free-sources-url") == 0) {
+ g_free (priv->license_id);
+ priv->license_id = gs_plugin_provenance_license_get_id (plugin);
+ }
+}
+
+/**
+ * gs_plugin_initialize:
+ */
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+ GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ priv->settings = g_settings_new ("org.gnome.software");
+ g_signal_connect (priv->settings, "changed",
+ G_CALLBACK (gs_plugin_provenance_license_changed_cb), plugin);
+ priv->sources = gs_plugin_provenance_license_get_sources (plugin);
+ priv->license_id = gs_plugin_provenance_license_get_id (plugin);
+}
+
+/**
+ * gs_plugin_order_after:
+ */
+const gchar **
+gs_plugin_order_after (GsPlugin *plugin)
+{
+ static const gchar *deps[] = {
+ "provenance",
+ NULL };
+ return deps;
+}
+
+/**
+ * gs_plugin_destroy:
+ */
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_strfreev (priv->sources);
+ g_free (priv->license_id);
+ g_object_unref (priv->settings);
+}
+
+/**
+ * gs_plugin_refine_app:
+ */
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ const gchar *origin;
+
+ /* not required */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE) == 0)
+ return TRUE;
+
+ /* no provenance */
+ if (!gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE))
+ return TRUE;
+
+ /* nothing to search */
+ if (priv->sources == NULL || priv->sources[0] == NULL)
+ return TRUE;
+
+ /* simple case */
+ origin = gs_app_get_origin (app);
+ if (origin != NULL && gs_utils_strv_fnmatch (priv->sources, origin))
+ gs_app_set_license (app, GS_APP_QUALITY_NORMAL, priv->license_id);
+
+ return TRUE;
+}
diff --git a/src/plugins/gs-plugin-provenance.c b/src/plugins/gs-plugin-provenance.c
index 6474822..8b1ef72 100644
--- a/src/plugins/gs-plugin-provenance.c
+++ b/src/plugins/gs-plugin-provenance.c
@@ -86,6 +86,7 @@ const gchar **
gs_plugin_order_after (GsPlugin *plugin)
{
static const gchar *deps[] = {
+ "dummy",
"packagekit-refine", /* after the package source is set */
NULL };
return deps;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]