Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add command "pkg-detail" #12

Open
wants to merge 3 commits into from

2 participants

@ekd123

zif pkg-detail zif description
zif pkg-detail zif version
zif info-only yum summary

My version just checks out the information from the remote repositories.
By the way, please take a look at line 1168, I really don't know why.

Maybe this patch seems a little dirty.

@ekd123 ekd123 Add a command called 'pkg-detail' which displays only one detail abou…
…t a package from the remote repositories, with an alias to it named 'info-only'.

This allows you, for example, to get the URL of PACKAGE using 'zif pkg-detail PACKAGE url'
45d3a6e
@ekd123

I forgot to say that the output format of command 'info' is changed, too. It looks cleaner than before.

Well, maybe still buggy.

@hughsie
Owner

commit 50c3ea2
Author: Richard Hughes richard@hughsie.com
Date: Mon Apr 23 17:10:55 2012 +0100

Pad the output of 'zif get-details pkgname' in a better way

Inspired from a patch by Mike Manilone <crtmike@gmail.com>, many thanks.
tools/zif-main.c
((4 lines not shown))
+ * zif_cmd_pkg_detail:
+ */
+static gboolean
+zif_cmd_pkg_detail (ZifCmdPrivate *priv, gchar **values, GError **error)
+{
+ ZifPackage *package = NULL;
+ ZifState *state_local = NULL;
+ GPtrArray *store_array = NULL;
+ gchar *tmp_strv[2] = { NULL, NULL };
+ GPtrArray *array = NULL;
+ GString *string = NULL;
+ gboolean ret = FALSE;
+
+ zif_progress_bar_start (priv->progressbar, _("Getting the detail"));
+
+ ret = zif_state_set_steps (priv->state,
@hughsie Owner
hughsie added a note

This needs to set the correct number of steps. If there are two steps, and the first takes 20% of the time and the second takes 80% of the time, then this would be 20, 80, -1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tools/zif-main.c
((28 lines not shown))
+ if (!ret)
+ goto out;
+
+ /* add remote packages */
+ store_array = zif_store_array_new ();
+ state_local = zif_state_get_child (priv->state);
+ ret= zif_store_array_add_remote_enabled (store_array, state_local, error);
+ if (!ret)
+ goto out;
+
+ /* this section done */
+ ret = zif_state_done (priv->state, error);
+ if (!ret)
+ goto out;
+
+ /* check we have a value */
@hughsie Owner
hughsie added a note

We probably want to check the number of arguments using g_strv_length(values) rather than doing it one by one. Then we can have something like "Specify a package name and data type, e.g. 'colord url'"

@ekd123
ekd123 added a note

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tools/zif-main.c
((67 lines not shown))
+ goto out;
+ }
+
+ /* filter the results in a sane way */
+ ret = zif_filter_post_resolve (priv, array, error);
+ if (!ret)
+ goto out;
+
+ if (array->len == 0) {
+ g_set_error_literal (error, 1, 0,
+ _("No package was found"));
+ goto out;
+ }
+
+ string = g_string_new ("");
+ package = g_ptr_array_index (array, 0);
@hughsie Owner
hughsie added a note

What happens when we have more than one package that matches? Do we just assume that the installed package is the same as all the remote packages? That's probably a sane assumption, until we get to the package size, where the user might want the installed size of the package, not the remote .rpm size, or vice versa.

@ekd123
ekd123 added a note

now works if more than one package matches.
added options just like Yum's "available/installed".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tools/zif-main.c
((69 lines not shown))
+
+ /* filter the results in a sane way */
+ ret = zif_filter_post_resolve (priv, array, error);
+ if (!ret)
+ goto out;
+
+ if (array->len == 0) {
+ g_set_error_literal (error, 1, 0,
+ _("No package was found"));
+ goto out;
+ }
+
+ string = g_string_new ("");
+ package = g_ptr_array_index (array, 0);
+ state_local = zif_state_get_child (priv->state);
+ if (!g_strcmp0 (values[1], "name"))
@hughsie Owner
hughsie added a note

The convention I've used in other places in the code is g_strcmp0 (value, "value") == 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tools/zif-main.c
((90 lines not shown))
+ else if (!g_strcmp0 (values[1], "size")) {
+ g_string_append_printf (string, "%" G_GUINT64_FORMAT "\n", zif_package_get_size (package, state_local, NULL));
+ }
+ else if (!g_strcmp0 (values[1], "repo"))
+ g_string_append_printf (string, "%s\n", zif_package_get_data (package));
+ else if (!g_strcmp0 (values[1], "summary"))
+ g_string_append_printf (string, "%s\n", zif_package_get_summary (package, state_local, NULL));
+ else if (!g_strcmp0 (values[1], "url"))
+ g_string_append_printf (string, "%s\n", zif_package_get_url (package, state_local, NULL));
+ else if (!g_strcmp0 (values[1], "license"))
+ g_string_append_printf (string, "%s\n", zif_package_get_license (package, state_local, NULL));
+ else if (!g_strcmp0 (values[1], "description"))
+ g_string_append_printf (string, "%s\n", zif_package_get_description (package, state_local, NULL));
+
+ /* this section done */
+ /* if we use this code, it will print "The system state was invalid: done on a state 0xXXXX that did not have a size set!" */
@hughsie Owner
hughsie added a note

Fix the steps, and you can enable this :)

@ekd123
ekd123 added a note

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@hughsie hughsie commented on the diff
tools/zif-main.c
@@ -6797,6 +6923,11 @@ typedef gboolean (*ZifCmdPrivateCb) (ZifCmdPrivate *cmd,
_("Display details about a package or group of packages"),
zif_cmd_get_details);
zif_cmd_add (priv->cmd_array,
@hughsie Owner
hughsie added a note

"pkg-detail" make sense, but the second things are designed to make zif more compatible with yum. I think we can just drop info-only.

@ekd123
ekd123 added a note

dropped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ekd123

Sorry, these days I have some work to do. I'll work on this feature again in a few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 23, 2012
  1. @ekd123

    Add a command called 'pkg-detail' which displays only one detail abou…

    ekd123 authored
    …t a package from the remote repositories, with an alias to it named 'info-only'.
    
    This allows you, for example, to get the URL of PACKAGE using 'zif pkg-detail PACKAGE url'
Commits on May 6, 2012
  1. @ekd123

    trivial: fix pkg-detail

    ekd123 authored
  2. @ekd123
This page is out of date. Refresh to see the latest.
Showing with 175 additions and 9 deletions.
  1. +175 −9 tools/zif-main.c
View
184 tools/zif-main.c
@@ -1064,6 +1064,167 @@ zif_cmd_get_depends (ZifCmdPrivate *priv, gchar **values, GError **error)
}
/**
+ * zif_cmd_pkg_detail:
+ */
+static gboolean
+zif_cmd_pkg_detail (ZifCmdPrivate *priv, gchar **values, GError **error)
+{
+ ZifPackage *package = NULL;
+ ZifState *state_local = NULL;
+ GPtrArray *store_array = NULL;
+ gchar *tmp_strv[2] = { NULL, NULL };
+ GPtrArray *array = NULL;
+ GString *string = NULL;
+ guint i;
+ gchar *data = NULL;
+ gchar *package_name = NULL;
+ gboolean ret = FALSE;
+ gboolean only_available = FALSE, only_installed = FALSE;
+
+ zif_progress_bar_start (priv->progressbar, _("Getting the detail"));
+
+ ret = zif_state_set_steps (priv->state,
+ error,
+ 20,
+ 20,
+ 20,
+ 20,
+ 20,
+ -1);
+
+ if (!ret)
+ goto out;
+
+ /* check if we have arguments */
+ if (g_strv_length (values) < 2 || g_strv_length (values) > 3)
+ {
+ g_set_error_literal (error, 1, 0,
+ _("Specify a package and data type (or with installed/available)\n"
+ "e.g. 'installed kernel size'"));
+ }
+ if (!g_strcmp0 (values[0], "installed"))
+ only_installed = TRUE;
+ else if (!g_strcmp0 (values[0], "available"))
+ only_available = TRUE;
+ else {
+ package_name = values[0];
+ data = values[1];
+ }
+ if (only_available || only_installed) {
+ package_name = values[1];
+ data = values[2];
+ }
+
+ store_array = zif_store_array_new ();
+ /* add remote packages */
+ if (!only_installed) {
+ state_local = zif_state_get_child (priv->state);
+ ret= zif_store_array_add_remote_enabled (store_array, state_local, error);
+ if (!ret)
+ goto out;
+
+ /* this section done */
+ ret = zif_state_done (priv->state, error);
+ if (!ret)
+ goto out;
+ }
+
+ /* add local packages */
+ if (!only_available) {
+ state_local = zif_state_get_child (priv->state);
+ ret = zif_store_array_add_local (store_array, state_local ,error);
+ if (!ret)
+ goto out;
+
+ /* this section done */
+ ret = zif_state_done (priv->state, error);
+ if (!ret)
+ goto out;
+ }
+
+ state_local = zif_state_get_child (priv->state);
+ tmp_strv[0] = package_name;
+ array = zif_store_array_resolve (store_array,
+ tmp_strv,
+ state_local,
+ error);
+ if (array == NULL) {
+ ret = FALSE;
+ goto out;
+ }
+
+ /* filter the results in a sane way */
+ ret = zif_filter_post_resolve (priv, array, error);
+ if (!ret)
+ goto out;
+
+ if (array->len == 0) {
+ g_set_error_literal (error, 1, 0,
+ _("No package was found"));
+ goto out;
+ }
+
+ string = g_string_new ("");
+ state_local = NULL;
+ for (i = 0; i < array->len; i++) {
+ package = g_ptr_array_index (array, i);
+ if (!g_strcmp0 (data, "name"))
+ g_string_append_printf (string, "%s\n", zif_package_get_name (package));
+ else if (!g_strcmp0 (data, "version"))
+ g_string_append_printf (string, "%s\n", zif_package_get_version (package));
+ else if (!g_strcmp0 (data, "arch"))
+ g_string_append_printf (string, "%s\n", zif_package_get_arch (package));
+ else if (!g_strcmp0 (data, "size")) {
+ state_local = zif_state_get_child (priv->state);
+ g_string_append_printf (string, "%" G_GUINT64_FORMAT "\n", zif_package_get_size (package, state_local, NULL));
+ }
+ else if (!g_strcmp0 (data, "repo"))
+ g_string_append_printf (string, "%s\n", zif_package_get_data (package));
+ else if (!g_strcmp0 (data, "summary")) {
+ state_local = zif_state_get_child (priv->state);
+ g_string_append_printf (string, "%s\n", zif_package_get_summary (package, state_local, NULL));
+ }
+ else if (!g_strcmp0 (data, "url")) {
+ state_local = zif_state_get_child (priv->state);
+ g_string_append_printf (string, "%s\n", zif_package_get_url (package, state_local, NULL));
+ }
+ else if (!g_strcmp0 (data, "license")) {
+ state_local = zif_state_get_child (priv->state);
+ g_string_append_printf (string, "%s\n", zif_package_get_license (package, state_local, NULL));
+ }
+ else if (!g_strcmp0 (data, "description")) {
+ state_local = zif_state_get_child (priv->state);
+ g_string_append_printf (string, "%s\n", zif_package_get_description (package, state_local, NULL));
+ }
+ }
+ /* this section done */
+ if (!state_local)
+ ret = zif_state_done (state_local, error);
+ else
+ ret = TRUE;
+ if (!ret)
+ goto out;
+ ret = zif_state_done (priv->state, error);
+ if (!ret)
+ goto out;
+
+ /* print what we've got */
+ zif_progress_bar_end (priv->progressbar);
+ g_print ("%s", string->str);
+
+ /* success */
+ ret = TRUE;
+out:
+ if (string != NULL)
+ g_string_free (string, TRUE);
+ if (store_array != NULL)
+ g_ptr_array_unref (store_array);
+ if (array != NULL)
+ g_ptr_array_unref (array);
+ return ret;
+}
+
+/**
* zif_cmd_get_details:
**/
static gboolean
@@ -1171,15 +1332,15 @@ zif_cmd_get_details (ZifCmdPrivate *priv, gchar **values, GError **error)
size = zif_package_get_size (package, state_loop, NULL);
/* TRANSLATORS: these are headers for the package data */
- g_string_append_printf (string, "%s\t : %s\n", _("Name"), zif_package_get_name (package));
- g_string_append_printf (string, "%s\t : %s\n", _("Version"), zif_package_get_version (package));
- g_string_append_printf (string, "%s\t : %s\n", _("Arch"), zif_package_get_arch (package));
- g_string_append_printf (string, "%s\t : %" G_GUINT64_FORMAT " bytes\n", _("Size"), size);
- g_string_append_printf (string, "%s\t : %s\n", _("Repo"), zif_package_get_data (package));
- g_string_append_printf (string, "%s\t : %s\n", _("Summary"), summary);
- g_string_append_printf (string, "%s\t : %s\n", _("URL"), url);
- g_string_append_printf (string, "%s\t : %s\n", _("License"), license);
- g_string_append_printf (string, "%s\t : %s\n", _("Description"), description);
+ g_string_append_printf (string, _("Name : %s\n"), zif_package_get_name (package));
+ g_string_append_printf (string, _("Version : %s\n"), zif_package_get_version (package));
+ g_string_append_printf (string, _("Arch : %s\n"), zif_package_get_arch (package));
+ g_string_append_printf (string, _("Size : %" G_GUINT64_FORMAT " bytes\n"), size);
+ g_string_append_printf (string, _("Repo : %s\n"), zif_package_get_data (package));
+ g_string_append_printf (string, _("Summary : %s\n"), summary);
+ g_string_append_printf (string, _("URL : %s\n"), url);
+ g_string_append_printf (string, _("License : %s\n"), license);
+ g_string_append_printf (string, _("Description:\n%s\n"), description);
/* this section done */
ret = zif_state_done (state_local, error);
@@ -6797,6 +6958,11 @@ main (int argc, char *argv[])
_("Display details about a package or group of packages"),
zif_cmd_get_details);
zif_cmd_add (priv->cmd_array,
@hughsie Owner
hughsie added a note

"pkg-detail" make sense, but the second things are designed to make zif more compatible with yum. I think we can just drop info-only.

@ekd123
ekd123 added a note

dropped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ "pkg-detail",
+ /* TRANSLATORS: command description */
+ _("Display only one detail about a package or group of packages from the remote repositories"),
+ zif_cmd_pkg_detail);
+ zif_cmd_add (priv->cmd_array,
"get-files",
/* TRANSLATORS: command description */
_("List the files in a package"),
Something went wrong with that request. Please try again.