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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#!/usr/bin/perl
# maintainer-indices generates Maintainer.idx and Source.idx files
# and is released under the terms of the GNU GPL version 3, or any
# later version, at your option. See the file README and COPYING for
# more information.
# Copyright 2018 by Don Armstrong <don@donarmstrong.com>.
use warnings;
use strict;
use Getopt::Long;
use Pod::Usage;
=head1 NAME
maintainer-indices - generates Maintainer.idx and Source.idx files
=head1 SYNOPSIS
maintainer-indices [options]
Options:
--debug, -d debugging level (Default 0)
--help, -h display this help
--man, -m display manual
=head1 OPTIONS
=over
=item B<--debug, -d>
Debug verbosity. (Default 0)
=item B<--help, -h>
Display brief usage information.
=item B<--man, -m>
Display this manual.
=back
=head1 EXAMPLES
C<maintainer-indices>
=cut
use vars qw($DEBUG);
use File::Copy;
use MLDBM qw(DB_File Storable);
$MLDBM::DumpMeth='portable';
use Fcntl;
use Debbugs::Config qw(:config);
use Debbugs::Common qw(lockpid getparsedaddrs);
my %options = (debug => 0,
help => 0,
man => 0,
);
GetOptions(\%options,
'debug|d+','help|h|?','man|m');
pod2usage() if $options{help};
pod2usage({verbose=>2}) if $options{man};
$DEBUG = $options{debug};
my @USAGE_ERRORS;
pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
my $indexes =
{source => {index => $config{spool_dir}.'/'.'source_maintainers.idx',
index_reverse => $config{spool_dir}.'/'.'source_maintainers_reverse.idx',
files =>
[@config{('source_maintainer_file',
'source_maintainer_file_override',
'pseudo_maint_file')}],
},
binary => {index => $config{spool_dir}.'/'.'binary_maintainers.idx',
index_reverse => $config{spool_dir}.'/'.'binary_maintainers_reverse.idx',
files =>
[@config{('maintainer_file',
'maintainer_file_override',
'pseudo_maint_file')}],
},
};
if (not lockpid($config{spool_dir}.'/lock/maintainer-indices')) {
print STDERR "Another maintainer-indices is running; stopping\n";
exit 1;
}
# tie new maint/source maint indexes for forward and reverse
for my $idx (keys %{$indexes}) {
for my $fr ('','_reverse') {
tie %{$indexes->{$idx}{"tie$fr"}},
MLDBM => $indexes->{$idx}{"index$fr"}.'-new',
O_CREAT|O_TRUNC|O_RDWR, 0644 or
die qq(Unable to tie $indexes->{$idx}{"index$fr"}-new: $!);
}
}
for my $idx (keys %{$indexes}) {
for my $fn (@{$indexes->{$idx}{files}}) {
next unless defined $fn and length $fn;
if (not -e $fn) {
warn "Missing $idx maintainer file '$fn'";
next;
}
add_to_index($fn,$indexes->{$idx}{tie},
$indexes->{$idx}{tie_reverse}
);
}
}
for my $idx (keys %{$indexes}) {
for my $fr ('','_reverse') {
move($indexes->{$idx}{"index$fr"}.'-new',
$indexes->{$idx}{"index$fr"}
);
}
}
sub add_to_index {
my ($fn,$forward,$reverse,$type) = @_;
$type //= 'address';
my $fh;
open($fh,'<',$fn) or
die "Unable to open $fn for reading: $!";
binmode($fh,':encoding(UTF-8)') or
die "Unable to set UTF-8 encoding: $!";
while (<$fh>) {
chomp;
next unless m/^(\S+)\s+(\S.*\S)\s*$/;
my ($key,$value) = ($1,$2);
$key = lc($key);
$forward->{$key} = $value;
my @values = $value;
if ($type eq 'address') {
@values = map {lc($_->address)}
getparsedaddrs($value);
}
for my $m (@values) {
# this is to work around a bug in tied hashes.
my $r = $reverse->{$m} // [];
push @{$r},$key;
$reverse->{$m} = $r;
}
}
close($fh) or
die "Unable to close $fn filehandle: $!";
}
__END__
# Local Variables:
# indent-tabs-mode: nil
# cperl-indent-level: 4
# End:
|