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