[gnome-software] Add an outline ostree plugin that just adds remotes as sources
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Add an outline ostree plugin that just adds remotes as sources
- Date: Fri, 25 Mar 2016 09:54:10 +0000 (UTC)
commit b66acbedac5cae9be2bc02977aa81d8b5e31172e
Author: Richard Hughes <richard hughsie com>
Date: Thu Mar 24 19:49:21 2016 +0000
Add an outline ostree plugin that just adds remotes as sources
configure.ac | 23 +++++++
src/plugins/Makefile.am | 12 ++++
src/plugins/gs-plugin-ostree.c | 143 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 178 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5d6999b..28f4e5f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -179,6 +179,28 @@ AS_IF([test "x$have_xdg_app" = "xyes"], [
])
AM_CONDITIONAL(HAVE_XDG_APP, test "$have_xdg_app" != no)
+# ostree
+AC_ARG_ENABLE(ostree,
+ [AS_HELP_STRING([--enable-ostree],
+ [enable ostree support [default=auto]])],,
+ enable_ostree=maybe)
+AS_IF([test "x$enable_ostree" != "xno"], [
+ PKG_CHECK_MODULES(OSTREE,
+ [ostree-1],
+ [have_ostree=yes],
+ [have_ostree=no])
+], [
+ have_ostree=no
+])
+AS_IF([test "x$have_ostree" = "xyes"], [
+ AC_DEFINE(HAVE_OSTREE,1,[Build ostree support])
+], [
+ AS_IF([test "x$enable_ostree" = "xyes"], [
+ AC_MSG_ERROR([ostree support requested but 'ostree' was not found])
+ ])
+])
+AM_CONDITIONAL(HAVE_OSTREE, test "$have_ostree" != no)
+
# Limba
AC_ARG_ENABLE(limba,
[AS_HELP_STRING([--enable-limba],
@@ -285,6 +307,7 @@ echo "
Firmware support: ${have_firmware}
Limba support: ${have_limba}
XDG-APP support: ${have_xdg_app}
+ OSTree support: ${have_ostree}
Steam support: ${enable_steam}
GNOME Shell ext. support: ${enable_shell_extensions}
ODRS support: ${enable_odrs}
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index a0f7803..d0ddf85 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -12,6 +12,7 @@ AM_CPPFLAGS = \
$(FWUPD_CFLAGS) \
$(JSON_GLIB_CFLAGS) \
$(LIMBA_CFLAGS) \
+ $(OSTREE_CFLAGS) \
$(XDG_APP_CFLAGS) \
-DBINDIR=\"$(bindir)\" \
-DDATADIR=\"$(datadir)\" \
@@ -67,6 +68,10 @@ if HAVE_XDG_APP
plugin_LTLIBRARIES += libgs_plugin_xdg_app.la
endif
+if HAVE_OSTREE
+plugin_LTLIBRARIES += libgs_plugin_ostree.la
+endif
+
if HAVE_LIMBA
plugin_LTLIBRARIES += libgs_plugin_limba.la
endif
@@ -143,6 +148,13 @@ libgs_plugin_xdg_app_la_LDFLAGS = -module -avoid-version
libgs_plugin_xdg_app_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
endif
+if HAVE_OSTREE
+libgs_plugin_ostree_la_SOURCES = gs-plugin-ostree.c
+libgs_plugin_ostree_la_LIBADD = $(GS_PLUGIN_LIBS) $(OSTREE_LIBS)
+libgs_plugin_ostree_la_LDFLAGS = -module -avoid-version
+libgs_plugin_ostree_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+endif
+
if HAVE_ODRS
libgs_plugin_odrs_la_SOURCES = gs-plugin-odrs.c
libgs_plugin_odrs_la_LIBADD = $(GS_PLUGIN_LIBS) $(JSON_GLIB_LIBS)
diff --git a/src/plugins/gs-plugin-ostree.c b/src/plugins/gs-plugin-ostree.c
new file mode 100644
index 0000000..7d4ad2b
--- /dev/null
+++ b/src/plugins/gs-plugin-ostree.c
@@ -0,0 +1,143 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2016 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 <ostree.h>
+#include <gio/gio.h>
+#include <glib/gstdio.h>
+
+#include <gs-plugin.h>
+
+#include "gs-utils.h"
+
+struct GsPluginPrivate {
+ OstreeRepo *ostree_repo;
+};
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+ return "ostree";
+}
+
+/**
+ * gs_plugin_initialize:
+ */
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+ plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+
+ /* only works on OSTree */
+ if (!g_file_test ("/run/ostree-booted", G_FILE_TEST_EXISTS)) {
+ gs_plugin_set_enabled (plugin, FALSE);
+ return;
+ }
+}
+
+/**
+ * gs_plugin_destroy:
+ */
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+ if (plugin->priv->ostree_repo != NULL)
+ g_object_unref (plugin->priv->ostree_repo);
+}
+
+/**
+ * gs_plugin_startup:
+ */
+static gboolean
+gs_plugin_startup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
+{
+ /* already started */
+ if (plugin->priv->ostree_repo != NULL)
+ return TRUE;
+
+ /* open */
+ plugin->priv->ostree_repo = ostree_repo_new_default ();
+ if (!ostree_repo_open (plugin->priv->ostree_repo, cancellable, error))
+ return FALSE;
+ return TRUE;
+}
+
+/**
+ * gs_plugin_add_sources:
+ */
+gboolean
+gs_plugin_add_sources (GsPlugin *plugin,
+ GList **list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ guint i;
+ g_auto(GStrv) names = NULL;
+
+ /* set up plugin */
+ if (!gs_plugin_startup (plugin, cancellable, error))
+ return FALSE;
+
+ /* get all remotes */
+ names = ostree_repo_remote_list (plugin->priv->ostree_repo, NULL);
+ if (names == NULL)
+ return TRUE;
+ for (i = 0; names[i] != NULL; i++) {
+ g_autofree gchar *url = NULL;
+ g_autoptr(GsApp) app = NULL;
+
+ /* get info */
+ if (!ostree_repo_remote_get_url (plugin->priv->ostree_repo,
+ names[i], &url, error))
+ return FALSE;
+
+ /* create app */
+ app = gs_app_new (names[i]);
+ gs_app_set_management_plugin (app, "ostree");
+ gs_app_set_kind (app, AS_APP_KIND_SOURCE);
+ gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+ gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, url);
+ gs_app_set_name (app, GS_APP_QUALITY_LOWEST, names[i]);
+ }
+
+ return TRUE;
+}
+
+/**
+ * gs_plugin_refresh:
+ */
+gboolean
+gs_plugin_refresh (GsPlugin *plugin,
+ guint cache_age,
+ GsPluginRefreshFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* set up plugin */
+ if (!gs_plugin_startup (plugin, cancellable, error))
+ return FALSE;
+
+ return TRUE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]