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