]> git.decadent.org.uk Git - dak.git/blob - tools/removals.pl
move removals.pl magic constants into config file
[dak.git] / tools / removals.pl
1 #! /usr/bin/perl
2
3 #    removals - generate an RSS feed of removals from Debian
4 #    (C) Copyright 2005 Tollef Fog Heen <tfheen@err.no>
5 #
6 #    This program is free software; you can redistribute it and/or
7 #    modify it under the terms of the GNU General Public License
8 #    version 2 as published by the Free Software Foundation.
9 #
10 #    This program is distributed in the hope that it will be useful,
11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #    General Public License for more details.
14 #
15 #    You should have received a copy of the GNU General Public License
16 #    along with this program; if not, write to the Free Software
17 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 #    02111-1307 USA
19
20
21 use strict;
22 use warnings;
23
24 use MIME::Base64 qw(encode_base64);
25 use XML::RSS;
26 use POSIX qw(strftime);
27 use CGI qw/:standard/;
28
29 die "usage: $0 <configfile>\n" unless scalar @ARGV;
30
31 my $config;
32
33 my $cfgfname = $ARGV[0];
34 open my $cfgfile, "<", $cfgfname
35         or die "config file $cfgfname not found: $!\n";
36 while (<$cfgfile>){
37         chomp;
38         s/#.*//;
39         next if m/^$/;
40         my ($key, $val) = split ": ", $_, 2;
41         warn "$0: warning: redefining config key $key\n" if defined $config->{$key};
42         $config->{$key} = $val;
43 }
44 close $cfgfile;
45
46 for ( qw/input items title link description subject creator publisher rights language/ ) {
47         die "config option '$_' missing in $cfgfname\n" unless $config->{$_};
48 }
49 open REMOVALS, "<", $config->{input};
50
51 my @removals;
52
53 {
54   local $/ = "=========================================================================\n=========================================================================";
55   @removals = reverse <REMOVALS>;
56 }
57
58 my $rss = new XML::RSS (version => '1.0');
59 $rss->channel(
60                           title        => $config->{title},
61                           link         => $config->{link},
62                           description  => $config->{description},
63                           dc => {
64                                          date       => POSIX::strftime ("%FT%R+00:00",gmtime()),
65                                          subject    => $config->{subject},
66                                          creator    => $config->{creator},
67                                          publisher  => $config->{publisher},
68                                          rights     => $config->{rights},
69                                          language   => $config->{language},
70                                         },
71                           syn => {
72                                           updatePeriod     => "hourly",
73                                           updateFrequency  => "1",
74                                           updateBase       => "1901-01-01T00:00+00:00",
75                                          }
76                          );
77
78 my $num_to_display = $config->{items};
79 for my $removal (@removals ) {
80   my ($null, $date, $ftpmaster, $body, $reason);
81   $removal =~ s/=========================================================================//g;
82   $removal =~ m/\[Date: ([^]]+)\] \[ftpmaster: ([^]]+)\]/;
83   $date = $1;
84   $ftpmaster = $2;
85   ($null, $body) = split /\n/, $removal, 2;
86   chomp $body;
87   $body =~ m/---- Reason ---.*\n(.*)/;
88   $reason = $1;
89   my $link =  encode_base64($date . $ftpmaster);
90   chomp($link);
91
92   $rss->add_item(title       => "$reason",
93                                  link        => $config->{link} . "?" . $link,
94                                  description => qq[<pre>$body</pre>],
95                                  dc => {
96                                                 creator => "$ftpmaster",
97                                            }
98                                 );
99
100   $num_to_display -= 1;
101   last unless $num_to_display;
102 }
103 print $rss->as_string;