| 1 |
#!/usr/bin/perl -w |
| 2 |
# |
| 3 |
# Grab bug information from the Debian BTS via SOAP, and update the |
| 4 |
# HEADER.html pages on cdimage.debian.org using that information |
| 5 |
# |
| 6 |
# Copyright 2011 Steve McIntyre <[email protected]> |
| 7 |
# GPL v2 |
| 8 |
|
| 9 |
use strict; |
| 10 |
use lib '/usr/share/devscripts'; |
| 11 |
use Devscripts::Debbugs; |
| 12 |
use Getopt::Long; |
| 13 |
use Data::Dumper; |
| 14 |
|
| 15 |
my ($daily_out, $weekly_out, $release_out); |
| 16 |
GetOptions ("daily=s" => \$daily_out, |
| 17 |
"weekly=s" => \$weekly_out, |
| 18 |
"release=s" => \$release_out); |
| 19 |
|
| 20 |
my $bugs; |
| 21 |
my $num_bugs; |
| 22 |
my $status; |
| 23 |
my %severities = ( |
| 24 |
wishlist => 1, |
| 25 |
minor => 2, |
| 26 |
normal => 3, |
| 27 |
important => 4, |
| 28 |
serious => 5, |
| 29 |
grave => 6, |
| 30 |
critical => 7 |
| 31 |
); |
| 32 |
my (@dailies, @weeklies, @releases); |
| 33 |
my $text; |
| 34 |
my $time_text; |
| 35 |
|
| 36 |
sub get_time() |
| 37 |
{ |
| 38 |
my @tm; |
| 39 |
my $text; |
| 40 |
|
| 41 |
@tm = gmtime(); |
| 42 |
$text = sprintf("%4d-%02d-%02d %02d:%02d:%02d UTC", |
| 43 |
(1900 + $tm[5]),(1 + $tm[4]),$tm[3],$tm[2],$tm[1],$tm[0]); |
| 44 |
return $text; |
| 45 |
} |
| 46 |
|
| 47 |
sub sort_bug ($$) |
| 48 |
{ |
| 49 |
my $a = shift; |
| 50 |
my $b = shift; |
| 51 |
if ($severities{$status->{$a}{"severity"}} > $severities{$status->{$b}{"severity"}}) { |
| 52 |
return -1; |
| 53 |
} |
| 54 |
if ($severities{$status->{$a}{"severity"}} < $severities{$status->{$b}{"severity"}}) { |
| 55 |
return 1; |
| 56 |
} |
| 57 |
return ($a cmp $b); |
| 58 |
} |
| 59 |
|
| 60 |
sub print_bugs (\@) |
| 61 |
{ |
| 62 |
my $listref = shift; |
| 63 |
my @list = @$listref; |
| 64 |
my $last_severity = "GUARD"; |
| 65 |
my $num_bugs = scalar (@list); |
| 66 |
my $text = ""; |
| 67 |
|
| 68 |
if ($num_bugs) { |
| 69 |
for my $bug (@list) { |
| 70 |
my $severity = $status->{$bug}{"severity"}; |
| 71 |
if ($severity !~ $last_severity) { |
| 72 |
if ($last_severity !~ "GUARD") { |
| 73 |
$text .= " </ul>\n"; |
| 74 |
} else { |
| 75 |
$text .= "<ul>\n"; |
| 76 |
} |
| 77 |
$text .= " <li>Severity: $severity\n"; |
| 78 |
$text .= " <ul>\n"; |
| 79 |
} |
| 80 |
$last_severity = $severity; |
| 81 |
$text .= " <li><a href=\"http://bugs.debian.org/$bug\">$bug</a>: "; |
| 82 |
$text .= $status->{$bug}{"subject"} . "\n"; |
| 83 |
} |
| 84 |
$text .= " </ul>\n"; |
| 85 |
$text .= "</ul>\n"; |
| 86 |
} else { |
| 87 |
$text .= "<p>No bugs found</p>\n"; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
sub update_file($$$) |
| 92 |
{ |
| 93 |
my $file = shift; |
| 94 |
my $text = shift; |
| 95 |
my $time_text = shift; |
| 96 |
my $update = 0; |
| 97 |
|
| 98 |
if (-f $file) { |
| 99 |
open(IN, "<", $file) or die "Can't open input file \"$file\" for reading\n"; |
| 100 |
open(OUT, ">", "$file.new") or die "Can't open output file \"$file.new\" for writing\n"; |
| 101 |
|
| 102 |
while (my $line = <IN>) { |
| 103 |
if ($line =~ /<!-- END BUGS -->/) |
| 104 |
{ |
| 105 |
print OUT "<p>Last bug check: $time_text</p>\n"; |
| 106 |
$update = 0; |
| 107 |
} |
| 108 |
if (!$update) { |
| 109 |
print OUT $line; |
| 110 |
} |
| 111 |
if ($line =~ /<!-- START BUGS -->/) |
| 112 |
{ |
| 113 |
$update = 1; |
| 114 |
print OUT $text; |
| 115 |
} |
| 116 |
} |
| 117 |
close(IN); |
| 118 |
close(OUT); |
| 119 |
rename "$file.new", "$file"; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
$bugs = Devscripts::Debbugs::select("package:cdimage.debian.org", "tags:d-i", "status", "tags"); |
| 124 |
if (not defined $bugs) { |
| 125 |
die "Error while retrieving bugs from SOAP server"; |
| 126 |
} |
| 127 |
|
| 128 |
$status = Devscripts::Debbugs::status(@{$bugs}); |
| 129 |
for my $bug (keys %{$status}) { |
| 130 |
my @versions = (@{$status->{$bug}{"found_versions"}}); |
| 131 |
my $version; |
| 132 |
if (!$status->{$bug}{"done"}) { |
| 133 |
foreach my $tmpver (@versions) { |
| 134 |
if ($tmpver =~ m/daily-image-(.*)$/) { |
| 135 |
$version = $1; |
| 136 |
push(@dailies, $bug); |
| 137 |
} elsif ($tmpver =~ m/weekly-image/) { |
| 138 |
$version = ""; |
| 139 |
push(@weeklies, $bug); |
| 140 |
} elsif ($tmpver =~ m/(\S*)-image/) { |
| 141 |
$version = $1; |
| 142 |
push(@releases, $bug); |
| 143 |
} else { |
| 144 |
print "unknown ver: " . $tmpver . "\n"; |
| 145 |
} |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
$time_text = get_time(); |
| 151 |
my $num_files = 0; |
| 152 |
|
| 153 |
if (defined ($daily_out)) { |
| 154 |
@dailies = sort sort_bug @dailies; |
| 155 |
$text = print_bugs(@dailies); |
| 156 |
update_file($daily_out, $text, $time_text); |
| 157 |
$num_files++; |
| 158 |
} |
| 159 |
if (defined ($weekly_out)) { |
| 160 |
@weeklies = sort sort_bug @weeklies; |
| 161 |
$text = print_bugs(@weeklies); |
| 162 |
update_file($weekly_out, $text, $time_text); |
| 163 |
$num_files++; |
| 164 |
} |
| 165 |
if (defined ($release_out)) { |
| 166 |
@releases = sort sort_bug @releases; |
| 167 |
$text = print_bugs(@releases); |
| 168 |
update_file($release_out, $text, $time_text); |
| 169 |
$num_files++; |
| 170 |
} |
| 171 |
if (!$num_files) { |
| 172 |
die "No output files defined\n"; |
| 173 |
} |