|
|
94e8a5 |
From 1ded5d5babfe620488aa8965c7fb922361fa6eaa Mon Sep 17 00:00:00 2001
|
|
|
94e8a5 |
From: Jaroslav Rohel <jrohel@redhat.com>
|
|
|
94e8a5 |
Date: Fri, 8 Nov 2019 13:27:17 +0100
|
|
|
94e8a5 |
Subject: [PATCH 1/2] Add repoquery command (RhBug:1769245)
|
|
|
94e8a5 |
|
|
|
94e8a5 |
Searches for selected packages and displays the requested information
|
|
|
94e8a5 |
about them.
|
|
|
94e8a5 |
|
|
|
94e8a5 |
Command options:
|
|
|
94e8a5 |
--available display available packages (default)
|
|
|
94e8a5 |
--installed display installed packages
|
|
|
94e8a5 |
|
|
|
94e8a5 |
Signed-off-by: Jaroslav Rohel <jrohel@redhat.com>
|
|
|
94e8a5 |
---
|
|
|
94e8a5 |
dnf/CMakeLists.txt | 6 +
|
|
|
94e8a5 |
dnf/meson.build | 9 +
|
|
|
94e8a5 |
dnf/plugins/repoquery/dnf-command-repoquery.c | 158 ++++++++++++++++++
|
|
|
94e8a5 |
.../dnf-command-repoquery.gresource.xml | 6 +
|
|
|
94e8a5 |
dnf/plugins/repoquery/dnf-command-repoquery.h | 33 ++++
|
|
|
94e8a5 |
dnf/plugins/repoquery/repoquery.plugin | 9 +
|
|
|
94e8a5 |
6 files changed, 221 insertions(+)
|
|
|
94e8a5 |
create mode 100644 dnf/plugins/repoquery/dnf-command-repoquery.c
|
|
|
94e8a5 |
create mode 100644 dnf/plugins/repoquery/dnf-command-repoquery.gresource.xml
|
|
|
94e8a5 |
create mode 100644 dnf/plugins/repoquery/dnf-command-repoquery.h
|
|
|
94e8a5 |
create mode 100644 dnf/plugins/repoquery/repoquery.plugin
|
|
|
94e8a5 |
|
|
|
94e8a5 |
diff --git a/dnf/CMakeLists.txt b/dnf/CMakeLists.txt
|
|
|
94e8a5 |
index eb73c11..2585c06 100644
|
|
|
94e8a5 |
--- a/dnf/CMakeLists.txt
|
|
|
94e8a5 |
+++ b/dnf/CMakeLists.txt
|
|
|
94e8a5 |
@@ -20,6 +20,11 @@ glib_compile_resources (DNF_COMMAND_REPOLIST plugins/repolist/dnf-command-repoli
|
|
|
94e8a5 |
INTERNAL)
|
|
|
94e8a5 |
list (APPEND DNF_COMMAND_REPOLIST "plugins/repolist/dnf-command-repolist.c")
|
|
|
94e8a5 |
|
|
|
94e8a5 |
+glib_compile_resources (DNF_COMMAND_REPOQUERY plugins/repoquery/dnf-command-repoquery.gresource.xml
|
|
|
94e8a5 |
+ C_PREFIX dnf_command_repoquery
|
|
|
94e8a5 |
+ INTERNAL)
|
|
|
94e8a5 |
+list (APPEND DNF_COMMAND_REPOQUERY "plugins/repoquery/dnf-command-repoquery.c")
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
glib_compile_resources (DNF_COMMAND_CLEAN plugins/clean/dnf-command-clean.gresource.xml
|
|
|
94e8a5 |
C_PREFIX dnf_command_clean
|
|
|
94e8a5 |
INTERNAL)
|
|
|
94e8a5 |
@@ -31,6 +36,7 @@ add_executable (microdnf dnf-main.c ${DNF_SRCS}
|
|
|
94e8a5 |
${DNF_COMMAND_REMOVE}
|
|
|
94e8a5 |
${DNF_COMMAND_UPDATE}
|
|
|
94e8a5 |
${DNF_COMMAND_REPOLIST}
|
|
|
94e8a5 |
+ ${DNF_COMMAND_REPOQUERY}
|
|
|
94e8a5 |
${DNF_COMMAND_CLEAN})
|
|
|
94e8a5 |
|
|
|
94e8a5 |
target_link_libraries (microdnf
|
|
|
94e8a5 |
diff --git a/dnf/meson.build b/dnf/meson.build
|
|
|
94e8a5 |
index d368180..d71a533 100644
|
|
|
94e8a5 |
--- a/dnf/meson.build
|
|
|
94e8a5 |
+++ b/dnf/meson.build
|
|
|
94e8a5 |
@@ -39,6 +39,15 @@ microdnf_srcs = [
|
|
|
94e8a5 |
),
|
|
|
94e8a5 |
'plugins/repolist/dnf-command-repolist.c',
|
|
|
94e8a5 |
|
|
|
94e8a5 |
+ # repoquery
|
|
|
94e8a5 |
+ gnome.compile_resources(
|
|
|
94e8a5 |
+ 'dnf-repoquery',
|
|
|
94e8a5 |
+ 'plugins/repoquery/dnf-command-repoquery.gresource.xml',
|
|
|
94e8a5 |
+ c_name : 'dnf_command_repoquery',
|
|
|
94e8a5 |
+ source_dir : 'plugins/repoquery',
|
|
|
94e8a5 |
+ ),
|
|
|
94e8a5 |
+ 'plugins/repoquery/dnf-command-repoquery.c',
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
# clean
|
|
|
94e8a5 |
gnome.compile_resources(
|
|
|
94e8a5 |
'dnf-clean',
|
|
|
94e8a5 |
diff --git a/dnf/plugins/repoquery/dnf-command-repoquery.c b/dnf/plugins/repoquery/dnf-command-repoquery.c
|
|
|
94e8a5 |
new file mode 100644
|
|
|
94e8a5 |
index 0000000..7db1a8f
|
|
|
94e8a5 |
--- /dev/null
|
|
|
94e8a5 |
+++ b/dnf/plugins/repoquery/dnf-command-repoquery.c
|
|
|
94e8a5 |
@@ -0,0 +1,158 @@
|
|
|
94e8a5 |
+/*
|
|
|
94e8a5 |
+ * Copyright (C) 2019 Red Hat, Inc.
|
|
|
94e8a5 |
+ *
|
|
|
94e8a5 |
+ * Licensed under the GNU Lesser General Public License Version 2.1
|
|
|
94e8a5 |
+ *
|
|
|
94e8a5 |
+ * This library is free software; you can redistribute it and/or
|
|
|
94e8a5 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
|
94e8a5 |
+ * License as published by the Free Software Foundation; either
|
|
|
94e8a5 |
+ * version 2.1 of the License, or (at your option) any later version.
|
|
|
94e8a5 |
+ *
|
|
|
94e8a5 |
+ * This library is distributed in the hope that it will be useful,
|
|
|
94e8a5 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
94e8a5 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
94e8a5 |
+ * Lesser General Public License for more details.
|
|
|
94e8a5 |
+ *
|
|
|
94e8a5 |
+ * You should have received a copy of the GNU Lesser General Public
|
|
|
94e8a5 |
+ * License along with this library; if not, write to the Free Software
|
|
|
94e8a5 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
94e8a5 |
+ */
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+#include "dnf-command-repoquery.h"
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+struct _DnfCommandRepoquery
|
|
|
94e8a5 |
+{
|
|
|
94e8a5 |
+ PeasExtensionBase parent_instance;
|
|
|
94e8a5 |
+};
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+static void dnf_command_repoquery_iface_init (DnfCommandInterface *iface);
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (DnfCommandRepoquery,
|
|
|
94e8a5 |
+ dnf_command_repoquery,
|
|
|
94e8a5 |
+ PEAS_TYPE_EXTENSION_BASE,
|
|
|
94e8a5 |
+ 0,
|
|
|
94e8a5 |
+ G_IMPLEMENT_INTERFACE (DNF_TYPE_COMMAND,
|
|
|
94e8a5 |
+ dnf_command_repoquery_iface_init))
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+static void
|
|
|
94e8a5 |
+dnf_command_repoquery_init (DnfCommandRepoquery *self)
|
|
|
94e8a5 |
+{
|
|
|
94e8a5 |
+}
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+static void
|
|
|
94e8a5 |
+disable_available_repos (DnfContext *ctx)
|
|
|
94e8a5 |
+{
|
|
|
94e8a5 |
+ GPtrArray *repos = dnf_context_get_repos (ctx);
|
|
|
94e8a5 |
+ for (guint i = 0; i < repos->len; ++i)
|
|
|
94e8a5 |
+ {
|
|
|
94e8a5 |
+ DnfRepo * repo = g_ptr_array_index (repos, i);
|
|
|
94e8a5 |
+ dnf_repo_set_enabled (repo, DNF_REPO_ENABLED_NONE);
|
|
|
94e8a5 |
+ }
|
|
|
94e8a5 |
+}
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+static gint
|
|
|
94e8a5 |
+gptrarr_dnf_package_cmp (gconstpointer a, gconstpointer b)
|
|
|
94e8a5 |
+{
|
|
|
94e8a5 |
+ return dnf_package_cmp(*(DnfPackage**)a, *(DnfPackage**)b);
|
|
|
94e8a5 |
+}
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+static gboolean
|
|
|
94e8a5 |
+dnf_command_repoquery_run (DnfCommand *cmd,
|
|
|
94e8a5 |
+ int argc,
|
|
|
94e8a5 |
+ char *argv[],
|
|
|
94e8a5 |
+ GOptionContext *opt_ctx,
|
|
|
94e8a5 |
+ DnfContext *ctx,
|
|
|
94e8a5 |
+ GError **error)
|
|
|
94e8a5 |
+{
|
|
|
94e8a5 |
+ gboolean opt_available = FALSE;
|
|
|
94e8a5 |
+ gboolean opt_installed = FALSE;
|
|
|
94e8a5 |
+ g_auto(GStrv) opt_key = NULL;
|
|
|
94e8a5 |
+ const GOptionEntry opts[] = {
|
|
|
94e8a5 |
+ { "available", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_available, "display available packages (default)", NULL },
|
|
|
94e8a5 |
+ { "installed", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_installed, "display installed packages", NULL },
|
|
|
94e8a5 |
+ { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &opt_key, NULL, NULL },
|
|
|
94e8a5 |
+ { NULL }
|
|
|
94e8a5 |
+ };
|
|
|
94e8a5 |
+ g_option_context_add_main_entries (opt_ctx, opts, NULL);
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ if (!g_option_context_parse (opt_ctx, &argc, &argv, error))
|
|
|
94e8a5 |
+ return FALSE;
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ // --available is default (compatibility with YUM/DNF)
|
|
|
94e8a5 |
+ if (!opt_available && !opt_installed)
|
|
|
94e8a5 |
+ opt_available = TRUE;
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ if (opt_available && opt_installed)
|
|
|
94e8a5 |
+ opt_available = opt_installed = FALSE;
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ if (opt_installed)
|
|
|
94e8a5 |
+ disable_available_repos (ctx);
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ DnfState * state = dnf_context_get_state (ctx);
|
|
|
94e8a5 |
+ DnfContextSetupSackFlags sack_flags = opt_available ? DNF_CONTEXT_SETUP_SACK_FLAG_SKIP_RPMDB
|
|
|
94e8a5 |
+ : DNF_CONTEXT_SETUP_SACK_FLAG_NONE;
|
|
|
94e8a5 |
+ dnf_context_setup_sack_with_flags (ctx, state, sack_flags, error);
|
|
|
94e8a5 |
+ DnfSack *sack = dnf_context_get_sack (ctx);
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ hy_autoquery HyQuery query = hy_query_create (sack);
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ if (opt_key)
|
|
|
94e8a5 |
+ {
|
|
|
94e8a5 |
+ hy_query_filter_empty (query);
|
|
|
94e8a5 |
+ for (char **pkey = opt_key; *pkey; ++pkey)
|
|
|
94e8a5 |
+ {
|
|
|
94e8a5 |
+ g_auto(HySubject) subject = hy_subject_create (*pkey);
|
|
|
94e8a5 |
+ HyNevra out_nevra;
|
|
|
94e8a5 |
+ hy_autoquery HyQuery key_query = hy_subject_get_best_solution (subject, sack, NULL,
|
|
|
94e8a5 |
+ &out_nevra, TRUE, TRUE, FALSE, TRUE, TRUE);
|
|
|
94e8a5 |
+ if (out_nevra)
|
|
|
94e8a5 |
+ hy_nevra_free(out_nevra);
|
|
|
94e8a5 |
+ hy_query_union (query, key_query);
|
|
|
94e8a5 |
+ }
|
|
|
94e8a5 |
+ }
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ g_autoptr(GPtrArray) pkgs = hy_query_run (query);
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ g_ptr_array_sort (pkgs, gptrarr_dnf_package_cmp);
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ // print packages without duplicated lines
|
|
|
94e8a5 |
+ const char *prev_line = "";
|
|
|
94e8a5 |
+ for (guint i = 0; i < pkgs->len; ++i)
|
|
|
94e8a5 |
+ {
|
|
|
94e8a5 |
+ DnfPackage *package = g_ptr_array_index (pkgs, i);
|
|
|
94e8a5 |
+ const char * line = dnf_package_get_nevra (package);
|
|
|
94e8a5 |
+ if (strcmp (line, prev_line) != 0)
|
|
|
94e8a5 |
+ {
|
|
|
94e8a5 |
+ g_print ("%s\n", line);
|
|
|
94e8a5 |
+ prev_line = line;
|
|
|
94e8a5 |
+ }
|
|
|
94e8a5 |
+ }
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ return TRUE;
|
|
|
94e8a5 |
+}
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+static void
|
|
|
94e8a5 |
+dnf_command_repoquery_class_init (DnfCommandRepoqueryClass *klass)
|
|
|
94e8a5 |
+{
|
|
|
94e8a5 |
+}
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+static void
|
|
|
94e8a5 |
+dnf_command_repoquery_iface_init (DnfCommandInterface *iface)
|
|
|
94e8a5 |
+{
|
|
|
94e8a5 |
+ iface->run = dnf_command_repoquery_run;
|
|
|
94e8a5 |
+}
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+static void
|
|
|
94e8a5 |
+dnf_command_repoquery_class_finalize (DnfCommandRepoqueryClass *klass)
|
|
|
94e8a5 |
+{
|
|
|
94e8a5 |
+}
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+G_MODULE_EXPORT void
|
|
|
94e8a5 |
+dnf_command_repoquery_register_types (PeasObjectModule *module)
|
|
|
94e8a5 |
+{
|
|
|
94e8a5 |
+ dnf_command_repoquery_register_type (G_TYPE_MODULE (module));
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ peas_object_module_register_extension_type (module,
|
|
|
94e8a5 |
+ DNF_TYPE_COMMAND,
|
|
|
94e8a5 |
+ DNF_TYPE_COMMAND_REPOQUERY);
|
|
|
94e8a5 |
+}
|
|
|
94e8a5 |
diff --git a/dnf/plugins/repoquery/dnf-command-repoquery.gresource.xml b/dnf/plugins/repoquery/dnf-command-repoquery.gresource.xml
|
|
|
94e8a5 |
new file mode 100644
|
|
|
94e8a5 |
index 0000000..6765af2
|
|
|
94e8a5 |
--- /dev/null
|
|
|
94e8a5 |
+++ b/dnf/plugins/repoquery/dnf-command-repoquery.gresource.xml
|
|
|
94e8a5 |
@@ -0,0 +1,6 @@
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+<gresources>
|
|
|
94e8a5 |
+ <gresource prefix="/org/fedoraproject/dnf/plugins/repoquery">
|
|
|
94e8a5 |
+ <file>repoquery.plugin</file>
|
|
|
94e8a5 |
+ </gresource>
|
|
|
94e8a5 |
+</gresources>
|
|
|
94e8a5 |
diff --git a/dnf/plugins/repoquery/dnf-command-repoquery.h b/dnf/plugins/repoquery/dnf-command-repoquery.h
|
|
|
94e8a5 |
new file mode 100644
|
|
|
94e8a5 |
index 0000000..80fae53
|
|
|
94e8a5 |
--- /dev/null
|
|
|
94e8a5 |
+++ b/dnf/plugins/repoquery/dnf-command-repoquery.h
|
|
|
94e8a5 |
@@ -0,0 +1,33 @@
|
|
|
94e8a5 |
+/*
|
|
|
94e8a5 |
+ * Copyright (C) 2019 Red Hat, Inc.
|
|
|
94e8a5 |
+ *
|
|
|
94e8a5 |
+ * Licensed under the GNU Lesser General Public License Version 2.1
|
|
|
94e8a5 |
+ *
|
|
|
94e8a5 |
+ * This library is free software; you can redistribute it and/or
|
|
|
94e8a5 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
|
94e8a5 |
+ * License as published by the Free Software Foundation; either
|
|
|
94e8a5 |
+ * version 2.1 of the License, or (at your option) any later version.
|
|
|
94e8a5 |
+ *
|
|
|
94e8a5 |
+ * This library is distributed in the hope that it will be useful,
|
|
|
94e8a5 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
94e8a5 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
94e8a5 |
+ * Lesser General Public License for more details.
|
|
|
94e8a5 |
+ *
|
|
|
94e8a5 |
+ * You should have received a copy of the GNU Lesser General Public
|
|
|
94e8a5 |
+ * License along with this library; if not, write to the Free Software
|
|
|
94e8a5 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
94e8a5 |
+ */
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+#pragma once
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+#include "dnf-command.h"
|
|
|
94e8a5 |
+#include <libpeas/peas.h>
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+G_BEGIN_DECLS
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+#define DNF_TYPE_COMMAND_REPOQUERY dnf_command_repoquery_get_type ()
|
|
|
94e8a5 |
+G_DECLARE_FINAL_TYPE (DnfCommandRepoquery, dnf_command_repoquery, DNF, COMMAND_REPOQUERY, PeasExtensionBase)
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+G_MODULE_EXPORT void dnf_command_repoquery_register_types (PeasObjectModule *module);
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+G_END_DECLS
|
|
|
94e8a5 |
diff --git a/dnf/plugins/repoquery/repoquery.plugin b/dnf/plugins/repoquery/repoquery.plugin
|
|
|
94e8a5 |
new file mode 100644
|
|
|
94e8a5 |
index 0000000..a107720
|
|
|
94e8a5 |
--- /dev/null
|
|
|
94e8a5 |
+++ b/dnf/plugins/repoquery/repoquery.plugin
|
|
|
94e8a5 |
@@ -0,0 +1,9 @@
|
|
|
94e8a5 |
+[Plugin]
|
|
|
94e8a5 |
+Module = command_repoquery
|
|
|
94e8a5 |
+Embedded = dnf_command_repoquery_register_types
|
|
|
94e8a5 |
+Name = repoquery
|
|
|
94e8a5 |
+Description = Search for packages matching keyword
|
|
|
94e8a5 |
+Authors = Jaroslav Rohel <jrohel@redhat.com>
|
|
|
94e8a5 |
+License = GPL-3.0+
|
|
|
94e8a5 |
+Copyright = Copyright (C) 2019 Red Hat, Inc.
|
|
|
94e8a5 |
+X-Command-Syntax = repoquery [OPTION…] [KEY…]
|
|
|
94e8a5 |
--
|
|
|
94e8a5 |
2.21.0
|
|
|
94e8a5 |
|
|
|
94e8a5 |
|
|
|
94e8a5 |
From 99831d883f2a95f3540a844fe8455f896b9b097d Mon Sep 17 00:00:00 2001
|
|
|
94e8a5 |
From: Jaroslav Rohel <jrohel@redhat.com>
|
|
|
94e8a5 |
Date: Sun, 10 Nov 2019 15:32:31 +0100
|
|
|
94e8a5 |
Subject: [PATCH 2/2] [repoquery] add "--info" and "--nevra" options
|
|
|
94e8a5 |
|
|
|
94e8a5 |
--info show detailed information about the packages
|
|
|
94e8a5 |
--nevra use name-epoch:version-release.architecture format
|
|
|
94e8a5 |
for displaying packages (default)
|
|
|
94e8a5 |
|
|
|
94e8a5 |
Signed-off-by: Jaroslav Rohel <jrohel@redhat.com>
|
|
|
94e8a5 |
---
|
|
|
94e8a5 |
dnf/plugins/repoquery/dnf-command-repoquery.c | 68 +++++++++++++++++--
|
|
|
94e8a5 |
1 file changed, 63 insertions(+), 5 deletions(-)
|
|
|
94e8a5 |
|
|
|
94e8a5 |
diff --git a/dnf/plugins/repoquery/dnf-command-repoquery.c b/dnf/plugins/repoquery/dnf-command-repoquery.c
|
|
|
94e8a5 |
index 7db1a8f..721c990 100644
|
|
|
94e8a5 |
--- a/dnf/plugins/repoquery/dnf-command-repoquery.c
|
|
|
94e8a5 |
+++ b/dnf/plugins/repoquery/dnf-command-repoquery.c
|
|
|
94e8a5 |
@@ -20,6 +20,8 @@
|
|
|
94e8a5 |
|
|
|
94e8a5 |
#include "dnf-command-repoquery.h"
|
|
|
94e8a5 |
|
|
|
94e8a5 |
+#include <libsmartcols.h>
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
struct _DnfCommandRepoquery
|
|
|
94e8a5 |
{
|
|
|
94e8a5 |
PeasExtensionBase parent_instance;
|
|
|
94e8a5 |
@@ -56,6 +58,49 @@ gptrarr_dnf_package_cmp (gconstpointer a, gconstpointer b)
|
|
|
94e8a5 |
return dnf_package_cmp(*(DnfPackage**)a, *(DnfPackage**)b);
|
|
|
94e8a5 |
}
|
|
|
94e8a5 |
|
|
|
94e8a5 |
+static void
|
|
|
94e8a5 |
+package_info_add_line (struct libscols_table *table, const char *key, const char *value)
|
|
|
94e8a5 |
+{
|
|
|
94e8a5 |
+ struct libscols_line *ln = scols_table_new_line (table, NULL);
|
|
|
94e8a5 |
+ scols_line_set_data (ln, 0, key);
|
|
|
94e8a5 |
+ scols_line_set_data (ln, 1, value);
|
|
|
94e8a5 |
+}
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+static void
|
|
|
94e8a5 |
+print_package_info (DnfPackage *package)
|
|
|
94e8a5 |
+{
|
|
|
94e8a5 |
+ struct libscols_table *table = scols_new_table ();
|
|
|
94e8a5 |
+ scols_table_enable_noheadings (table, 1);
|
|
|
94e8a5 |
+ scols_table_set_column_separator (table, " : ");
|
|
|
94e8a5 |
+ scols_table_new_column (table, "key", 5, 0);
|
|
|
94e8a5 |
+ struct libscols_column *cl = scols_table_new_column (table, "value", 10, SCOLS_FL_WRAP);
|
|
|
94e8a5 |
+ scols_column_set_safechars (cl, "\n");
|
|
|
94e8a5 |
+ scols_column_set_wrapfunc (cl, scols_wrapnl_chunksize, scols_wrapnl_nextchunk, NULL);
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ package_info_add_line (table, "Name", dnf_package_get_name (package));
|
|
|
94e8a5 |
+ guint64 epoch = dnf_package_get_epoch (package);
|
|
|
94e8a5 |
+ if (epoch != 0)
|
|
|
94e8a5 |
+ {
|
|
|
94e8a5 |
+ g_autofree gchar *str_epoch = g_strdup_printf ("%ld", epoch);
|
|
|
94e8a5 |
+ package_info_add_line (table, "Epoch", str_epoch);
|
|
|
94e8a5 |
+ }
|
|
|
94e8a5 |
+ package_info_add_line (table, "Version", dnf_package_get_version (package));
|
|
|
94e8a5 |
+ package_info_add_line (table, "Release", dnf_package_get_release (package));
|
|
|
94e8a5 |
+ package_info_add_line (table, "Architecture", dnf_package_get_arch (package));
|
|
|
94e8a5 |
+ g_autofree gchar *size = g_format_size_full (dnf_package_get_size (package),
|
|
|
94e8a5 |
+ G_FORMAT_SIZE_LONG_FORMAT | G_FORMAT_SIZE_IEC_UNITS);
|
|
|
94e8a5 |
+ package_info_add_line (table, "Size", size);
|
|
|
94e8a5 |
+ package_info_add_line (table, "Source", dnf_package_get_sourcerpm (package));
|
|
|
94e8a5 |
+ package_info_add_line (table, "Repository", dnf_package_get_reponame (package));
|
|
|
94e8a5 |
+ package_info_add_line (table, "Summanry", dnf_package_get_summary (package));
|
|
|
94e8a5 |
+ package_info_add_line (table, "URL", dnf_package_get_url (package));
|
|
|
94e8a5 |
+ package_info_add_line (table, "License", dnf_package_get_license (package));
|
|
|
94e8a5 |
+ package_info_add_line (table, "Description", dnf_package_get_description (package));
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
+ scols_print_table (table);
|
|
|
94e8a5 |
+ scols_unref_table (table);
|
|
|
94e8a5 |
+}
|
|
|
94e8a5 |
+
|
|
|
94e8a5 |
static gboolean
|
|
|
94e8a5 |
dnf_command_repoquery_run (DnfCommand *cmd,
|
|
|
94e8a5 |
int argc,
|
|
|
94e8a5 |
@@ -65,11 +110,16 @@ dnf_command_repoquery_run (DnfCommand *cmd,
|
|
|
94e8a5 |
GError **error)
|
|
|
94e8a5 |
{
|
|
|
94e8a5 |
gboolean opt_available = FALSE;
|
|
|
94e8a5 |
+ gboolean opt_info = FALSE;
|
|
|
94e8a5 |
gboolean opt_installed = FALSE;
|
|
|
94e8a5 |
+ gboolean opt_nevra = FALSE;
|
|
|
94e8a5 |
g_auto(GStrv) opt_key = NULL;
|
|
|
94e8a5 |
const GOptionEntry opts[] = {
|
|
|
94e8a5 |
{ "available", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_available, "display available packages (default)", NULL },
|
|
|
94e8a5 |
+ { "info", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_info, "show detailed information about the packages", NULL },
|
|
|
94e8a5 |
{ "installed", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_installed, "display installed packages", NULL },
|
|
|
94e8a5 |
+ { "nevra", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_nevra,
|
|
|
94e8a5 |
+ "use name-epoch:version-release.architecture format for displaying packages (default)", NULL },
|
|
|
94e8a5 |
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &opt_key, NULL, NULL },
|
|
|
94e8a5 |
{ NULL }
|
|
|
94e8a5 |
};
|
|
|
94e8a5 |
@@ -115,16 +165,24 @@ dnf_command_repoquery_run (DnfCommand *cmd,
|
|
|
94e8a5 |
|
|
|
94e8a5 |
g_ptr_array_sort (pkgs, gptrarr_dnf_package_cmp);
|
|
|
94e8a5 |
|
|
|
94e8a5 |
- // print packages without duplicated lines
|
|
|
94e8a5 |
const char *prev_line = "";
|
|
|
94e8a5 |
for (guint i = 0; i < pkgs->len; ++i)
|
|
|
94e8a5 |
{
|
|
|
94e8a5 |
DnfPackage *package = g_ptr_array_index (pkgs, i);
|
|
|
94e8a5 |
- const char * line = dnf_package_get_nevra (package);
|
|
|
94e8a5 |
- if (strcmp (line, prev_line) != 0)
|
|
|
94e8a5 |
+ if (opt_nevra || !opt_info)
|
|
|
94e8a5 |
+ {
|
|
|
94e8a5 |
+ const char * line = dnf_package_get_nevra (package);
|
|
|
94e8a5 |
+ // print nevras without duplicated lines
|
|
|
94e8a5 |
+ if (opt_info || strcmp (line, prev_line) != 0)
|
|
|
94e8a5 |
+ {
|
|
|
94e8a5 |
+ g_print ("%s\n", line);
|
|
|
94e8a5 |
+ prev_line = line;
|
|
|
94e8a5 |
+ }
|
|
|
94e8a5 |
+ }
|
|
|
94e8a5 |
+ if (opt_info)
|
|
|
94e8a5 |
{
|
|
|
94e8a5 |
- g_print ("%s\n", line);
|
|
|
94e8a5 |
- prev_line = line;
|
|
|
94e8a5 |
+ print_package_info (package);
|
|
|
94e8a5 |
+ g_print ("\n");
|
|
|
94e8a5 |
}
|
|
|
94e8a5 |
}
|
|
|
94e8a5 |
|
|
|
94e8a5 |
--
|
|
|
94e8a5 |
2.21.0
|
|
|
94e8a5 |
|