2 # add_bug_to_estraier adds a log for a bug to the estaier db, and is
3 # released under the terms of the GPL version 2, or any later version,
4 # at your option. See the file README and COPYING for more
6 # Copyright 2006 by Don Armstrong <don@debian.org>.
19 add_bug_to_estraier -- add a bug log to an estraier database
23 add_bug_to_estraier [options] < list_of_bugs_to_add
26 --url, -u url to estraier node
27 --user, -U user to log into the estraier node
28 --pass, -P password for the estraier node
29 --spool, -s spool location
30 --conf, -c addbug configuration file
31 --cron add all bugs to estraier
32 --timestamp bug timestamp file
33 --debug, -d debugging level (Default 0)
34 --help, -h display this help
35 --man, -m display manual
43 Url to the estraier node
47 User to log onto the estraier node
51 Password to log onto the estraier node
55 Spool location; if not set defaults to /etc/debbugs/config
59 Configuration file; a set of key = value pairs separated by newlines;
60 the long name of any option is the name that the configuration file
65 Descend through the spool and add all of the bugs to estraier
69 Use the timestamp file to only add new bugs; will lock the timestamp
70 file to avoid racing with other invocations
74 Debug verbosity. (Default 0)
78 Display brief useage information.
89 test_bts --bug 7 --host donbugs.donarmstrong.com
91 =head1 DATABASE CREATION
93 estcmd create -si -xh3 -attr status str -attr subject str \
94 -attr date num -attr submitter str -attr package str \
95 -attr severity str -attr tags str bts
101 use Debbugs::Config qw(:globals);
102 use Debbugs::Mail qw(send_mail_message);
103 use Debbugs::MIME qw(create_mime_message);
105 use Search::Estraier;
106 use Debbugs::Estraier qw(:add);
110 use vars qw($DEBUG $VERBOSE);
112 # XXX parse config file
114 my %options = (debug => 0,
126 GetOptions(\%options,'url|u=s','user|U=s','passwd|P=s',
127 'spool|s=s','conf|C=s','cron!','timestamp=s',
128 'debug|d+','help|h|?','man|m');
132 if (not defined $options{conf}) {
133 $ERRORS .= "--url must be set\n" if not defined $options{url};
134 $ERRORS .= "--user must be set\n" if not defined $options{user};
135 $ERRORS .= "--passwd must be set\n" if not defined $options{passwd};
139 my $conf_fh = new IO::File $options{conf},'r'
140 or die "Unable to open $options{conf} for reading";
144 my ($key,$value) = split /\s*[:=]\s*/,$_,2;
145 $options{$key} = $value if defined $key and not defined $options{$key};
147 $ERRORS .= "url must be set\n" if not defined $options{url};
148 $ERRORS .= "user must be set\n" if not defined $options{user};
149 $ERRORS .= "passwd must be set\n" if not defined $options{passwd};
151 $ERRORS .= "--spool must be set if --cron is used\n" if
152 not defined $options{spool} and $options{cron};
153 pod2usage($ERRORS) if length $ERRORS;
155 pod2usage() if $options{help};
156 pod2usage({verbose=>2}) if $options{man};
159 $DEBUG = $options{debug};
161 $Debbugs::Estraier::DEBUG = $DEBUG;
164 my $node = new Search::Estraier::Node (url => $options{url},
165 user => $options{user},
166 passwd => $options{passwd},
168 $gSpoolDir = $options{spool} if defined $options{spool};
170 if ($options{cron}) {
172 my $start_time = time;
175 check_pid($options{timestamp});
176 # read timestamp file
177 if (defined $options{timestamp}) {
178 my $timestamp_fh = new IO::File $options{timestamp},'r' or
179 die "Unable to open timestamp $options{timestamp}: $!";
180 while (<$timestamp_fh>) {
182 my ($key,$value) = split /\s+/,$_,2;
183 $timestamps{$key} = $value;
186 for my $hash (map {sprintf '%02d',$_ } 0..99) {
188 print STDERR "Examining $_\n" if $DEBUG > 1;
189 return if not /^(\d+)\.log$/;
191 my $stat = stat $_ or next;
193 return if exists $timestamps{$File::Find::dir} and
194 ($timestamps{$File::Find::dir} > $stat->mtime);
195 $seen_dirs{$File::Find::dir} = $start_time;
196 print STDERR "Adding $bug_num\n" if $DEBUG;
199 $max_message = add_bug_log($node,$bug_num);
202 print STDERR "Adding $bug_num failed with $@\n";
205 map {(-d "$options{spool}/$_/$hash")?
206 "$options{spool}/$_/$hash":()}
209 # write timestamp file
210 if (defined $options{timestamp}) {
211 %timestamps = (%timestamps,%seen_dirs);
212 my $timestamp_fh = new IO::File $options{timestamp},'w' or
213 die "Unable to open timestamp $options{timestamp}: $!";
214 foreach my $key (keys %timestamps) {
215 print {$timestamp_fh} $key,' ',
216 $timestamps{$key}||'',qq(\n);
220 unlink("$options{timestamp}.pid");
223 while (my $bug_num = <STDIN>) {
225 add_bug_log($node,$bug_num);
231 my ($timestamp) = @_;
232 if (-e "${timestamp}.pid") {
233 my $time_fh = new IO::File "${timestamp}.pid", 'r' or die "Unable to read pidfile";
235 my $pid = <$time_fh>;
237 print STDERR "Another cron is running" and exit 0;
240 my $time_fh = new IO::File "${timestamp}.pid", 'w' or
241 die "Unable to read pidfile";