Add a repo-contents command

This can show available runtimes and applications.
tingping/wmclass
Matthias Clasen 2015-01-15 23:25:03 -05:00
parent 24901067fa
commit 4cec1e3934
4 changed files with 98 additions and 0 deletions

View File

@ -30,6 +30,7 @@ xdg_app_SOURCES = \
xdg-app-builtins-add-repo.c \
xdg-app-builtins-delete-repo.c \
xdg-app-builtins-list-repos.c \
xdg-app-builtins-repo-contents.c \
xdg-app-builtins-install.c \
xdg-app-builtins-update.c \
xdg-app-builtins-list.c \

View File

@ -0,0 +1,95 @@
#include "config.h"
#include <locale.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "libgsystem.h"
#include "xdg-app-builtins.h"
#include "xdg-app-utils.h"
static gboolean opt_show_details;
static gboolean opt_only_runtimes;
static gboolean opt_only_apps;
static GOptionEntry options[] = {
{ "show-details", 0, 0, G_OPTION_ARG_NONE, &opt_show_details, "Show arches and branches", NULL },
{ "only-runtimes", 0, 0, G_OPTION_ARG_NONE, &opt_only_runtimes, "Show only runtimes", NULL },
{ "only-apps", 0, 0, G_OPTION_ARG_NONE, &opt_only_apps, "Show only apps", NULL },
{ NULL }
};
gboolean
xdg_app_builtin_repo_contents (int argc, char **argv, GCancellable *cancellable, GError **error)
{
gboolean ret = FALSE;
GOptionContext *context;
gs_unref_object XdgAppDir *dir = NULL;
gs_unref_object OstreeRepo *repo = NULL;
gs_unref_hashtable GHashTable *refs = NULL;
GHashTableIter iter;
gpointer key;
gs_unref_hashtable GHashTable *seen = NULL;
context = g_option_context_new (" - Show available runtimes and applications");
if (!xdg_app_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
goto out;
repo = xdg_app_dir_get_repo (dir);
if (!ostree_repo_list_refs (repo, NULL, &refs, cancellable, error))
goto out;
seen = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
g_hash_table_iter_init (&iter, refs);
while (g_hash_table_iter_next (&iter, &key, NULL))
{
const char *refspec = key;
gs_free char *remote = NULL;
gs_free char *ref = NULL;
char *name = NULL;
char *p;
if (!ostree_parse_refspec (refspec, &remote, &ref, error))
goto out;
if (g_str_has_prefix (ref, "runtime/") && !opt_only_apps)
{
name = g_strdup (ref + strlen ("runtime/"));
if (!opt_show_details)
{
p = strchr (name, '/');
if (p)
*p = 0;
}
}
if (g_str_has_prefix (ref, "app/") && !opt_only_runtimes)
{
name = g_strdup (ref + strlen ("app/"));
if (!opt_show_details)
{
p = strchr (name, '/');
if (p)
*p = 0;
}
}
if (name && !g_hash_table_contains (seen, name))
{
g_hash_table_add (seen, name);
g_print ("%s\n", name);
}
}
ret = TRUE;
out:
if (context)
g_option_context_free (context);
return ret;
}

View File

@ -31,6 +31,7 @@ void usage_error (GOptionContext *context,
BUILTINPROTO(add_repo);
BUILTINPROTO(delete_repo);
BUILTINPROTO(list_repos);
BUILTINPROTO(repo_contents);
BUILTINPROTO(install_runtime);
BUILTINPROTO(update_runtime);
BUILTINPROTO(list_runtimes);

View File

@ -22,6 +22,7 @@ static XdgAppCommand commands[] = {
{ "add-repo", xdg_app_builtin_add_repo },
{ "delete-repo", xdg_app_builtin_delete_repo },
{ "list-repos", xdg_app_builtin_list_repos },
{ "repo-contents", xdg_app_builtin_repo_contents },
{ "install-runtime", xdg_app_builtin_install_runtime },
{ "update-runtime", xdg_app_builtin_update_runtime },
{ "list-runtimes", xdg_app_builtin_list_runtimes },