2 # vim: ts=4 sw=4 nowrap
4 # General functions for scanning the BTS-database.
5 # Based on bugscan, written by Richard Braakman <dark@debian.org>,
6 # which was based on an unknown other script.
9 # %comments - map from bugnumber to bug description
10 # %premature - list of prematurely closed bugreports
11 # %exclude - list of bugreports to exclude from the report
12 # %maintainer - map from packagename to maintainer
13 # %section - map from packagename to section in the FTP-site
14 # %packagelist - map from packagename to bugreports
15 # %NMU - map with NMU information
17 use lib qw(/org/bugs.debian.org/perl/);
19 use Debbugs::MIME qw(decode_rfc1522 encode_rfc1522);
20 use Debbugs::Packages;
21 use Debbugs::Versions;
23 use Fcntl qw(O_RDONLY);
28 # It is in paragraph format, with the first line of each paragraph being
29 # the bug number or package name to which the comment applies.
30 # Prefix a bug number with a * to force it to be listed even if it's closed.
31 # (This deals with prematurely closed bugs)
33 local($index); # Bug-number for current comment
34 local($file); # Name of comments-file
36 %comments = (); # Initialize our data
40 open(C, $file) or die "open $file: $!\n";
43 if (m/^\s*$/) { # Check for paragraph-breaks
45 } elsif (defined $index) {
46 $comments{$index} .= $_ . "\n";
48 if (s/^\*//) { # Test & remove initial *
51 if (s/\s+EXCLUDE\s*//) { # Test & remove EXCLUDE
56 $comments{$index} = ''; # New comment, initialize data
63 # Read the list of maintainer
64 sub readmaintainers() {
65 local ($pkg); # Name of package
66 local ($mnt); # Maintainer name & email
68 open(M, $maintainerlist) or die "open $maintainerlist: $!\n";
71 m/^(\S+)\s+(\S.*\S)\s*$/ or die "Maintainers: $_ ?";
72 ($pkg, $mnt) = ($1, $2);
73 $pkg =~ y/A-Z/a-z/; # Normalize package-name. why???
76 $mnt="$2 <$1>" if ( m/(\S+)\s+\(([^)]+)\)/ );
78 $maintainer{$pkg}= $mnt;
85 local($root); # Root of archive we are scanning
86 local($archive); # Name of archive we are scanning
87 local($sect); # Name of current section
91 for $sect ( @sections) {
92 open(P, "zcat $root/$sect/source/Sources.gz|")
93 or die open "open: $sect / $arch sourcelist: $!\n";
96 next unless m/^Package:\s/;
97 s/^Package:\s*//; # Strip the fieldname
98 $section{$_} = "$archive/$sect";
105 local($root); # Root of archive we are scanning
106 local($archive); # Name of archive we are scanning
107 local($sect); # Name of current section
108 local($arch); # Name of current architecture
112 for $arch ( @architectures ) {
113 for $sect ( @sections) {
114 open(P, "zcat $root/$sect/binary-$arch/Packages.gz|")
115 or die "open: $root/$sect/binary-$arch/Packages.gz: $!\n";
118 next unless m/^Package:\s/; # We're only interested in the packagenames
119 s/^Package:\s*//; # Strip the fieldname
120 $section{$_} = "$archive/$sect";
127 sub readdebbugssources() {
134 or die "open: $file: $!\n";
137 my ($host, $bin, $sect, $ver, $src) = split /\s+/;
138 my $sectname = ($sect =~ /^\Q$archive/) ? $sect : "$archive/$sect";
139 $debbugssection{$bin} = $sectname;
140 $debbugssection{$src} = $sectname;
145 sub readpseudopackages() {
146 open(P, $pseudolist) or die("open $pseudolist: $!\n");
150 $section{$_} = "pseudo";
160 chdir($spooldir) or die "chdir $spooldir: $!\n";
162 opendir(DIR, $spooldir) or die "opendir $spooldir: $!\n";
163 @dirs=grep(m/^\d+$/,readdir(DIR));
167 scanspooldir("$spooldir/$dir");
174 local($f); # While we're currently processing
175 local(@list); # List of files to process
176 local($skip); # Flow control
177 local($walk); # index variable
178 local($taginfo); # Tag info
180 chdir($dir) or die "chdir $dir: $!\n";
182 opendir(DIR, $dir) or die "opendir $dir: $!\n";
183 @list = grep { s/\.summary$// }
184 grep { m/^\d+\.summary$/ }
189 next if $exclude{$f}; # Check the list of bugs to skip
191 my $bug = Debbugs::Status::read_bug(summary => "$f.summary");
192 next if (!defined($bug));
195 for $walk (@priorities) {
196 $skip=0 if $walk eq $bug->{'severity'};
199 my @tags = split(' ', $bug->{'keywords'});
202 $skip=1 if $tag eq $s;
207 my $oldstable_tag = grep(/^woody$/, @tags);
208 my $stable_tag = grep(/^sarge$/, @tags);
209 my $testing_tag = grep(/^etch$/, @tags);
210 my $unstable_tag = grep(/^sid$/, @tags);
211 my $experimental_tag = grep(/^experimental$/, @tags);
213 # default according to dondelelcaro 2006-11-11
214 if (!$oldstable_tag && !$stable_tag && !$testing_tag && !$unstable_tag && !$experimental_tag) {
217 $experimental_tag = 1;
220 # only bother to check the versioning status for the distributions indicated by the tags
221 $status_oldstable = get_status($f, $bug, 'oldstable') if ($oldstable_tag);
222 $status_stable = get_status($f, $bug, 'stable') if ($stable_tag);
223 $status_testing = get_status($f, $bug, 'testing') if ($testing_tag);
224 $status_unstable = get_status($f, $bug, 'unstable') if ($unstable_tag);
225 $status_experimental = get_status($f, $bug, 'experimental') if ($experimental_tag);
228 $relinfo .= (($oldstable_tag && $status_oldstable->{'pending'} eq 'pending') ? "O" : "");
229 $relinfo .= (($stable_tag && $status_stable->{'pending'} eq 'pending') ? "S" : "");
230 $relinfo .= (($testing_tag && $status_testing->{'pending'} eq 'pending') ? "T" : "");
231 $relinfo .= (($unstable_tag && $status_unstable->{'pending'} eq 'pending') ? "U" : "");
232 $relinfo .= (($experimental_tag && $status_experimental->{'pending'} eq 'pending') ? "E" : "");
234 next if $relinfo eq '' and not $premature{$f};
235 $premature{$f}++ if $relinfo eq '';
238 $taginfo .= ($bug->{'keywords'} =~ /\bpending\b/ ? "P" : " ");
239 $taginfo .= ($bug->{'keywords'} =~ /\bpatch\b/ ? "+" : " ");
240 $taginfo .= ($bug->{'keywords'} =~ /\bhelp\b/ ? "H" : " ");
241 $taginfo .= ($bug->{'keywords'} =~ /\bmoreinfo\b/ ? "M" : " ");
242 $taginfo .= ($bug->{'keywords'} =~ /\bunreproducible\b/ ? "R" : " ");
243 $taginfo .= ($bug->{'keywords'} =~ /\bsecurity\b/ ? "S" : " ");
244 $taginfo .= ($bug->{'keywords'} =~ /\bupstream\b/ ? "U" : " ");
245 $taginfo .= ($bug->{'keywords'} =~ /\betch-ignore\b/ ? "I" : " ");
248 if (length($bug->{'mergedwith'})) {
249 my @merged = split(' ', $bug->{'mergedwith'});
250 next if ($merged[0] < $f);
253 for $package (split /[,\s]+/, $bug->{'package'}) {
254 $_= $package; y/A-Z/a-z/; $_= $` if m/[^-+._a-z0-9]/;
255 if (not defined $section{$_}) {
256 if (defined $debbugssection{$_}) {
259 next; # Skip unavailable packages
263 $packagelist{$_} .= " $f";
266 if ($relinfo eq "") { # or $relinfo eq "U" # confuses e.g. #210306
269 $relinfo = " [$relinfo]";
272 $bugs{$f} = "$f $taginfo$relinfo " . $bug->{'subject'};
278 local ($bug); # Number of current bug
279 local ($subject); # Subject for current bug
280 local ($pkg); # Name of current package
281 local ($file); # Name of statusfile
282 local ($sect); # Section of current package
283 local ($mnt); # Maintainer of current package
286 open(P, $file) or die "open $file: $!";
290 ($bug,$subject)=split(/ /, $_, 2);
291 $bugs{$bug}=$subject;
292 $packagelist{$pkg} .= "$bug ";
294 ($pkg,$sect, $mnt)=split(/ /, $_, 3);
295 $section{$pkg}=$sect;
296 $maintainer{$pkg}=$mnt;
303 sub readNMUstatus() {
304 local ($bug); # Number of current bug
305 local ($source); # Source upload which closes this bug.
306 local ($version); # Version where this bug was closed.
307 local ($flag); # Whether this paragraph has been processed.
308 local ($field, $value);
310 for (split /\n/, LWP::UserAgent->new->request(HTTP::Request->new(GET => shift))->content) {
314 $NMU{$bug, "source"} = $source;
315 $NMU{$bug, "version"} = $version;
316 # $comments{$bug} .= "[FIXED] Fixed package $source is in Incoming\n";
319 ($field, $value) = split(/: /, $_, 2);
320 $bug = $value if($field =~ /bug/i);
321 $source = $value if($field =~ /source/i);
322 $version = $value if($field =~ /version/i);
328 $NMU{$bug, "source"} = $source;
329 $NMU{$bug, "version"} = $version;
330 # $comments{$bug} .= "[FIXED] Fixed package $source in in Incoming\n";
340 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
341 $url =~ s/([<>&"])/\&$saniarray{$1};/g;
346 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
347 my $in = shift || "";
348 $in =~ s/([<>&"])/\&$saniarray{$1};/g;
353 local ($number) = shift; # Number of bug to html-ize
354 # local ($section); # Section for the bug
356 "<A HREF=\"http://bugs.debian.org/cgi-bin/bugreport.cgi?archive=no&bug=" .
357 urlsanit($number) . '">' . htmlsanit($number) . '</A>';
358 # ($section=$number) =~ s/([0-9]{2}).*/$1/;
359 # "<A HREF=\"${btsURL}/db/$section/$number.html\">$number</A>";
363 local ($name) = shift; # Name of package
365 "<A HREF=\"http://bugs.debian.org/cgi-bin/pkgreport.cgi?archive=no&pkg=" .
366 urlsanit($name) . '">' . htmlsanit($name) . '</A>';
367 # "<A HREF=\"${btsURL}/db/pa/l$name.html\">$name</A>";
370 my $_version_cache = {};
372 my ($bugnr, $bug, $dist) = @_;
374 my @versions = Debbugs::Status::getversions($bug->{'package'}, $dist, undef);
375 my @sourceversions = Debbugs::Status::makesourceversions($bug->{'package'}, undef, @versions);
377 return Debbugs::Status::max_buggy(bug => $bugnr,
378 sourceversions => \@sourceversions,
379 found => $bug->{'found_versions'},
380 fixed => $bug->{'fixed_versions'},
381 version_cache => $_version_cache,
382 package => $bug->{'package'});
388 if ($status =~ m/^\[[^]]*I/ or
389 $status =~ m/ \[[^]]*X/ or
390 ($status =~ m/ \[[^]]*[OSUE]/ and $status !~ m/ \[[^]]*T/)) {