use lib dirname(__FILE__) for everything
[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 %list;               # List of bugnumber associated with package
140         my %seen_bugs;          # bugs which have already been counted
141
142         for my $p (sort keys %scanlib::packagelist) {
143                 my $count = 0;          # Number of bugs for this package
144
145                 for my $nr (@{$scanlib::packagelist{$p}}) {
146                     # if we've already counted this bug, we don't want to count it again
147                     next if $seen_bugs{$nr};
148                     $seen_bugs{$nr} = 1;
149                         $pendingtotal++ if ($scanlib::bugs{$nr}->{'pending'});
150                         $patchtotal++ if ($scanlib::bugs{$nr}->{'patch'});
151                         $ignoretotal++ if ($scanlib::bugs{$nr}->{$bugcfg::debian_releases->{stable}.'-ignore'} || $scanlib::bugs{$nr}->{$bugcfg::debian_releases->{testing}.'-ignore'});
152                         $worrytotal++ if (scanlib::check_worry($scanlib::bugs{$nr}));
153                         $stabletotal++ if (scanlib::check_worry_stable($scanlib::bugs{$nr}));
154
155                         $bugcount++;
156                         $count++;
157                 }
158         }
159
160         if ($html) {
161                 print "<strong><font color=\"red\">Total number of release-critical bugs</font>:</strong> $bugcount<BR>\n";
162                 printf("<strong>Number that have a patch:</strong> %d<BR>\n", $patchtotal);
163                 printf("<strong>Number that have a fix prepared and waiting to upload:</strong> %d<BR>\n", $pendingtotal);
164                 printf("<strong>Number that are being ignored:</strong> %d<BR>\n", $ignoretotal);
165                 printf("<strong><font color=\"blue\">Number concerning the current stable release</font>:</strong> %d<BR>\n", $stabletotal);
166                 printf("<strong><font color=\"green\">Number concerning the next release</font>:</strong> %d<P>\n", $worrytotal);
167         } else {
168                 print "Total number of release-critical bugs: $bugcount\n";
169                 printf("Number that have a patch: %d\n", $patchtotal);
170                 printf("Number that have a fix prepared and waiting to upload: %d\n", $pendingtotal);
171                 printf("Number that are being ignored: %d\n", $ignoretotal);
172                 printf("Number concerning the current stable release: %d\n", $stabletotal);
173                 printf("Number concerning the next release: %d\n", $worrytotal);
174         }
175 }
176
177
178 sub FilterPackages($) {
179         my $filter = shift;             # Distribution we want to keep
180
181         for my $p (sort keys %scanlib::packagelist) {
182                 delete $scanlib::packagelist{$p} unless (defined $scanlib::section{$p} and
183                                                          $scanlib::section{$p} =~ m/^$filter/);
184         }
185 }
186
187 sub FilterBugs() {
188         for my $p (sort keys %scanlib::packagelist) {
189                 $scanlib::packagelist{$p} = [ grep { scanlib::check_worry($scanlib::bugs{$_}) } @{$scanlib::packagelist{$p}} ];
190                 delete $scanlib::packagelist{$p} if (scalar @{$scanlib::packagelist{$p}} == 0);
191         }
192 }
193
194 sub FilterBugsStable() {
195         for my $p (sort keys %scanlib::packagelist) {
196                 $scanlib::packagelist{$p} = [ grep { scanlib::check_worry_stable($scanlib::bugs{$_}) } @{$scanlib::packagelist{$p}} ];
197                 delete $scanlib::packagelist{$p} if (scalar @{$scanlib::packagelist{$p}} == 0);
198         }
199 }
200
201 our ($opt_h,$opt_V,$opt_S,$opt_H,$opt_d,$opt_b,$opt_t,$opt_s,$opt_l);
202
203 getopts('VhHlsbtd:S:');
204 ShowUsage if ($opt_h);
205 ShowVersion if ($opt_V);
206 $statusfile=$opt_S if ($opt_S);
207 $html=1 if ($opt_H);
208
209 scanlib::readstatus($statusfile);
210
211 FilterPackages($opt_d) if ($opt_d);
212 FilterBugsStable() if ($opt_b);
213 FilterBugs() if ($opt_t);
214
215 MakeStatistics if ($opt_s);
216 if ($opt_l) {
217         MakeBuglist();
218 }
219
220 exit 0;
221