user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
9ac4870f8399f705cf3323abfcc5f4aac8c5f0ac blob 2954 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
 
# Copyright (C) 2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>

# "lei ls-search" to display results saved via "lei q --save"
package PublicInbox::LeiLsSearch;
use strict;
use v5.10.1;
use PublicInbox::LeiSavedSearch;
use parent qw(PublicInbox::IPC);

sub do_ls_search_long {
	my ($self, $pfx) = @_;
	# TODO: share common JSON output code with LeiOverview
	my $json = $self->{json}->new->utf8->canonical;
	my $lei = $self->{lei};
	$json->ascii(1) if $lei->{opt}->{ascii};
	my $fmt = $lei->{opt}->{'format'};
	$lei->{1}->autoflush(0);
	my $ORS = "\n";
	my $pretty = $lei->{opt}->{pretty};
	my $EOR;  # TODO: compact pretty like "lei q"
	if ($fmt =~ /\A(concat)?json\z/ && $pretty) {
		$EOR = ($1//'') eq 'concat' ? "\n}" : "\n},";
	}
	if ($fmt eq 'json') {
		$lei->out('[');
		$ORS = ",\n";
	}
	my @x = sort(grep(/\A\Q$pfx/, PublicInbox::LeiSavedSearch::list($lei)));
	while (my $x = shift @x) {
		$ORS = '' if !scalar(@x);
		my $lss = PublicInbox::LeiSavedSearch->up($lei, $x) or next;
		my $cfg = $lss->{-cfg};
		my $ent = {
			q => $cfg->get_all('lei.q'),
			output => $cfg->{'lei.q.output'},
		};
		for my $k ($lss->ARRAY_FIELDS) {
			my $ary = $cfg->get_all("lei.q.$k") // next;
			$ent->{$k} = $ary;
		}
		for my $k ($lss->BOOL_FIELDS) {
			my $val = $cfg->{"lei.q.$k"} // next;
			$ent->{$k} = $val;
		}
		if (defined $EOR) { # pretty, but compact
			$EOR = "\n}" if !scalar(@x);
			my $buf = "{\n";
			$buf .= join(",\n", map {;
				my $f = $_;
				if (my $v = $ent->{$f}) {
					$v = $json->encode([$v]);
					qq{  "$f": }.substr($v, 1, -1);
				} else {
					();
				}
			# key order by importance
			} (qw(output q), $lss->ARRAY_FIELDS,
				$lss->BOOL_FIELDS) );
			$lei->out($buf .= $EOR);
		} else {
			$lei->out($json->encode($ent), $ORS);
		}
	}
	if ($fmt eq 'json') {
		$lei->out("]\n");
	} elsif ($fmt eq 'concatjson') {
		$lei->out("\n");
	}
}

sub bg_worker ($$$) {
	my ($lei, $pfx, $json) = @_;
	my $self = bless { -wq_nr_workers => 1, json => $json }, __PACKAGE__;
	my ($op_c, $ops) = $lei->workers_start($self, 'ls-search', 1);
	$lei->{lsss} = $self;
	$self->wq_io_do('do_ls_search_long', [], $pfx);
	$self->wq_close(1);
	$op_c->op_wait_event($ops);
}

sub lei_ls_search {
	my ($lei, $pfx) = @_;
	my $fmt = $lei->{opt}->{'format'} // '';
	if ($lei->{opt}->{l}) {
		$lei->{opt}->{'format'} //= $fmt = 'json';
	}
	my $json;
	my $tty = -t $lei->{1};
	$lei->start_pager if $tty;
	if ($fmt =~ /\A(ldjson|ndjson|jsonl|(?:concat)?json)\z/) {
		$lei->{opt}->{pretty} //= $tty;
		$json = ref(PublicInbox::Config->json);
	} elsif ($fmt ne '') {
		return $lei->fail("unknown format: $fmt");
	}
	my $ORS = "\n";
	if ($lei->{opt}->{z}) {
		return $lei->fail('-z and --format do not mix') if $json;
		$ORS = "\0";
	}
	$pfx //= '';
	return bg_worker($lei, $pfx, $json) if $json;
	for (sort(grep(/\A\Q$pfx/, PublicInbox::LeiSavedSearch::list($lei)))) {
		$lei->out($_, $ORS);
	}
}

1;
debug log:

solving 9ac4870f ...
found 9ac4870f in public-inbox.git

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://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/ https://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://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.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 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