user/dev discussion of public-inbox itself
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 09/10] index: support --verbose option
Date: Wed, 29 May 2019 08:28:59 +0000
Message-ID: <20190529082900.9312-10-e@80x24.org> (raw)
In-Reply-To: <20190529082900.9312-1-e@80x24.org>

It doesn't implement progress of batches, yet, but it wires
up the parsing of the command-line while preserving output
compatibility.

This output is NOT meant to be stable.
---
 lib/PublicInbox/Admin.pm  | 18 ++++++++++++++++++
 lib/PublicInbox/Xapcmd.pm | 14 +-------------
 script/public-inbox-index |  5 +++--
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm
index 34aa312..07d8b57 100644
--- a/lib/PublicInbox/Admin.pm
+++ b/lib/PublicInbox/Admin.pm
@@ -167,4 +167,22 @@ sub index_inbox {
 	}
 }
 
+sub progress_prepare ($) {
+	my ($opt) = @_;
+
+	# public-inbox-index defaults to quiet, -xcpdb and -compact do not
+	if (defined($opt->{quiet}) && $opt->{quiet} < 0) {
+		$opt->{quiet} = !$opt->{verbose};
+	}
+	if ($opt->{quiet}) {
+		open my $null, '>', '/dev/null' or
+			die "failed to open /dev/null: $!\n";
+		$opt->{1} = fileno($null); # suitable for spawn() redirect
+		$opt->{-dev_null} = $null;
+	} else {
+		$opt->{verbose} ||= 1;
+		$opt->{-progress} = sub { print STDERR @_ };
+	}
+}
+
 1;
diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index 999819c..7e3d47f 100644
--- a/lib/PublicInbox/Xapcmd.pm
+++ b/lib/PublicInbox/Xapcmd.pm
@@ -86,18 +86,6 @@ sub prepare_reindex ($$) {
 	}
 }
 
-sub progress_prepare ($) {
-	my ($opt) = @_;
-	if ($opt->{quiet}) {
-		open my $null, '>', '/dev/null' or
-			die "failed to open /dev/null: $!\n";
-		$opt->{1} = fileno($null);
-		$opt->{-dev_null} = $null;
-	} else {
-		$opt->{-progress} = sub { print STDERR @_ };
-	}
-}
-
 sub same_fs_or_die ($$) {
 	my ($x, $y) = @_;
 	return if ((stat($x))[0] == (stat($y))[0]); # 0 - st_dev
@@ -132,7 +120,7 @@ sub process_queue {
 sub run {
 	my ($ibx, $task, $opt) = @_; # task = 'cpdb' or 'compact'
 	my $cb = \&${\"PublicInbox::Xapcmd::$task"};
-	progress_prepare($opt ||= {});
+	PublicInbox::Admin::progress_prepare($opt ||= {});
 	my $dir = $ibx->{mainrepo} or die "no mainrepo in inbox\n";
 	runnable_or_die($XAPIAN_COMPACT) if $opt->{compact};
 	my $reindex; # v1:{ from => $x40 }, v2:{ from => [ $x40, $x40, .. ] } }
diff --git a/script/public-inbox-index b/script/public-inbox-index
index 40187b3..c0d637b 100755
--- a/script/public-inbox-index
+++ b/script/public-inbox-index
@@ -13,8 +13,8 @@ my $usage = "public-inbox-index INBOX_DIR";
 use PublicInbox::Admin;
 PublicInbox::Admin::require_or_die('-index');
 
-my $opt = {};
-GetOptions($opt, qw(reindex jobs|j=i prune indexlevel|L=s))
+my $opt = { quiet => -1 };
+GetOptions($opt, qw(verbose|v+ reindex jobs|j=i prune indexlevel|L=s))
 	or die "bad command-line args\n$usage";
 die "--jobs must be positive\n" if defined $opt->{jobs} && $opt->{jobs} <= 0;
 
@@ -35,4 +35,5 @@ foreach my $ibx (@ibxs) {
 }
 
 PublicInbox::Admin::require_or_die(keys %$mods);
+PublicInbox::Admin::progress_prepare($opt);
 PublicInbox::Admin::index_inbox($_, $opt) for @ibxs;
-- 
EW


  parent reply	other threads:[~2019-05-29  8:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-29  8:28 [PATCH 00/10] index: support progress output Eric Wong
2019-05-29  8:28 ` [PATCH 01/10] v2writable: introduce $sync state and put mm_tmp in it Eric Wong
2019-05-29  8:28 ` [PATCH 02/10] v2writable: sync: move delete markers into $sync state Eric Wong
2019-05-29  8:28 ` [PATCH 03/10] v2writable: move {reindex} field to " Eric Wong
2019-05-29  8:28 ` [PATCH 04/10] v2writable: move {regen} into " Eric Wong
2019-05-29  8:28 ` [PATCH 05/10] v2writable: move {ranges} " Eric Wong
2019-05-29  8:28 ` [PATCH 06/10] v2writable: localize unindex-range.$EPOCH to " Eric Wong
2019-05-29  8:28 ` [PATCH 07/10] v2writable: use prototypes for internal subs Eric Wong
2019-05-29  8:28 ` [PATCH 08/10] v2writable: move index_sync options to sync state Eric Wong
2019-05-29  8:28 ` Eric Wong [this message]
2019-05-29  8:29 ` [PATCH 10/10] v2writable: show progress updates for index_sync Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190529082900.9312-10-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ http://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git