summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2015-09-24 12:06:19 +0200
committerAlexander Larsson <alexl@redhat.com>2015-09-24 21:36:35 +0200
commit66e61764f3697d5df266644d263ee38ce2c87ae9 (patch)
treef367272019e4d44286d5605ca8b7d9d12dc0fd9b
parentc40f2ad74e039b3a49a3dd8dd58def5aa45e5ffb (diff)
downloadxdg-app-66e61764f3697d5df266644d263ee38ce2c87ae9.tar.gz
list-remotes: Add support for listing both user and system remotes
-rw-r--r--app/xdg-app-builtins-list-remotes.c110
-rw-r--r--doc/xdg-app-list-remotes.xml5
-rw-r--r--lib/xdg-app-utils.c22
-rw-r--r--lib/xdg-app-utils.h15
4 files changed, 100 insertions, 52 deletions
diff --git a/app/xdg-app-builtins-list-remotes.c b/app/xdg-app-builtins-list-remotes.c
index 0afec3d..6fb8df5 100644
--- a/app/xdg-app-builtins-list-remotes.c
+++ b/app/xdg-app-builtins-list-remotes.c
@@ -32,8 +32,12 @@
#include "xdg-app-utils.h"
static gboolean opt_show_details;
+static gboolean opt_user;
+static gboolean opt_system;
static GOptionEntry options[] = {
+ { "user", 0, 0, G_OPTION_ARG_NONE, &opt_user, "Show user installations", NULL },
+ { "system", 0, 0, G_OPTION_ARG_NONE, &opt_system, "Show system-wide installations", NULL },
{ "show-details", 'd', 0, G_OPTION_ARG_NONE, &opt_show_details, "Show remote details", NULL },
{ NULL }
};
@@ -42,70 +46,92 @@ gboolean
xdg_app_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
- g_autoptr(XdgAppDir) dir = NULL;
- g_auto(GStrv) remotes = NULL;
- guint ii, n_remotes = 0;
+ g_autoptr(XdgAppDir) user_dir = NULL;
+ g_autoptr(XdgAppDir) system_dir = NULL;
+ XdgAppDir *dirs[2] = { 0 };
+ guint ii, n_remotes = 0, n_dirs = 0, j;
+ XdgAppTablePrinter *printer;
context = g_option_context_new (" - List remote repositories");
- if (!xdg_app_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
+ if (!xdg_app_option_context_parse (context, options, &argc, &argv, XDG_APP_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error))
return FALSE;
- remotes = ostree_repo_remote_list (xdg_app_dir_get_repo (dir), &n_remotes);
+ if (!opt_user && !opt_system)
+ {
+ opt_user = TRUE;
+ opt_system = TRUE;
+ }
+
+ if (opt_user)
+ {
+ user_dir = xdg_app_dir_get_user ();
+ dirs[n_dirs++] = user_dir;
+ }
+
+ if (opt_system)
+ {
+ system_dir = xdg_app_dir_get_system ();
+ dirs[n_dirs++] = system_dir;
+ }
+
+ printer = xdg_app_table_printer_new ();
- if (opt_show_details)
+ for (j = 0; j < n_dirs; j++)
{
- XdgAppTablePrinter *printer = xdg_app_table_printer_new ();
- GKeyFile *config = ostree_repo_get_config (xdg_app_dir_get_repo (dir));;
- g_autoptr(GString) options = g_string_new ("");
+ XdgAppDir *dir = dirs[j];
+ GKeyFile *config;
+ g_auto(GStrv) remotes = NULL;
+
+ if (!xdg_app_dir_ensure_repo (dir, cancellable, NULL))
+ continue;
+
+ config = ostree_repo_get_config (xdg_app_dir_get_repo (dir));
+ remotes = ostree_repo_remote_list (xdg_app_dir_get_repo (dir), &n_remotes);
for (ii = 0; ii < n_remotes; ii++)
{
- char *remote_name = remotes[ii];
- g_autofree char *remote_url = NULL;
- g_autofree char *group = NULL;
- g_autofree char *title = NULL;
- gboolean gpg_verify = TRUE;
+ if (opt_show_details)
+ {
+ char *remote_name = remotes[ii];
+ g_autofree char *remote_url = NULL;
+ g_autofree char *group = NULL;
+ g_autofree char *title = NULL;
+ gboolean gpg_verify = TRUE;
- group = g_strdup_printf ("remote \"%s\"", remote_name);
+ group = g_strdup_printf ("remote \"%s\"", remote_name);
- xdg_app_table_printer_add_column (printer, remote_name);
+ xdg_app_table_printer_add_column (printer, remote_name);
- title = g_key_file_get_string (config, group, "xa.title", NULL);
- if (title)
- xdg_app_table_printer_add_column (printer, title);
- else
- xdg_app_table_printer_add_column (printer, "-");
+ title = g_key_file_get_string (config, group, "xa.title", NULL);
+ if (title)
+ xdg_app_table_printer_add_column (printer, title);
+ else
+ xdg_app_table_printer_add_column (printer, "-");
- ostree_repo_remote_get_url (xdg_app_dir_get_repo (dir), remote_name, &remote_url, NULL);
+ ostree_repo_remote_get_url (xdg_app_dir_get_repo (dir), remote_name, &remote_url, NULL);
- xdg_app_table_printer_add_column (printer, remote_url);
+ xdg_app_table_printer_add_column (printer, remote_url);
- ostree_repo_remote_get_gpg_verify (xdg_app_dir_get_repo (dir), remote_name,
- &gpg_verify, NULL);
- if (!gpg_verify)
- {
- if (options->len != 0)
- g_string_append_c (options, ',');
- g_string_append (options, "no-gpg-verify");
- }
+ xdg_app_table_printer_add_column (printer, ""); /* Options */
- if (options->len != 0)
- xdg_app_table_printer_add_column (printer, options->str);
+ ostree_repo_remote_get_gpg_verify (xdg_app_dir_get_repo (dir), remote_name,
+ &gpg_verify, NULL);
+ if (!gpg_verify)
+ xdg_app_table_printer_append_with_comma (printer, "no-gpg-verify");
- g_string_truncate (options, 0);
+ if (opt_user && opt_system)
+ xdg_app_table_printer_append_with_comma (printer, dir == user_dir ? "user" : "system");
+ }
+ else
+ xdg_app_table_printer_add_column (printer, remotes[ii]);
xdg_app_table_printer_finish_row (printer);
}
-
- xdg_app_table_printer_print (printer);
- xdg_app_table_printer_free (printer);
- }
- else
- {
- for (ii = 0; ii < n_remotes; ii++)
- g_print ("%s\n", remotes[ii]);
}
+ xdg_app_table_printer_print (printer);
+ xdg_app_table_printer_free (printer);
+
return TRUE;
}
diff --git a/doc/xdg-app-list-remotes.xml b/doc/xdg-app-list-remotes.xml
index b7039eb..f41db2f 100644
--- a/doc/xdg-app-list-remotes.xml
+++ b/doc/xdg-app-list-remotes.xml
@@ -42,8 +42,9 @@
Lists the known remote repositories.
</para>
<para>
- Unless overridden with the --user option, this command
- shows the system-wide configuration.
+ By default, both per-user and system-wide installations
+ are shown. Use the --user or --system options to change
+ this.
</para>
</refsect1>
diff --git a/lib/xdg-app-utils.c b/lib/xdg-app-utils.c
index 8e24578..79d31a0 100644
--- a/lib/xdg-app-utils.c
+++ b/lib/xdg-app-utils.c
@@ -775,6 +775,26 @@ xdg_app_table_printer_add_column (XdgAppTablePrinter *printer,
}
void
+xdg_app_table_printer_append_with_comma (XdgAppTablePrinter *printer,
+ const char *text)
+{
+ char *old, *new;
+
+ g_assert (printer->current->len > 0);
+
+ old = g_ptr_array_index (printer->current, printer->current->len - 1);
+
+ if (old[0] != 0)
+ new = g_strconcat (old, ",", text, NULL);
+ else
+ new = g_strdup (text);
+
+ g_ptr_array_index (printer->current, printer->current->len - 1) = new;
+ g_free (old);
+}
+
+
+void
xdg_app_table_printer_finish_row (XdgAppTablePrinter *printer)
{
printer->n_columns = MAX (printer->n_columns, printer->current->len);
@@ -808,7 +828,7 @@ xdg_app_table_printer_print (XdgAppTablePrinter *printer)
char **row = g_ptr_array_index (printer->rows,i);
for (j = 0; row[j] != NULL; j++)
- g_print ("%-*s%s", widths[j], row[j], j == printer->n_columns - 1 ? "" : "\t");
+ g_print ("%s%-*s", (j == 0) ? "" : "\t", widths[j], row[j]);
g_print ("\n");
}
}
diff --git a/lib/xdg-app-utils.h b/lib/xdg-app-utils.h
index 1f7cd2b..0b36cb1 100644
--- a/lib/xdg-app-utils.h
+++ b/lib/xdg-app-utils.h
@@ -132,13 +132,14 @@ gint xdg_app_mkstempat (int dir_fd,
typedef struct XdgAppTablePrinter XdgAppTablePrinter;
-XdgAppTablePrinter *xdg_app_table_printer_new (void);
-void xdg_app_table_printer_free (XdgAppTablePrinter *printer);
-void xdg_app_table_printer_add_column (XdgAppTablePrinter *printer,
- const char *text);
-void xdg_app_table_printer_finish_row (XdgAppTablePrinter *printer);
-void xdg_app_table_printer_print (XdgAppTablePrinter *printer);
-
+XdgAppTablePrinter *xdg_app_table_printer_new (void);
+void xdg_app_table_printer_free (XdgAppTablePrinter *printer);
+void xdg_app_table_printer_add_column (XdgAppTablePrinter *printer,
+ const char *text);
+void xdg_app_table_printer_append_with_comma (XdgAppTablePrinter *printer,
+ const char *text);
+void xdg_app_table_printer_finish_row (XdgAppTablePrinter *printer);
+void xdg_app_table_printer_print (XdgAppTablePrinter *printer);
#define AUTOLOCK(name) G_GNUC_UNUSED __attribute__((cleanup(xdg_app_auto_unlock_helper))) GMutex * G_PASTE(auto_unlock, __LINE__) = xdg_app_auto_lock_helper (&G_LOCK_NAME (name))