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