File: grab_cdimage_bugs

package info (click to toggle)
debian-cd 3.1.13
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,244 kB
  • sloc: sh: 4,925; perl: 3,730; makefile: 387
file content (173 lines) | stat: -rwxr-xr-x 4,543 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/perl -w
#
# Grab bug information from the Debian BTS via SOAP, and update the
# HEADER.html pages on cdimage.debian.org using that information
#
# Copyright 2011 Steve McIntyre <93sam@debian.org>
# GPL v2

use strict;
use lib '/usr/share/devscripts';
use Devscripts::Debbugs;
use Getopt::Long;
use Data::Dumper;

my ($daily_out, $weekly_out, $release_out);
GetOptions ("daily=s"   => \$daily_out,
            "weekly=s"  => \$weekly_out,
            "release=s" => \$release_out);

my $bugs;
my $num_bugs;
my $status;
my %severities = (
    wishlist   => 1,
    minor      => 2,
    normal     => 3,
    important  => 4,
    serious    => 5,
    grave      => 6,
    critical   => 7
    );
my (@dailies, @weeklies, @releases);
my $text;
my $time_text;

sub get_time()
{
    my @tm;
    my $text;

    @tm = gmtime();
    $text = sprintf("%4d-%02d-%02d %02d:%02d:%02d UTC",
                    (1900 + $tm[5]),(1 + $tm[4]),$tm[3],$tm[2],$tm[1],$tm[0]);
    return $text;
}

sub sort_bug ($$)
{
    my $a = shift;
    my $b = shift;
    if ($severities{$status->{$a}{"severity"}} > $severities{$status->{$b}{"severity"}}) {
        return -1;
    }
    if ($severities{$status->{$a}{"severity"}} < $severities{$status->{$b}{"severity"}}) {
        return 1;
    }
    return ($a cmp $b);
}

sub print_bugs (\@)
{
    my $listref = shift;
    my @list = @$listref;
    my $last_severity = "GUARD";
    my $num_bugs = scalar (@list);
    my $text = "";

    if ($num_bugs) {
        for my $bug (@list) {
            my $severity = $status->{$bug}{"severity"};
            if ($severity !~ $last_severity) {
                if ($last_severity !~ "GUARD") {
                    $text .= "  </ul>\n";
                } else {
                    $text .= "<ul>\n";
                }
                $text .= "  <li>Severity: $severity\n";
                $text .= "  <ul>\n";
            }
            $last_severity = $severity;
            $text .= "    <li><a href=\"http://bugs.debian.org/$bug\">$bug</a>: ";
            $text .= $status->{$bug}{"subject"} . "\n";
        }
        $text .= "  </ul>\n";
        $text .= "</ul>\n";
    } else {
        $text .= "<p>No bugs found</p>\n";
    }
}

sub update_file($$$)
{
    my $file = shift;
    my $text = shift;
    my $time_text = shift;
    my $update = 0;

    if (-f $file) {
        open(IN, "<", $file) or die "Can't open input file \"$file\" for reading\n";
        open(OUT, ">", "$file.new") or die "Can't open output file \"$file.new\" for writing\n";

        while (my $line = <IN>) {
            if ($line =~ /<!-- END BUGS -->/)
            {
                print OUT "<p>Last bug check: $time_text</p>\n";
                $update = 0;
            }
            if (!$update) {
                print OUT $line;
            }
            if ($line =~ /<!-- START BUGS -->/)
            {
                $update = 1;
                print OUT $text;
            }
        }
        close(IN);
        close(OUT);
        rename "$file.new", "$file";
    }
}

$bugs = Devscripts::Debbugs::select("package:cdimage.debian.org", "tags:d-i", "status", "tags");
if (not defined $bugs) {
    die "Error while retrieving bugs from SOAP server";
}

$status = Devscripts::Debbugs::status(@{$bugs});
for my $bug (keys %{$status}) {
    my @versions = (@{$status->{$bug}{"found_versions"}});
    my $version;
    if (!$status->{$bug}{"done"}) {
        foreach my $tmpver (@versions) {
            if ($tmpver =~ m/daily-image-(.*)$/) {
                $version = $1;
                push(@dailies, $bug);
            } elsif ($tmpver =~ m/weekly-image/) {
                $version = "";
                push(@weeklies, $bug);
            } elsif ($tmpver =~ m/(\S*)-image/) {
                $version = $1;
                push(@releases, $bug);
            } else {
                print "unknown ver: " . $tmpver . "\n";
            }
        }
    }
}

$time_text = get_time();
my $num_files = 0;

if (defined ($daily_out)) {
    @dailies = sort sort_bug @dailies;
    $text = print_bugs(@dailies);
    update_file($daily_out, $text, $time_text);
    $num_files++;
}
if (defined ($weekly_out)) {
    @weeklies = sort sort_bug @weeklies;
    $text = print_bugs(@weeklies);
    update_file($weekly_out, $text, $time_text);
    $num_files++;
}
if (defined ($release_out)) {
    @releases = sort sort_bug @releases;
    $text = print_bugs(@releases);
    update_file($release_out, $text, $time_text);
    $num_files++;
}
if (!$num_files) {
    die "No output files defined\n";
}