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