bugscan now uses basename
[bugscan.git] / bugreport
1 #!/usr/bin/perl
2 # vim: ts=8 sw=8 nowrap
3
4 # Generate a report of the release-critical bugs for packages
5
6 use Getopt::Std;
7 require scanlib;
8 require bugcfg;
9 use strict;
10 use warnings;
11
12 my $Version             = "BugReport 1.4\nCopyright (C) 1998-2002 Wichert Akkerman <wakkerma\@debian.org>\n";
13 my $html                = 0;
14 my $statusfile          = "status";
15
16 sub ShowVersion() {
17         print "$Version\n";
18         exit 0;
19 }
20
21 sub ShowUsage() {
22         print <<EOF;
23 Usage:
24   $0 [-V] [-h] [-H] [-l] [-s] [-b] [-t] [-d distrib] [-S file] [-C file]
25 Options:
26   -V    show version
27   -h    show some (hopefully) helpful information
28   -H    produce HTML output
29   -l    list all release-critical bugs
30   -s    list bug statistics
31   -b    show bugs relevant for stable only
32   -t    show bugs relevant for testing only
33   -d    only list these distributions (comma-separated)
34   -S    use different statusfile
35 EOF
36         exit 0;
37 }
38
39 sub PrintPackageHeader() {
40         my $p   = shift;        # Package to print
41         my ($name, $email);     # Name & email of maintainer
42
43         if ($html) {
44                 print "<div class=\"package\"><pre>";
45                 print "<a name=\"$p\"><strong>Package:</strong></a> " . scanlib::wwwname($p);
46                 if (defined($scanlib::section{$p})) {
47                         print " ($scanlib::section{$p}).\n";
48                 } else {
49                         print " (unknown).\n";
50                 }
51                 print "<strong>Maintainer:</strong> ";
52                 if (exists($scanlib::maintainer{$p}) && $scanlib::maintainer{$p} ne '') {
53                         if ($scanlib::maintainer{$p} =~ /(.*) <([^>]*)>/) {
54                                 ($name,$email) = ($1,$2);
55                         } elsif ($scanlib::maintainer{$p} =~ /<(.*) \((.*)\)>/) {
56                                 ($name,$email) = ($1,$2);
57                         } elsif ($scanlib::maintainer{$p} =~ /<(.*)>/) {
58                                 $name = $email = $1;
59                         }
60                         if (defined($name)) {
61                                 print "$name &lt;<a href=\"http://bugs.debian.org/$email\">$email</A>&gt;\n";
62                         } else {
63                                 print "$scanlib::maintainer{$p}\n";
64                         }
65                 } else {
66                         print "unknown\n";
67                 }
68         } else {
69                 print "\nPackage: $p ($scanlib::section{$p})\n";
70                 print "Maintainer: " . (defined($scanlib::maintainer{$p}) ? $scanlib::maintainer{$p} : "unknown") . "\n";
71         }
72 }
73
74 sub PrintPackageFooter() {
75         my $p   = shift;        # Package to print
76
77         if ($html) {
78                 print "</pre></div>\n";
79         }
80 }
81
82 sub MakeBuglist() {
83         my $p;                          # Index variable
84         my $nr;                 # Current bugnumber
85         my $sect;                       # BTS-subsection for bugnumber
86         my $header;             # Flag if packagename has already been printed
87
88         for my $p (sort {$a cmp $b} keys %scanlib::packagelist) {
89                 $header = 0;
90                 for $nr (sort @{$scanlib::packagelist{$p}}) {
91                         if (! $header) {
92                                 $header = 1;
93                                 &PrintPackageHeader($p);
94                         }
95
96                         if ($html) {
97                                 my $worry = scanlib::check_worry($scanlib::bugs{$nr});
98                         
99                                 if ($scanlib::bugs{$nr}->{'pending'}) {
100                                         print '<span style="color: #f040d0">';
101                                 } elsif ($scanlib::bugs{$nr}->{'patch'}) {
102                                         print '<span style="color: #00aa00">';
103                                 } elsif ($scanlib::bugs{$nr}->{'help'}) {
104                                         print '<span style="color: #ffaa30">';
105                                 }
106                                 print "<strike>" if ($scanlib::bugs{$nr}->{$bugcfg::debian_releases->{stable}.'-ignore'} || $scanlib::bugs{$nr}->{$bugcfg::debian_releases->{testing}.'-ignore'});
107                                 print "<em class=\"worry\">" if $worry;
108                                 ($sect=$nr) =~ s/([0-9]{2}).*/$1/;
109                                 printf "<A NAME=\"$nr\"></A>  %s [%s] [%s] %s\n", scanlib::wwwnumber($nr),
110                                         scanlib::get_taginfo($scanlib::bugs{$nr}),
111                                         scanlib::get_relinfo($scanlib::bugs{$nr}), 
112                                         scanlib::htmlsanit($scanlib::bugs{$nr}->{'subject'});
113                                 print "</em>" if $worry;
114                                 print "</strike>" if ($scanlib::bugs{$nr}->{$bugcfg::debian_releases->{stable}.'-ignore'} || $scanlib::bugs{$nr}->{$bugcfg::debian_releases->{testing}.'-ignore'});
115                         } else {
116                                 printf("  %-6d [%s] [%s] %s\n", $nr, scanlib::get_taginfo($scanlib::bugs{$nr}),
117                                         scanlib::get_relinfo($scanlib::bugs{$nr}), $scanlib::bugs{$nr}->{'subject'});
118                         }
119                         print "</span>" if ($html && ($scanlib::bugs{$nr}->{'pending'} ||
120                                                       $scanlib::bugs{$nr}->{'patch'} ||
121                                                                                   $scanlib::bugs{$nr}->{'help'}));
122                 }
123                 if ($header) {
124                         &PrintPackageFooter($p);
125                 }
126         }
127 }
128
129
130 sub MakeStatistics() {
131         my $bugcount=0;         # Total number of bugs so far
132         my $patchtotal=0;       # Total number of bugs marked patch
133         my $pendingtotal=0;     # Total number of bugs marked pending
134         my $ignoretotal=0;      # Total number of bugs marked ignore
135         my $worrytotal=0;       # Total number of bugs we're actually worried about
136         my $stabletotal=0;      # Total number of bugs affecting stable
137         my %list;               # List of bugnumber associated with package
138         my %seen_bugs;          # bugs which have already been counted
139
140         for my $p (sort keys %scanlib::packagelist) {
141                 my $count = 0;          # Number of bugs for this package
142
143                 for my $nr (@{$scanlib::packagelist{$p}}) {
144                     # if we've already counted this bug, we don't want to count it again
145                     next if $seen_bugs{$nr};
146                     $seen_bugs{$nr} = 1;
147                         $pendingtotal++ if ($scanlib::bugs{$nr}->{'pending'});
148                         $patchtotal++ if ($scanlib::bugs{$nr}->{'patch'});
149                         $ignoretotal++ if ($scanlib::bugs{$nr}->{$bugcfg::debian_releases->{stable}.'-ignore'} || $scanlib::bugs{$nr}->{$bugcfg::debian_releases->{testing}.'-ignore'});
150                         $worrytotal++ if (scanlib::check_worry($scanlib::bugs{$nr}));
151                         $stabletotal++ if (scanlib::check_worry_stable($scanlib::bugs{$nr}));
152
153                         $bugcount++;
154                         $count++;
155                 }
156         }
157
158         if ($html) {
159                 print "<strong><font color=\"red\">Total number of release-critical bugs</font>:</strong> $bugcount<BR>\n";
160                 printf("<strong>Number that have a patch:</strong> %d<BR>\n", $patchtotal);
161                 printf("<strong>Number that have a fix prepared and waiting to upload:</strong> %d<BR>\n", $pendingtotal);
162                 printf("<strong>Number that are being ignored:</strong> %d<BR>\n", $ignoretotal);
163                 printf("<strong><font color=\"blue\">Number concerning the current stable release</font>:</strong> %d<BR>\n", $stabletotal);
164                 printf("<strong><font color=\"green\">Number concerning the next release</font>:</strong> %d<P>\n", $worrytotal);
165         } else {
166                 print "Total number of release-critical bugs: $bugcount\n";
167                 printf("Number that have a patch: %d\n", $patchtotal);
168                 printf("Number that have a fix prepared and waiting to upload: %d\n", $pendingtotal);
169                 printf("Number that are being ignored: %d\n", $ignoretotal);
170                 printf("Number concerning the current stable release: %d\n", $stabletotal);
171                 printf("Number concerning the next release: %d\n", $worrytotal);
172         }
173 }
174
175
176 sub FilterPackages($) {
177         my $filter = shift;             # Distribution we want to keep
178
179         for my $p (sort keys %scanlib::packagelist) {
180                 delete $scanlib::packagelist{$p} unless (defined $scanlib::section{$p} and
181                                                          $scanlib::section{$p} =~ m/^$filter/);
182         }
183 }
184
185 sub FilterBugs() {
186         for my $p (sort keys %scanlib::packagelist) {
187                 $scanlib::packagelist{$p} = [ grep { scanlib::check_worry($scanlib::bugs{$_}) } @{$scanlib::packagelist{$p}} ];
188                 delete $scanlib::packagelist{$p} if (scalar @{$scanlib::packagelist{$p}} == 0);
189         }
190 }
191
192 sub FilterBugsStable() {
193         for my $p (sort keys %scanlib::packagelist) {
194                 $scanlib::packagelist{$p} = [ grep { scanlib::check_worry_stable($scanlib::bugs{$_}) } @{$scanlib::packagelist{$p}} ];
195                 delete $scanlib::packagelist{$p} if (scalar @{$scanlib::packagelist{$p}} == 0);
196         }
197 }
198
199 our ($opt_h,$opt_V,$opt_S,$opt_H,$opt_d,$opt_b,$opt_t,$opt_s,$opt_l);
200
201 getopts('VhHlsbtd:S:');
202 ShowUsage if ($opt_h);
203 ShowVersion if ($opt_V);
204 $statusfile=$opt_S if ($opt_S);
205 $html=1 if ($opt_H);
206
207 scanlib::readstatus($statusfile);
208
209 FilterPackages($opt_d) if ($opt_d);
210 FilterBugsStable() if ($opt_b);
211 FilterBugs() if ($opt_t);
212
213 MakeStatistics if ($opt_s);
214 if ($opt_l) {
215         MakeBuglist();
216 }
217
218 exit 0;
219