6 use Debbugs::Config qw(:globals);
7 use Debbugs::Bugs qw(count_bugs);
8 use Debbugs::CGI qw(html_escape);
9 use Debbugs::Status qw(get_bug_status);
12 # Derived from the 'summary' script in the debbugs package, via
16 die "failed to get time: $!" unless defined $startdate;
18 # check the ctime of '/org/bugs.debian.org/www/stats/oldbugs.html'
20 my $ob = stat '/org/bugs.debian.org/www/stats/oldbugs.html';
21 if (defined $ob and (time - $ob->ctime) < 60*60*12) {
22 # If less than 12 hours have passed since we last ran this file,
27 my %excludepackage = ();
28 for (qw(bugs.debian.org ftp.debian.org lists.debian.org)) {
29 $excludepackage{$_} = 1;
32 my (%oldpackage, %olddesc, %oldage);
34 count_bugs(function => sub {
38 return () if $d{status} eq 'done' or
39 $d{severity} eq 'fixed' or $d{severity} eq 'wishlist';
40 my %tags = map { $_ => 1 } split ' ', $d{tags};
41 return () if $tags{fixed};
43 my $status = get_bug_status($d{bug});
44 my @merged = sort split ' ', $status->{mergedwith};
45 return () if @merged and $merged[0] < $d{bug};
47 # 3600*24*30 (30 days)
48 my $cmonths = int(($startdate - $status->{date}) / 2592000);
49 if ($cmonths >= 24 && !length($status->{forwarded}) &&
50 !$excludepackage{$d{pkg}}) {
51 $oldpackage{$d{bug}} = $d{pkg};
52 $olddesc{$d{bug}} = (length($d{tags}) ? "$d{tags}/" : '') .
54 $oldage{$d{bug}} = $cmonths;
61 my $nrbugs = keys %oldpackage;
63 open OLDBUGS, '> /org/bugs.debian.org/www/stats/oldbugs.html.new'
64 or die "can't open oldbugs.html.new: $!";
65 print OLDBUGS <<EOF or die "can't write to oldbugs.html.new: $!";
66 <html><head><title>Bugs Over Two Years Old</title></head>
68 <h1>Bugs Over Two Years Old</h1>
70 <p>Report date: $date<br>
71 Number of bugs: $nrbugs
75 # TODO: sort optimization would help a lot here
77 my $firstpackage = $oldpackage{(sort { $a <=> $b } keys %oldpackage)[0]};
79 print OLDBUGS "<p>Package: <a href=\"http://bugs.debian.org/$firstpackage\">$firstpackage</a><br>\n" or
80 die "can't write to oldbugs.html.new: $!";
83 for (sort { $a <=> $b } keys %oldpackage) {
84 if ($oldpackage{$_} eq $firstpackage) {
85 printf OLDBUGS "<a href=\"http://bugs.debian.org/%d\">%d</a> %s<br>\n", $_, $_, html_escape($olddesc{$_}) or
86 die "can't write to oldbugs.html.new: $!";;
88 delete $oldpackage{$_};
94 close OLDBUGS or die "can't close oldbugs.html.new: $!";
95 rename '/org/bugs.debian.org/www/stats/oldbugs.html.new',
96 '/org/bugs.debian.org/www/stats/oldbugs.html'
97 or die "can't rename oldbugs.html.new to oldbugs.html: $!";