| 1 |
#! /usr/bin/perl |
| 2 |
|
| 3 |
use warnings; |
| 4 |
use strict; |
| 5 |
|
| 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); |
| 10 |
|
| 11 |
|
| 12 |
# Derived from the 'summary' script in the debbugs package, via |
| 13 |
# ~ajt/bugscan. |
| 14 |
|
| 15 |
my $startdate = time; |
| 16 |
die "failed to get time: $!" unless defined $startdate; |
| 17 |
|
| 18 |
# check the ctime of '/org/bugs.debian.org/www/stats/oldbugs.html' |
| 19 |
use File::stat; |
| 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, |
| 23 |
# don't rebuild it. |
| 24 |
exit 0; |
| 25 |
} |
| 26 |
|
| 27 |
my %excludepackage = (); |
| 28 |
for (qw(bugs.debian.org ftp.debian.org lists.debian.org)) { |
| 29 |
$excludepackage{$_} = 1; |
| 30 |
} |
| 31 |
|
| 32 |
my (%oldpackage, %olddesc, %oldage); |
| 33 |
|
| 34 |
count_bugs(function => sub { |
| 35 |
my %d = @_; |
| 36 |
|
| 37 |
# Fast checks. |
| 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}; |
| 42 |
|
| 43 |
my $status = get_bug_status($d{bug}); |
| 44 |
my @merged = sort split ' ', $status->{mergedwith}; |
| 45 |
return () if @merged and $merged[0] < $d{bug}; |
| 46 |
|
| 47 |
# 3600*24*30 (30 days) |
| 48 |
my $cmonths = int(($startdate - |
| 49 |
length($status->{date})?$status->{date}:0) / |
| 50 |
2592000); |
| 51 |
if ($cmonths >= 24 && !length($status->{forwarded}) && |
| 52 |
!$excludepackage{$d{pkg}}) { |
| 53 |
$oldpackage{$d{bug}} = $d{pkg}; |
| 54 |
$olddesc{$d{bug}} = (length($d{tags}) ? "$d{tags}/" : '') . |
| 55 |
$status->{subject}; |
| 56 |
$oldage{$d{bug}} = $cmonths; |
| 57 |
} |
| 58 |
}); |
| 59 |
|
| 60 |
my $date = `date`; |
| 61 |
chomp $date; |
| 62 |
|
| 63 |
my $nrbugs = keys %oldpackage; |
| 64 |
|
| 65 |
open OLDBUGS, '> /org/bugs.debian.org/www/stats/oldbugs.html.new' |
| 66 |
or die "can't open oldbugs.html.new: $!"; |
| 67 |
binmode(OLDBUGS,':encoding(UTF-8)'); |
| 68 |
print OLDBUGS <<EOF or die "can't write to oldbugs.html.new: $!"; |
| 69 |
<html><head><title>Bugs Over Two Years Old</title></head> |
| 70 |
<body> |
| 71 |
<h1>Bugs Over Two Years Old</h1> |
| 72 |
|
| 73 |
<p>Report date: $date<br> |
| 74 |
Number of bugs: $nrbugs |
| 75 |
</p> |
| 76 |
EOF |
| 77 |
|
| 78 |
# TODO: sort optimization would help a lot here |
| 79 |
while (%oldpackage) { |
| 80 |
my $firstpackage = $oldpackage{(sort { $a <=> $b } keys %oldpackage)[0]}; |
| 81 |
|
| 82 |
print OLDBUGS "<p>Package: <a href=\"http://bugs.debian.org/$firstpackage\">$firstpackage</a><br>\n" or |
| 83 |
die "can't write to oldbugs.html.new: $!"; |
| 84 |
# TODO: maintainer |
| 85 |
# TODO: comments |
| 86 |
for (sort { $a <=> $b } keys %oldpackage) { |
| 87 |
if ($oldpackage{$_} eq $firstpackage) { |
| 88 |
printf OLDBUGS "<a href=\"http://bugs.debian.org/%d\">%d</a> %s<br>\n", $_, $_, html_escape($olddesc{$_}) or |
| 89 |
die "can't write to oldbugs.html.new: $!";; |
| 90 |
# TODO: comments |
| 91 |
delete $oldpackage{$_}; |
| 92 |
} |
| 93 |
} |
| 94 |
print OLDBUGS "\n"; |
| 95 |
} |
| 96 |
|
| 97 |
close OLDBUGS or die "can't close oldbugs.html.new: $!"; |
| 98 |
rename '/org/bugs.debian.org/www/stats/oldbugs.html.new', |
| 99 |
'/org/bugs.debian.org/www/stats/oldbugs.html' |
| 100 |
or die "can't rename oldbugs.html.new to oldbugs.html: $!"; |