Small simplification in bugcounts.
[bugscan.git] / bugreport
1 #!/usr/bin/perl
2 # vim: ts=4 sw=4 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] [-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   -t    show bugs relevant for testing only
32   -d    only list these distributions (comma-separated)
33   -S    use different statusfile
34 EOF
35         exit 0;
36 }
37
38 sub PrintPackageHeader() {
39         my $p   = shift;        # Package to print
40         my ($name, $email);     # Name & email of maintainer
41
42         if ($html) {
43                 print "<div class=\"package\"><pre>";
44                 print "<a name=\"$p\"><strong>Package:</strong></a> " . scanlib::wwwname($p);
45                 if (defined($scanlib::section{$p})) {
46                         print " ($scanlib::section{$p}).\n";
47                 } else {
48                         print " (unknown).\n";
49                 }
50                 print "<strong>Maintainer:</strong> ";
51                 if (exists($scanlib::maintainer{$p}) && $scanlib::maintainer{$p} ne '') {
52                         if ($scanlib::maintainer{$p} =~ /(.*) <([^>]*)>/) {
53                                 ($name,$email) = ($1,$2);
54                         } elsif ($scanlib::maintainer{$p} =~ /<(.*) \((.*)\)>/) {
55                                 ($name,$email) = ($1,$2);
56                         } elsif ($scanlib::maintainer{$p} =~ /<(.*)>/) {
57                                 $name = $email = $1;
58                         }
59                         if (defined($name)) {
60                                 print "$name &lt;<a href=\"http://bugs.debian.org/$email\">$email</A>&gt;\n";
61                         } else {
62                                 print "$scanlib::maintainer{$p}\n";
63                         }
64                 } else {
65                         print "unknown\n";
66                 }
67         } else {
68                 print "\nPackage: $p ($scanlib::section{$p})\n";
69                 print "Maintainer: " . (defined($scanlib::maintainer{$p}) ? $scanlib::maintainer{$p} : "unknown") . "\n";
70         }
71 }
72
73 sub PrintPackageFooter() {
74         my $p   = shift;        # Package to print
75
76         if ($html) {
77                 print "</pre></div>\n";
78         }
79 }
80
81 sub MakeBuglist() {
82         my $p;                          # Index variable
83         my $nr;                 # Current bugnumber
84         my $sect;                       # BTS-subsection for bugnumber
85         my $header;             # Flag if packagename has already been printed
86
87         for my $p (sort {$a cmp $b} keys %scanlib::packagelist) {
88                 $header = 0;
89                 for $nr (sort @{$scanlib::packagelist{$p}}) {
90                         if (! $header) {
91                                 $header = 1;
92                                 &PrintPackageHeader($p);
93                         }
94
95                         if ($html) {
96                                 my $worry = scanlib::check_worry($scanlib::bugs{$nr});
97                         
98                                 if ($scanlib::bugs{$nr} =~ m/ \[[^]]*X/) {
99                                         print '<span style="color: #808080">';
100                                 } elsif ($scanlib::bugs{$nr} =~ m/^\[[^]]*P/) {
101                                         print '<span style="color: #f040d0">';
102                                 } elsif ($scanlib::bugs{$nr} =~ m/^\[[^]]*\+/) {
103                                         print '<span style="color: #00aa00">';
104                                 } elsif ($scanlib::bugs{$nr} =~ m/^\[[^]]*H/) {
105                                         print '<span style="color: #ffaa30">';
106                                 }
107                                 print "<strike>" if ($scanlib::bugs{$nr} =~ m/^\[.......I\]/);
108                                 print "<em class=\"worry\">" if $worry;
109                                 ($sect=$nr) =~ s/([0-9]{2}).*/$1/;
110                                 print "<A NAME=\"$nr\"></A>  " . scanlib::wwwnumber($nr) . ' ' .
111                                           scanlib::htmlsanit($scanlib::bugs{$nr}) . "\n";
112                                 print "</em>" if $worry;
113                                 print "</strike>" if ($scanlib::bugs{$nr} =~ m/^\[.......I\]/);
114                         } else {
115                                 printf("  %-6d %s\n", $nr, $scanlib::bugs{$nr});
116                         }
117                         print "</span>" if ($html && ($scanlib::bugs{$nr} =~ m/^\[[^]]*[H+P]/ ||
118                                                       $scanlib::bugs{$nr} =~ m/ \[[^]]*X/));
119                 }
120                 if ($header) {
121                         &PrintPackageFooter($p);
122                 }
123         }
124 }
125
126
127 sub MakeStatistics() {
128         my $bugcount=0;         # Total number of bugs so far
129         my $patchtotal=0;       # Total number of bugs marked patch
130         my $pendingtotal=0;     # Total number of bugs marked pending
131         my $ignoretotal=0;      # Total number of bugs marked ignore
132         my $worrytotal=0;       # Total number of bugs we're actually worried about
133         my $stabletotal=0;      # Total number of bugs affecting stable
134         my %list;               # List of bugnumber associated with package
135
136         for my $p (sort keys %scanlib::packagelist) {
137                 my $count = 0;          # Number of bugs for this package
138
139                 for my $nr (@{$scanlib::packagelist{$p}}) {
140                         $pendingtotal++ if ($scanlib::bugs{$nr}->{'pending'});
141                         $patchtotal++ if ($scanlib::bugs{$nr}->{'patch'});
142                         $ignoretotal++ if ($scanlib::bugs{$nr}->{'sarge-ignore'} || $scanlib::bugs{$nr}->{'etch-ignore'});
143                         $worrytotal++ if (scanlib::check_worry($scanlib::bugs{$nr}));
144                         $stabletotal++ if (scanlib::check_worry_stable($scanlib::bugs{$nr}));
145
146                         $bugcount++;
147                         $count++;
148                 }
149         }
150
151         if ($html) {
152                 print "<strong>Total number of release-critical bugs:</strong> $bugcount<BR>\n";
153                 printf("<strong>Number that have a patch:</strong> %d<BR>\n", $patchtotal);
154                 printf("<strong>Number that have a fix prepared and waiting to upload:</strong> %d<BR>\n", $pendingtotal);
155                 printf("<strong>Number that are being ignored:</strong> %d<BR>\n", $ignoretotal);
156                 printf("<strong>Number concerning the current stable release:</strong> %d<BR>\n", $stabletotal);
157                 printf("<strong>Number concerning the next release (excluding ignored and not-in-testing):</strong> %d<P>\n", $worrytotal);
158         } else {
159                 print "Total number of release-critical bugs: $bugcount\n";
160                 printf("Number that have a patch: %d\n", $patchtotal);
161                 printf("Number that have a fix prepared and waiting to upload: %d\n", $pendingtotal);
162                 printf("Number that are being ignored: %d\n", $ignoretotal);
163                 printf("Number concerning the current stable release: %d<P>\n", $stabletotal);
164                 printf("Number concerning the next release (excluding ignored and not-in-testing): %d\n", $worrytotal);
165         }
166 }
167
168
169 sub FilterPackages($) {
170         my $filter = shift;             # Distribution we want to keep
171
172         for my $p (sort keys %scanlib::packagelist) {
173                 delete $scanlib::packagelist{$p} unless ($scanlib::section{$p} =~ m/^$filter/);
174         }
175 }
176
177 sub FilterBugs() {
178         for my $p (sort keys %scanlib::packagelist) {
179                 $scanlib::packagelist{$p} = [ grep { scanlib::check_worry($scanlib::bugs{$_}) } @{$scanlib::packagelist{$p}} ];
180                 delete $scanlib::packagelist{$p} if (scalar @{$scanlib::packagelist{$p}} == 0);
181         }
182 }
183
184 our ($opt_h,$opt_V,$opt_S,$opt_H,$opt_d,$opt_t,$opt_s,$opt_l);
185
186 getopts('VhHlstd:S:');
187 ShowUsage if ($opt_h);
188 ShowVersion if ($opt_V);
189 $statusfile=$opt_S if ($opt_S);
190 $html=1 if ($opt_H);
191
192 scanlib::readstatus($statusfile);
193
194 FilterPackages($opt_d) if ($opt_d);
195 FilterBugs() if ($opt_t);
196
197 MakeStatistics if ($opt_s);
198 if ($opt_l) {
199         MakeBuglist();
200 }
201
202 exit 0;
203