Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
Add a command called 'pkg-detail' which displays only one detail abou…
Browse files Browse the repository at this point in the history
…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'
  • Loading branch information
ekd123 committed Apr 23, 2012
1 parent 2bd6535 commit 45d3a6e
Showing 1 changed file with 140 additions and 9 deletions.
149 changes: 140 additions & 9 deletions tools/zif-main.c
Expand Up @@ -1063,6 +1063,132 @@ zif_cmd_get_depends (ZifCmdPrivate *priv, gchar **values, GError **error)
return ret;
}

/**
* 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,
error,
20,
20,
20,
20,
20,
-1);

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 */
if (values == NULL || values[0] == NULL) {
/* TRANSLATORS: error message: A user did not specify
* a required value */
g_set_error_literal (error, 1, 0,
_("Specify a package name"));
ret = FALSE;
goto out;
}

if (values[1] == NULL) {
g_set_error_literal (error, 1, 0,
_("Which information would you like?"));
ret = FALSE;
goto out;
}
state_local = zif_state_get_child (priv->state);
tmp_strv[0] = values[0];
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 ("");
package = g_ptr_array_index (array, 0);
state_local = zif_state_get_child (priv->state);
if (!g_strcmp0 (values[1], "name"))
g_string_append_printf (string, "%s\n", zif_package_get_name (package));
else if (!g_strcmp0 (values[1], "version"))
g_string_append_printf (string, "%s\n", zif_package_get_version (package));
else if (!g_strcmp0 (values[1], "arch"))
g_string_append_printf (string, "%s\n", zif_package_get_arch (package));
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!" */
/* ret = zif_state_done (state_local, error); */
/* 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:
**/
Expand Down Expand Up @@ -1171,15 +1297,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);
Expand Down Expand Up @@ -6796,6 +6922,11 @@ main (int argc, char *argv[])
/* TRANSLATORS: command description */
_("Display details about a package or group of packages"),
zif_cmd_get_details);
zif_cmd_add (priv->cmd_array,
"pkg-detail,info-only",
/* 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 */
Expand Down

0 comments on commit 45d3a6e

Please sign in to comment.