From: Don Armstrong Date: Tue, 23 May 2006 06:45:23 +0000 (-0700) Subject: * Add a bin directory X-Git-Tag: release/2.6.0~585^2^2~103^2~21 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=229aad8f6f9ce2cbda227aa0d19861e0426b5494;p=debbugs.git * Add a bin directory * Place within it the test_bts commands and the add_bug_to_estraier command which enable the bts to be tested and bugs to be added to estraier via a cron job. --- diff --git a/bin/add_bug_to_estraier b/bin/add_bug_to_estraier new file mode 100755 index 00000000..e27f8782 --- /dev/null +++ b/bin/add_bug_to_estraier @@ -0,0 +1,202 @@ +#!/usr/bin/perl +# add_bug_to_estraier adds a log for a bug to the estaier db, and is +# released under the terms of the GPL version 2, or any later version, +# at your option. See the file README and COPYING for more +# information. +# Copyright 2006 by Don Armstrong . + + + +use warnings; +use strict; + + +use Getopt::Long; +use Pod::Usage; + +=head1 NAME + +add_bug_to_estraier + +=head1 SYNOPSIS + +add_bug_to_estraier [options] < list_of_bugs_to_add + + Options: + --debug, -d debugging level (Default 0) + --help, -h display this help + --man, -m display manual + +=head1 OPTIONS + +=over + +=item B<--url, -u> + +Url to the estraier node + +=item B<--user,-U> + +User to log onto the estraier node + +=item B<--pass,-P> + +Password to log onto the estraier node + +=item B<--spool,-s> + +Spool location; if not set defaults to /etc/debbugs/config + +=item B<--conf,-C> + +Configuration file; a set of key = value pairs separated by newlines; +the long name of any option is the name that the configuration file +takes + +=item B<--cron> + +Descend through the spool and add all of the bugs to estraier + +=item B<--timestamp> + +Use the timestamp file to only add new bugs; will lock the timestamp +file to avoid racing with other invocations + +=item B<--debug, -d> + +Debug verbosity. (Default 0) + +=item B<--help, -h> + +Display brief useage information. + +=item B<--man, -m> + +Display this manual. + +=back + + +=head1 EXAMPLES + + test_bts --bug 7 --host donbugs.donarmstrong.com + + +=cut + + +use Debbugs::Mail qw(send_mail_message); +use Debbugs::MIME qw(create_mime_message); + +use Search::Estraier; +use Debbugs::Estraier qw(:add); +use File::Find; + +use vars qw($DEBUG $VERBOSE); + +# XXX parse config file + +my %options = (debug => 0, + help => 0, + man => 0, + url => undef, + user => undef, + passwd => undef, + spool => undef, + conf => undef, + cron => 0, + timestamp => undef, + ); + +GetOptions(\%options,'url|u=s','user|U=s','passwd|P=s', + 'spool|s=s','conf|C=s','cron!','timestamp=s', + 'debug|d+','help|h|?','man|m'); + +my $ERRORS = ''; + +if (not defined $options{conf}) { + $ERRORS .= "--url must be set\n" if not defined $options{url}; + $ERRORS .= "--user must be set\n" if not defined $options{user}; + $ERRORS .= "--passwd must be set\n" if not defined $options{passwd}; +} +else { + # Read the conf file + my $conf_fh = new IO::File $options{conf},'r' + or die "Unable to open $options{conf} for reading"; + while (<$conf_fh>) { + chomp; + next if /^\s*\#/; + my ($key,$value) = split /\s*[:=]\s*/,$_,2; + $options{$key} = $value if not defined $options{$key}; + } + $ERRORS .= "url must be set\n" if not defined $options{url}; + $ERRORS .= "user must be set\n" if not defined $options{user}; + $ERRORS .= "passwd must be set\n" if not defined $options{passwd}; +} +$ERRORS .= "--spool must be set if --cron is used\n" if + not defined $options{spool} and $options{cron}; +pod2usage($ERRORS) if length $ERRORS; + +pod2usage() if $options{help}; +pod2usage({verbose=>2}) if $options{man}; + + +$DEBUG = $options{debug}; + +$VERBOSE = 0; + +my $node = new Search::Estraier::Node (url => $options{url}, + user => $options{user}, + passwd => $options{passwd}, + ); +$Debbugs::Config::gSpoolDir = $options{spool} if defined $options{spool}; + +if ($options{cron}) { + my %timestamps; + my $start_time = time; + my %seen_dirs; + # read timestamp file + if (defined $options{timestamp}) { + my $timestamp_fh = new IO::File $options{timestamp},'r' or + die "Unable to open timestamp $options{timestamp}: $!"; + while (<$timestamp_fh>) { + chomp; + my ($key,$value) = split /\s+/,$_,2; + $timestamps{$key} = $value; + } + } + find(sub { + print STDERR "Examining $_\n" if $DEBUG; + return if not /^(\d+)\.log$/; + my $bug_num = $1; + my $stat = stat $_ or next; + return unless -f _; + return if exists $timestamps{$File::Find::dir} and + $timestamps{$File::Find::dir} > $stat->mtime; + $seen_dirs{$File::Find::dir} = $start_time; + add_bug_log($node,$1); + }, + map {(-d "$options{spool}/$_")?"$options{spool}/$_":()} + qw(db-h archived db), + ); + # write timestamp file + if (defined $options{timestamp}) { + %timestamps = (%timestamps,%seen_dirs); + my $timestamp_fh = new IO::File $options{timestamp},'w' or + die "Unable to open timestamp $options{timestamp}: $!"; + foreach my $key (keys %timestamps) { + print {$timestamp_fh} $key,' ', + $timestamps{$key}||'',qq(\n); + } + } +} +else { + while (my $bug_num = ) { + chomp $bug_num; + add_bug_log($node,$bug_num); + } +} + + + +__END__ diff --git a/bin/test_bts b/bin/test_bts new file mode 100755 index 00000000..d9cf761a --- /dev/null +++ b/bin/test_bts @@ -0,0 +1,178 @@ +#!/usr/bin/perl +# test_bts tests a running BTS by sending mail to it, and is released +# under the terms of the GPL version 2, or any later version, at your +# option. See the file README and COPYING for more information. +# Copyright 2006 by Don Armstrong . + + + +use warnings; +use strict; + + +use Getopt::Long; +use Pod::Usage; + +=head1 NAME + +test_bts - Test a running bts install + +=head1 SYNOPSIS + +test_bts [options] + + Options: + --bug, -b bug number to mail + --host, -h host to send mail to + --control, -c whether to send control messages (off by default) + --process, -p whether to send process messages (on by default) + --submit, -s whether a new bug is created (off by default) + --quiet, -q disable output (off by default) + --debug, -d debugging level (Default 0) + --help, -h display this help + --man, -m display manual + +=head1 OPTIONS + +=over + +=item B<--bug, -b> + +Bug number to mail + +=item B<--host, -H> + +The host running the bts + +=item B<--control, -c> + +Whether control messages are sent; defaults to false. + +=item B<--process, -p> + +Whether messages are sent to process (bugnum@host) + +=item B<--submit, -s> + +Whether a new bug is created by a message to submit; not enabled by default. + +=item B<--quiet,-q> + +Disable output + +=item B<--debug, -d> + +Debug verbosity. (Default 0) + +=item B<--help, -h> + +Display brief useage information. + +=item B<--man, -m> + +Display this manual. + +=back + +=head1 EXAMPLES + + test_bts --bug 7 --host donbugs.donarmstrong.com + + +=cut + + +use Debbugs::Mail qw(send_mail_message); +use Debbugs::MIME qw(create_mime_message); + + +use vars qw($DEBUG $VERBOSE); + +# XXX parse config file + +my %options = (debug => 0, + help => 0, + man => 0, + host => undef, + bug => undef, + quiet => 0, + from => undef, + process => 1, + submit => 0, + control => 0, + ); + +GetOptions(\%options,'host|H=s','bug|b=s','control|c!','submit|s!', + 'process|p!','from|f=s','quiet|q+', + 'debug|d+','help|h|?','man|m'); + +my $ERRORS = ''; + +$ERRORS .= "--from must be set\n" if not defined $options{from}; +$ERRORS .= "--host must be set\n" if not defined $options{host}; +$ERRORS .= "--bug must be set\n" if not defined $options{bug}; +pod2usage($ERRORS) if length $ERRORS; + +pod2usage() if $options{help}; +pod2usage({verbose=>2}) if $options{man}; + + +$DEBUG = $options{debug}; + +$VERBOSE = 1 - $options{quiet}; + +if ($options{process}) { + my @standard_headers = ([], + ['X-Debbugs-No-Ack:','yes no ack'], + ); + + my %process_messages = ('-maintonly' => \@standard_headers, + '-quiet' => \@standard_headers, + '-forwarded' => \@standard_headers, + '-done' => \@standard_headers, + '-submitter' => \@standard_headers, + '' => \@standard_headers, + ); + my $message_count = 0; + for my $addr (keys %process_messages) { + for my $header (@{$process_messages{$addr}}) { + $message_count++; + my $message = + create_mime_message([To => "$options{bug}$addr\@$options{host}", + From => $options{from}, + Subject => "message $message_count to $addr from test_bts", + @{$header}, + ],< $message, + recipients => "$options{bug}$addr\@$options{host}", + ); + } + } +} +if ($options{control}) { + die "Not implemented"; +} +if ($options{submit}) { + die "Not implemented"; +} + +__END__