removals.pl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #! /usr/bin/perl
  2. # removals - generate an RSS feed of removals from Debian
  3. # (C) Copyright 2005 Tollef Fog Heen <tfheen@err.no>
  4. # (C) Copyright 2010 Uli Martens <uli@youam.net>
  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. use strict;
  20. use warnings;
  21. use MIME::Base64 qw(encode_base64);
  22. use XML::RSS;
  23. use POSIX qw(strftime);
  24. use CGI qw/:standard/;
  25. die "usage: $0 <configfile>\n" unless scalar @ARGV;
  26. my $config;
  27. my $cfgfname = $ARGV[0];
  28. open my $cfgfile, "<", $cfgfname
  29. or die "config file $cfgfname not found: $!\n";
  30. while (<$cfgfile>){
  31. chomp;
  32. s/#.*//;
  33. next if m/^$/;
  34. my ($key, $val) = split ": ", $_, 2;
  35. warn "$0: warning: redefining config key $key\n" if defined $config->{$key};
  36. $config->{$key} = $val;
  37. }
  38. close $cfgfile;
  39. for ( qw/input items title link description subject creator publisher rights language/ ) {
  40. die "config option '$_' missing in $cfgfname\n" unless $config->{$_};
  41. }
  42. open REMOVALS, "<", $config->{input};
  43. my @removals;
  44. {
  45. local $/ = "=========================================================================\n=========================================================================";
  46. @removals = reverse <REMOVALS>;
  47. }
  48. my $rss = new XML::RSS (version => '1.0');
  49. $rss->channel(
  50. title => $config->{title},
  51. link => $config->{link},
  52. description => $config->{description},
  53. dc => {
  54. date => POSIX::strftime ("%FT%R+00:00",gmtime()),
  55. subject => $config->{subject},
  56. creator => $config->{creator},
  57. publisher => $config->{publisher},
  58. rights => $config->{rights},
  59. language => $config->{language},
  60. },
  61. syn => {
  62. updatePeriod => "hourly",
  63. updateFrequency => "1",
  64. updateBase => "1901-01-01T00:00+00:00",
  65. }
  66. );
  67. my $num_to_display = $config->{items};
  68. for my $removal (@removals ) {
  69. my ($null, $date, $ftpmaster, $body, $packages, $reason);
  70. $removal =~ s/=========================================================================//g;
  71. $removal =~ m/\[Date: ([^]]+)\] \[ftpmaster: ([^]]+)\]/;
  72. $date = $1;
  73. $ftpmaster = $2;
  74. ($null, $body) = split /\n/, $removal, 2;
  75. chomp $body;
  76. $body =~ m/---- Reason ---.*\n(.*)/;
  77. $reason = $1;
  78. $packages = join( ", ",
  79. map { ( my $p = $_ ) =~ s/^\s*(.+?) \|.+/$1/; $p }
  80. grep {/.+\|.+\|.+/} split( /\n/, $body ) );
  81. $packages
  82. = ( substr $packages, 0,
  83. ( $config->{titlelength} - length($reason) - 6 ) )
  84. . " ..."
  85. if length("$packages: $reason") > $config->{titlelength};
  86. my $link = encode_base64($date . $ftpmaster);
  87. chomp($link);
  88. $rss->add_item(title => "$packages: $reason",
  89. link => $config->{link} . "?" . $link,
  90. description => qq[<pre>$body</pre>],
  91. dc => {
  92. creator => "$ftpmaster",
  93. }
  94. );
  95. $num_to_display -= 1;
  96. last unless $num_to_display;
  97. }
  98. print $rss->as_string;