dovecot-2.0: doveadm: Output is now written via "formatter" inte...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jun 11 22:35:15 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/c4fdccf298bf
changeset: 11521:c4fdccf298bf
user: Timo Sirainen <tss at iki.fi>
date: Fri Jun 11 20:34:44 2010 +0100
description:
doveadm: Output is now written via "formatter" interface. The default can be changed with -f parameter.
Currently implemented 3 formatters: flow, tab and table.
diffstat:
src/doveadm/Makefile.am | 6 +
src/doveadm/doveadm-mail-mailbox-status.c | 58 +++++---
src/doveadm/doveadm-mail-mailbox.c | 8 +-
src/doveadm/doveadm-mail-search.c | 15 ++-
src/doveadm/doveadm-mail.c | 31 +----
src/doveadm/doveadm-mail.h | 6 -
src/doveadm/doveadm-print-flow.c | 75 ++++++++++++
src/doveadm/doveadm-print-private.h | 26 ++++
src/doveadm/doveadm-print-tab.c | 56 +++++++++
src/doveadm/doveadm-print-table.c | 193 ++++++++++++++++++++++++++++++++
src/doveadm/doveadm-print.c | 134 ++++++++++++++++++++++
src/doveadm/doveadm-print.h | 23 +++
src/doveadm/doveadm-who.c | 79 ++++++++-----
src/doveadm/doveadm.c | 9 +-
src/plugins/quota/doveadm-quota.c | 58 ++++++---
15 files changed, 665 insertions(+), 112 deletions(-)
diffs (truncated from 1108 to 300 lines):
diff -r f37d19f1c0a3 -r c4fdccf298bf src/doveadm/Makefile.am
--- a/src/doveadm/Makefile.am Fri Jun 11 16:14:47 2010 +0100
+++ b/src/doveadm/Makefile.am Fri Jun 11 20:34:44 2010 +0100
@@ -64,6 +64,10 @@
doveadm-mail-list-iter.c \
doveadm-mail-search.c \
doveadm-penalty.c \
+ doveadm-print.c \
+ doveadm-print-flow.c \
+ doveadm-print-tab.c \
+ doveadm-print-table.c \
doveadm-pw.c \
doveadm-settings.c \
doveadm-who.c
@@ -74,5 +78,7 @@
doveadm-mail.h \
doveadm-mail-iter.h \
doveadm-mail-list-iter.h \
+ doveadm-print.h \
+ doveadm-print-private.h \
doveadm-settings.h \
doveadm-who.h
diff -r f37d19f1c0a3 -r c4fdccf298bf src/doveadm/doveadm-mail-mailbox-status.c
--- a/src/doveadm/doveadm-mail-mailbox-status.c Fri Jun 11 16:14:47 2010 +0100
+++ b/src/doveadm/doveadm-mail-mailbox-status.c Fri Jun 11 20:34:44 2010 +0100
@@ -4,6 +4,7 @@
#include "str.h"
#include "mail-namespace.h"
#include "mail-storage.h"
+#include "doveadm-print.h"
#include "doveadm-mail.h"
#include "doveadm-mail-list-iter.h"
@@ -58,36 +59,25 @@
const struct mailbox_status *status,
uint8_t mailbox_guid[MAIL_GUID_128_SIZE])
{
- string_t *str = t_str_new(128);
-
if (box != NULL)
- str_printfa(str, "%s: ", mailbox_get_vname(box));
+ doveadm_print(mailbox_get_vname(box));
if ((ctx->items & STATUS_MESSAGES) != 0)
- str_printfa(str, "messages=%u ", status->messages);
+ doveadm_print_num(status->messages);
if ((ctx->items & STATUS_RECENT) != 0)
- str_printfa(str, "recent=%u ", status->recent);
+ doveadm_print_num(status->recent);
if ((ctx->items & STATUS_UIDNEXT) != 0)
- str_printfa(str, "uidnext=%u ", status->uidnext);
+ doveadm_print_num(status->uidnext);
if ((ctx->items & STATUS_UIDVALIDITY) != 0)
- str_printfa(str, "uidvalidity=%u ", status->uidvalidity);
+ doveadm_print_num(status->uidvalidity);
if ((ctx->items & STATUS_UNSEEN) != 0)
- str_printfa(str, "unseen=%u ", status->unseen);
- if ((ctx->items & STATUS_HIGHESTMODSEQ) != 0) {
- str_printfa(str, "highestmodseq=%llu ",
- (unsigned long long)status->highest_modseq);
- }
- if ((ctx->items & STATUS_VIRTUAL_SIZE) != 0) {
- str_printfa(str, "vsize=%llu ",
- (unsigned long long)status->virtual_size);
- }
- if (ctx->guid) {
- str_printfa(str, "guid=%s ",
- mail_guid_128_to_string(mailbox_guid));
- }
-
- str_truncate(str, str_len(str)-1);
- dm_printf(&ctx->ctx, "%s\n", str_c(str));
+ doveadm_print_num(status->unseen);
+ if ((ctx->items & STATUS_HIGHESTMODSEQ) != 0)
+ doveadm_print_num(status->highest_modseq);
+ if ((ctx->items & STATUS_VIRTUAL_SIZE) != 0)
+ doveadm_print_num(status->virtual_size);
+ if (ctx->guid)
+ doveadm_print(mail_guid_128_to_string(mailbox_guid));
}
static void
@@ -164,6 +154,27 @@
status_parse_fields(ctx, t_strsplit_spaces(fields, " "));
ctx->search_args = doveadm_mail_mailbox_search_args_build(args);
+
+ if (!ctx->total_sum) {
+ doveadm_print_header("mailbox", "mailbox",
+ DOVEADM_PRINT_HEADER_FLAG_HIDE_TITLE);
+ }
+ if ((ctx->items & STATUS_MESSAGES) != 0)
+ doveadm_print_header_simple("messages");
+ if ((ctx->items & STATUS_RECENT) != 0)
+ doveadm_print_header_simple("recent");
+ if ((ctx->items & STATUS_UIDNEXT) != 0)
+ doveadm_print_header_simple("uidnext");
+ if ((ctx->items & STATUS_UIDVALIDITY) != 0)
+ doveadm_print_header_simple("uidvalidity");
+ if ((ctx->items & STATUS_UNSEEN) != 0)
+ doveadm_print_header_simple("unseen");
+ if ((ctx->items & STATUS_HIGHESTMODSEQ) != 0)
+ doveadm_print_header_simple("highestmodseq");
+ if ((ctx->items & STATUS_VIRTUAL_SIZE) != 0)
+ doveadm_print_header_simple("vsize");
+ if (ctx->guid)
+ doveadm_print_header_simple("guid");
}
static bool
@@ -190,6 +201,7 @@
ctx->ctx.v.parse_arg = cmd_mailbox_status_parse_arg;
ctx->ctx.v.init = cmd_mailbox_status_init;
ctx->ctx.v.run = cmd_mailbox_status_run;
+ doveadm_print_init(DOVEADM_PRINT_TYPE_FLOW);
return &ctx->ctx;
}
diff -r f37d19f1c0a3 -r c4fdccf298bf src/doveadm/doveadm-mail-mailbox.c
--- a/src/doveadm/doveadm-mail-mailbox.c Fri Jun 11 16:14:47 2010 +0100
+++ b/src/doveadm/doveadm-mail-mailbox.c Fri Jun 11 20:34:44 2010 +0100
@@ -7,6 +7,7 @@
#include "mail-namespace.h"
#include "mail-storage.h"
#include "mail-search-build.h"
+#include "doveadm-print.h"
#include "doveadm-mail-list-iter.h"
#include "doveadm-mail.h"
@@ -123,9 +124,9 @@
while ((info = doveadm_mail_list_iter_next(iter)) != NULL) {
str_truncate(str, 0);
if (ctx->mutf7 || imap_utf7_to_utf8(info->name, str) < 0)
- dm_printf(_ctx, "%s\n", info->name);
+ doveadm_print(info->name);
else
- dm_printf(_ctx, "%s\n", str_c(str));
+ doveadm_print(str_c(str));
}
doveadm_mail_list_iter_deinit(&iter);
}
@@ -158,6 +159,8 @@
{
struct list_cmd_context *ctx = (struct list_cmd_context *)_ctx;
+ doveadm_print_header("mailbox", "mailbox",
+ DOVEADM_PRINT_HEADER_FLAG_HIDE_TITLE);
ctx->search_args = doveadm_mail_mailbox_search_args_build(args);
}
@@ -170,6 +173,7 @@
ctx->ctx.ctx.v.run = cmd_mailbox_list_run;
ctx->ctx.ctx.v.parse_arg = cmd_mailbox_list_parse_arg;
ctx->ctx.ctx.getopt_args = "78s";
+ doveadm_print_init(DOVEADM_PRINT_TYPE_FLOW);
return &ctx->ctx.ctx;
}
diff -r f37d19f1c0a3 -r c4fdccf298bf src/doveadm/doveadm-mail-search.c
--- a/src/doveadm/doveadm-mail-search.c Fri Jun 11 16:14:47 2010 +0100
+++ b/src/doveadm/doveadm-mail-search.c Fri Jun 11 20:34:44 2010 +0100
@@ -2,6 +2,7 @@
#include "lib.h"
#include "mail-storage.h"
+#include "doveadm-print.h"
#include "doveadm-mail-list-iter.h"
#include "doveadm-mail-iter.h"
#include "doveadm-mail.h"
@@ -27,8 +28,12 @@
ret = -1;
else {
guid_str = mail_guid_128_to_string(guid);
- while (doveadm_mail_iter_next(iter, mail))
- dm_printf(ctx, "%s %u\n", guid_str, mail->uid);
+ while (doveadm_mail_iter_next(iter, mail)) {
+ doveadm_print(guid_str);
+ T_BEGIN {
+ doveadm_print(dec2str(mail->uid));
+ } T_END;
+ }
}
mail_free(&mail);
if (doveadm_mail_iter_deinit(&iter) < 0)
@@ -60,6 +65,11 @@
if (args[0] == NULL)
doveadm_mail_help_name("search");
+ doveadm_print_header("mailbox-guid", "mailbox-guid",
+ DOVEADM_PRINT_HEADER_FLAG_HIDE_TITLE);
+ doveadm_print_header("uid", "uid",
+ DOVEADM_PRINT_HEADER_FLAG_HIDE_TITLE);
+
ctx->search_args = doveadm_mail_build_search_args(args);
}
@@ -70,6 +80,7 @@
ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
ctx->v.init = cmd_search_init;
ctx->v.run = cmd_search_run;
+ doveadm_print_init(DOVEADM_PRINT_TYPE_FLOW);
return ctx;
}
diff -r f37d19f1c0a3 -r c4fdccf298bf src/doveadm/doveadm-mail.c
--- a/src/doveadm/doveadm-mail.c Fri Jun 11 16:14:47 2010 +0100
+++ b/src/doveadm/doveadm-mail.c Fri Jun 11 20:34:44 2010 +0100
@@ -18,6 +18,7 @@
#include "mail-search-parser.h"
#include "doveadm.h"
#include "doveadm-settings.h"
+#include "doveadm-print.h"
#include "doveadm-mail.h"
#include <stdio.h>
@@ -41,7 +42,6 @@
pool = pool_alloconly_create("doveadm mail cmd", 1024);
ctx = p_malloc(pool, size);
ctx->pool = pool;
- ctx->dm_printf_last_lf = TRUE;
return ctx;
}
@@ -276,7 +276,7 @@
n = user_count / 10000;
for (interval = 10; n > 0 && interval < 1000; interval *= 10)
n /= 10;
-
+
user_idx = 0;
while ((ret = ctx->v.get_next_user(ctx, &user)) > 0) {
if (wildcard_user != NULL) {
@@ -284,6 +284,7 @@
continue;
}
input.username = user;
+ doveadm_print_sticky("username", user);
T_BEGIN {
ret = doveadm_mail_next_user(ctx, &input, &error);
if (ret < 0)
@@ -360,6 +361,9 @@
switch (c) {
case 'A':
ctx->iterate_all_users = TRUE;
+ doveadm_print_header("username", "Username",
+ DOVEADM_PRINT_HEADER_FLAG_STICKY |
+ DOVEADM_PRINT_HEADER_FLAG_HIDE_TITLE);
break;
case 'u':
service_flags |=
@@ -396,29 +400,6 @@
exit(FATAL_DEFAULT);
}
-void dm_printf(struct doveadm_mail_cmd_context *ctx, const char *format, ...)
-{
- va_list args;
-
- va_start(args, format);
- if (!ctx->iterate_all_users)
- vprintf(format, args);
- else T_BEGIN {
- const char *str = t_strdup_vprintf(format, args);
- bool prev_lf = ctx->dm_printf_last_lf;
-
- for (; *str != '\0'; str++) {
- if (prev_lf)
- printf("%s: ", ctx->cur_mail_user->username);
- putchar(*str);
- prev_lf = *str == '\n';
- }
- ctx->dm_printf_last_lf = prev_lf;
-
- } T_END;
- va_end(args);
-}
-
static bool
doveadm_mail_try_run_multi_word(const struct doveadm_mail_cmd *cmd,
const char *cmdname, int argc, char *argv[])
diff -r f37d19f1c0a3 -r c4fdccf298bf src/doveadm/doveadm-mail.h
--- a/src/doveadm/doveadm-mail.h Fri Jun 11 16:14:47 2010 +0100
+++ b/src/doveadm/doveadm-mail.h Fri Jun 11 20:34:44 2010 +0100
@@ -45,7 +45,6 @@
ARRAY_DEFINE(module_contexts, union doveadm_mail_cmd_module_context *);
unsigned int iterate_all_users:1;
- unsigned int dm_printf_last_lf:1;
unsigned int failed:1;
};
@@ -85,11 +84,6 @@
#define doveadm_mail_cmd_alloc(type) \
(type *)doveadm_mail_cmd_alloc_size(sizeof(type))
-/* same as printf(), but when running with -A parameter,
- prefix each line with username. */
-void dm_printf(struct doveadm_mail_cmd_context *ctx, const char *format, ...)
- ATTR_FORMAT(2, 3);
-
More information about the dovecot-cvs
mailing list