forked from Mirrors/flatpak-builder
Use the CLI progress for update --appstream too
parent
e41cb789fa
commit
23399ddc35
|
@ -70,6 +70,7 @@ static gboolean
|
|||
update_appstream (FlatpakDir *dir, const char *remote, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
gboolean changed;
|
||||
gboolean res;
|
||||
|
||||
if (opt_arch == NULL)
|
||||
opt_arch = (char *)flatpak_get_arch ();
|
||||
|
@ -86,21 +87,30 @@ update_appstream (FlatpakDir *dir, const char *remote, GCancellable *cancellable
|
|||
for (i = 0; remotes[i] != NULL; i++)
|
||||
{
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
FlatpakTerminalProgress terminal_progress = { 0 };
|
||||
|
||||
if (flatpak_dir_get_remote_disabled (dir, remotes[i]))
|
||||
continue;
|
||||
|
||||
g_print (_("Updating appstream for remote %s\n"), remotes[i]);
|
||||
g_autoptr(OstreeAsyncProgress) progress = flatpak_progress_new (flatpak_terminal_progress_cb, &terminal_progress);
|
||||
if (!flatpak_dir_update_appstream (dir, remotes[i], opt_arch, &changed,
|
||||
NULL, cancellable, &local_error))
|
||||
progress, cancellable, &local_error))
|
||||
g_printerr ("Error updating: %s\n", local_error->message);
|
||||
ostree_async_progress_finish (progress);
|
||||
flatpak_terminal_progress_end (&terminal_progress);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!flatpak_dir_update_appstream (dir, remote, opt_arch, &changed,
|
||||
NULL, cancellable, error))
|
||||
FlatpakTerminalProgress terminal_progress = { 0 };
|
||||
g_autoptr(OstreeAsyncProgress) progress = flatpak_progress_new (flatpak_terminal_progress_cb, &terminal_progress);
|
||||
res = flatpak_dir_update_appstream (dir, remote, opt_arch, &changed,
|
||||
progress, cancellable, error);
|
||||
ostree_async_progress_finish (progress);
|
||||
if (!res)
|
||||
return FALSE;
|
||||
flatpak_terminal_progress_end (&terminal_progress);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdio.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
|
@ -648,72 +647,6 @@ flatpak_transaction_update_metadata (FlatpakTransaction *self,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int inited;
|
||||
int n_columns;
|
||||
int last_width;
|
||||
} TerminalProgress;
|
||||
|
||||
#define BAR_LENGTH 20
|
||||
#define BAR_CHARS " -=#"
|
||||
|
||||
static void
|
||||
progress_cb (const char *status,
|
||||
guint progress,
|
||||
gboolean estimating,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_autoptr(GString) str = g_string_new ("");
|
||||
TerminalProgress *term = user_data;
|
||||
int i;
|
||||
int n_full, remainder, partial;
|
||||
int width, padded_width;
|
||||
|
||||
if (!term->inited)
|
||||
{
|
||||
struct winsize w;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||
term->n_columns = w.ws_col;
|
||||
term->last_width = 0;
|
||||
term->inited = 1;
|
||||
}
|
||||
|
||||
g_string_append (str, "[");
|
||||
|
||||
n_full = (BAR_LENGTH * progress) / 100;
|
||||
remainder = progress - (n_full * 100 / BAR_LENGTH);
|
||||
partial = (remainder * strlen(BAR_CHARS) * BAR_LENGTH) / 100;
|
||||
|
||||
for (i = 0; i < n_full; i++)
|
||||
g_string_append_c (str, BAR_CHARS[strlen(BAR_CHARS)-1]);
|
||||
|
||||
if (i < BAR_LENGTH)
|
||||
{
|
||||
g_string_append_c (str, BAR_CHARS[partial]);
|
||||
i++;
|
||||
}
|
||||
|
||||
for (; i < BAR_LENGTH; i++)
|
||||
g_string_append (str, " ");
|
||||
|
||||
g_string_append (str, "] ");
|
||||
g_string_append (str, status);
|
||||
|
||||
g_print ("\r");
|
||||
width = MIN (strlen (str->str), term->n_columns);
|
||||
padded_width = MAX (term->last_width, width);
|
||||
term->last_width = width;
|
||||
g_print ("%-*.*s", padded_width, padded_width, str->str);
|
||||
}
|
||||
|
||||
static void
|
||||
progress_end (TerminalProgress *term)
|
||||
{
|
||||
if (term->inited)
|
||||
g_print("\n");
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
flatpak_transaction_run (FlatpakTransaction *self,
|
||||
gboolean stop_on_first_error,
|
||||
|
@ -733,7 +666,7 @@ flatpak_transaction_run (FlatpakTransaction *self,
|
|||
const char *pref;
|
||||
const char *opname;
|
||||
FlatpakTransactionOpKind kind;
|
||||
TerminalProgress terminal_progress = { 0 };
|
||||
FlatpakTerminalProgress terminal_progress = { 0 };
|
||||
|
||||
kind = op->kind;
|
||||
if (kind == FLATPAK_TRANSACTION_OP_KIND_INSTALL_OR_UPDATE)
|
||||
|
@ -766,7 +699,7 @@ flatpak_transaction_run (FlatpakTransaction *self,
|
|||
|
||||
if (kind == FLATPAK_TRANSACTION_OP_KIND_INSTALL)
|
||||
{
|
||||
g_autoptr(OstreeAsyncProgress) progress = flatpak_progress_new (progress_cb, &terminal_progress);
|
||||
g_autoptr(OstreeAsyncProgress) progress = flatpak_progress_new (flatpak_terminal_progress_cb, &terminal_progress);
|
||||
opname = _("install");
|
||||
g_print (_("Installing: %s from %s\n"), pref, op->remote);
|
||||
res = flatpak_dir_install (self->dir,
|
||||
|
@ -778,7 +711,7 @@ flatpak_transaction_run (FlatpakTransaction *self,
|
|||
progress,
|
||||
cancellable, &local_error);
|
||||
ostree_async_progress_finish (progress);
|
||||
progress_end (&terminal_progress);
|
||||
flatpak_terminal_progress_end (&terminal_progress);
|
||||
}
|
||||
else if (kind == FLATPAK_TRANSACTION_OP_KIND_UPDATE)
|
||||
{
|
||||
|
@ -790,7 +723,7 @@ flatpak_transaction_run (FlatpakTransaction *self,
|
|||
if (target_commit != NULL)
|
||||
{
|
||||
g_print (_("Updating: %s from %s\n"), pref, op->remote);
|
||||
g_autoptr(OstreeAsyncProgress) progress = flatpak_progress_new (progress_cb, &terminal_progress);
|
||||
g_autoptr(OstreeAsyncProgress) progress = flatpak_progress_new (flatpak_terminal_progress_cb, &terminal_progress);
|
||||
res = flatpak_dir_update (self->dir,
|
||||
self->no_pull,
|
||||
self->no_deploy,
|
||||
|
@ -801,7 +734,7 @@ flatpak_transaction_run (FlatpakTransaction *self,
|
|||
progress,
|
||||
cancellable, &local_error);
|
||||
ostree_async_progress_finish (progress);
|
||||
progress_end (&terminal_progress);
|
||||
flatpak_terminal_progress_end (&terminal_progress);
|
||||
if (res)
|
||||
{
|
||||
g_autoptr(GVariant) deploy_data = NULL;
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <sys/file.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include "libglnx/libglnx.h"
|
||||
|
@ -5809,6 +5810,65 @@ flatpak_get_current_locale_subpaths (void)
|
|||
return (char **)g_ptr_array_free (subpaths, FALSE);
|
||||
}
|
||||
|
||||
#define BAR_LENGTH 20
|
||||
#define BAR_CHARS " -=#"
|
||||
|
||||
void
|
||||
flatpak_terminal_progress_cb (const char *status,
|
||||
guint progress,
|
||||
gboolean estimating,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_autoptr(GString) str = g_string_new ("");
|
||||
FlatpakTerminalProgress *term = user_data;
|
||||
int i;
|
||||
int n_full, remainder, partial;
|
||||
int width, padded_width;
|
||||
|
||||
if (!term->inited)
|
||||
{
|
||||
struct winsize w;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||
term->n_columns = w.ws_col;
|
||||
term->last_width = 0;
|
||||
term->inited = 1;
|
||||
}
|
||||
|
||||
g_string_append (str, "[");
|
||||
|
||||
n_full = (BAR_LENGTH * progress) / 100;
|
||||
remainder = progress - (n_full * 100 / BAR_LENGTH);
|
||||
partial = (remainder * strlen(BAR_CHARS) * BAR_LENGTH) / 100;
|
||||
|
||||
for (i = 0; i < n_full; i++)
|
||||
g_string_append_c (str, BAR_CHARS[strlen(BAR_CHARS)-1]);
|
||||
|
||||
if (i < BAR_LENGTH)
|
||||
{
|
||||
g_string_append_c (str, BAR_CHARS[partial]);
|
||||
i++;
|
||||
}
|
||||
|
||||
for (; i < BAR_LENGTH; i++)
|
||||
g_string_append (str, " ");
|
||||
|
||||
g_string_append (str, "] ");
|
||||
g_string_append (str, status);
|
||||
|
||||
g_print ("\r");
|
||||
width = MIN (strlen (str->str), term->n_columns);
|
||||
padded_width = MAX (term->last_width, width);
|
||||
term->last_width = width;
|
||||
g_print ("%-*.*s", padded_width, padded_width, str->str);
|
||||
}
|
||||
|
||||
void
|
||||
flatpak_terminal_progress_end (FlatpakTerminalProgress *term)
|
||||
{
|
||||
if (term->inited)
|
||||
g_print("\n");
|
||||
}
|
||||
|
||||
static inline guint
|
||||
get_write_progress (guint outstanding_writes)
|
||||
{
|
||||
|
|
|
@ -666,6 +666,18 @@ void flatpak_complete_options (FlatpakCompletion *completion,
|
|||
GOptionEntry *entries);
|
||||
void flatpak_completion_free (FlatpakCompletion *completion);
|
||||
|
||||
typedef struct {
|
||||
int inited;
|
||||
int n_columns;
|
||||
int last_width;
|
||||
} FlatpakTerminalProgress;
|
||||
|
||||
void flatpak_terminal_progress_cb (const char *status,
|
||||
guint progress,
|
||||
gboolean estimating,
|
||||
gpointer user_data);
|
||||
void flatpak_terminal_progress_end (FlatpakTerminalProgress *term);
|
||||
|
||||
typedef void (*FlatpakProgressCallback)(const char *status,
|
||||
guint progress,
|
||||
gboolean estimating,
|
||||
|
|
Loading…
Reference in New Issue