]> git.donarmstrong.com Git - debbugs.git/blobdiff - scripts/rebuild.in
[project @ 2003-08-23 15:12:57 by cjwatson]
[debbugs.git] / scripts / rebuild.in
index 6c869bf92b6e7df4a2554269d92faf9442655667..6c98f2545dba5f87bc325b2df921ba4a5d6b6f2e 100755 (executable)
@@ -1,78 +1,60 @@
 #!/usr/bin/perl -w
-# $Id: rebuild.in,v 1.3 2000/10/07 17:27:13 joy Exp $
+# $Id: rebuild.in,v 1.13 2003/08/23 15:12:57 cjwatson Exp $
 
-# Load modules and set envirnment
+# Load modules and set environment
 use File::Copy;
-require('/etc/debbugs/config');
-require('/usr/lib/debbugs/errorlib');
-$ENV{'PATH'} = '/usr/lib/debbugs:'.$ENV{'PATH'};
-chdir("$gSpoolDir") || die "chdir spool: $!\n";
+$config_path = '/etc/debbugs';
+$lib_path = '/usr/lib/debbugs';
 
-sub readreport {
-    my $lref = shift;
-       my $path = shift;
-       
-    open(S,"$path/$lref.status") || die "unable to open $path/$lref: $!\n";
-    chop($s_originator= <S>);
-    chop($s_date= <S>);
-    chop($s_subject= <S>);
-    chop($s_msgid= <S>);
-    chop($s_package= <S>);
-    chop($s_keywords= <S>);
-    chop($s_done= <S>);
-    chop($s_forwarded= <S>);
-    chop($s_mergedwith= <S>);
-    chop($s_severity= <S>);
-    close(S);
-    return 1;
-}
+require("$config_path/config");
+require("$lib_path/errorlib");
+use vars qw($gSpoolDir);
+
+$ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
+
+chdir("$gSpoolDir") || die "chdir spool: $!\n";
 
 #global variables
 $debug = 0;
-defined($startdate= time) || &quit("failed to get time: $!");
-
-@ARGV==0 or &quit( "no archive given on the commandline" );
-$archive= shift(@ARGV);
-open IDXFILE, "> index.$archive" or &quit( "trying to reset index file: $!" );
 
+@ARGV==0 and &quit( "no archive given on the commandline" );
+my $archive = shift(@ARGV);
+my $index = "index.$archive";
+$index = 'index.db' if $archive eq 'db-h';
+open IDXFILE, "> $index" or &quit( "trying to reset index file: $!" );
 
-if ( $archive eq 'db' )
+#get list of bugs (ie, status files)
+my @files;
+for ($subdir=0; $subdir<100; $subdir++ )
 {
-       opendir(DIR,'db') || next; 
-       @list= grep(m/^\d+\.status$/,readdir(DIR));
-       closedir DIR;
-       grep(s/\.status$//,@list);
-       @list= sort { $a <=> $b } @list;
-
-       #process each bug (ie, status file)
-       while ( defined( $list[0] )) 
-       {       my $ref = shift @list;
-               print STDERR "$ref considering\n" if $debug;
-       readreport($ref, $path);
-               printf IDXFILE "%s %d %s\n", $s_package, $ref, $s_subject;
-    }
+    my $path = sprintf( "$archive/%.2d", $subdir );
+    opendir(DIR,$path) || next; 
+    my @list= grep(m/^\d+\.summary$/,readdir(DIR));
+    closedir DIR;
+    grep(s/\.summary$//,@list);
+    push @files, @list;
 }
-else
-{
 
-#get list of bugs (ie, status files)
-for ($subdir=0; $subdir<100; $subdir++ )
+@files = sort { $a <=> $b } @files;
+
+#process each bug (ie, status file)
+for my $ref (@files) 
 {
-       my $path = sprintf( "$archive/%.2d", $subdir );
-       opendir(DIR,$path) || next; 
-       @list= grep(m/^\d+\.status$/,readdir(DIR));
-       closedir DIR;
-       grep(s/\.status$//,@list);
-       @list= sort { $a <=> $b } @list;
+    print STDERR "$ref considering\n" if $debug;
+    my $data = readbug($ref, $archive);
+    $data->{severity} =~ y/A-Z/a-z/;
 
-       #process each bug (ie, status file)
-       while ( defined( $list[0] )) 
-       {       my $ref = shift @list;
-               print STDERR "$ref considering\n" if $debug;
-       readreport($ref, $path);
-               printf IDXFILE "%s %d %s\n", $s_package, $ref, $s_subject;
-    }
-}
+    (my $pkglist = $data->{package}) =~ s/[,\s]+/,/g;
+    $pkglist =~ s/^,+//;
+    $pkglist =~ s/,+$//;
 
+    my $whendone = 'open';
+    $whendone = 'forwarded' if length $data->{forwarded};
+    $whendone = 'done' if length $data->{done};
+
+    printf IDXFILE "%s %d %d %s [%s] %s %s\n",
+       $pkglist, $ref, $data->{date}, $whendone, $data->{originator},
+       $data->{severity}, $data->{keywords};
 }
+
 close IDXFILE;