Diff for /CVSROOT/cvs2rss.pl between versions 1.1 and 1.7

version 1.1, 2005/10/11 19:45:18 version 1.7, 2005/10/17 19:50:57
Line 13 Line 13
 #  #
 # AddType application/rss+xml .rss  # AddType application/rss+xml .rss
 #  #
 # Important note:   
 # If you have html files (or files with html in them) in your CVS Repository, look in your RSS.pm for:  
 #  
 # $text =~ s/</&lt;/g;  
 #  
 # I suggest commenting out this line because it will screw up this script (I think its a bug in the parser)  
 # If you do not, when this script uses XML:RSS's parsefile(), it will mess up any <descriptions> that   
 # contain HTML.  
 #  
 # P.S. The "other" cvs2rss.pl isn't really cvs2rss, it is more like cvs2xml, boo!  # P.S. The "other" cvs2rss.pl isn't really cvs2rss, it is more like cvs2xml, boo!
 # P.P.S. Parts of this are stolen from commit2rss.rb and the XML::RSS examples.  # P.P.S. Parts of this are stolen from commit2rss.rb and the XML::RSS examples.
 #  #
 # Version 1.0 - 08.24.04 RSS Compliant, no cvs diff capability yet..  # Version 1.0 - 08.24.04 RSS Compliant, no cvs diff capability yet..
 # Version 1.1 - 08.31.04 Adding CVS Diff capability  # Version 1.1 - 08.31.04 Adding CVS Diff capability
   # Edit by Guy Albertelli, -- corrected the packaging of Entities
   #                          - commits now <pre>ed
   #                          - removed html rants
 #  #
   
 use strict;  use strict;
   use HTML::Entities();
 use XML::RSS;  use XML::RSS;
 use POSIX;  use POSIX;
   
Line 37  use POSIX; Line 32  use POSIX;
 my $rssFeed ="/home/loninst/public_html/loncapa.rss";  my $rssFeed ="/home/loninst/public_html/loncapa.rss";
 my $emailDomain = "loncapa.org";  my $emailDomain = "loncapa.org";
 my $channelTitle = "Lon-CAPA RSS Feed";  my $channelTitle = "Lon-CAPA RSS Feed";
 my $channelLink = "http://install.loncapa.org/cvs.rss";  my $channelLink = "http://install.loncapa.org/loncapa.rss";
 my $numEntries = 200;  my $numEntries = 200;
   
 # Set this to 1 to enable cvs rdiff (is pretty broken if you are diffing html content)  # Set this to 1 to enable cvs rdiff
 my $cvsDiff = 1;  my $cvsDiff = 1;
   
 # Leave everything else alone  # Leave everything else alone
Line 51  my $description; Line 46  my $description;
 my @title=split(",",$ARGV[0]);  my @title=split(",",$ARGV[0]);
   
 my $rss = new XML::RSS(version => '2.0');  my $rss = new XML::RSS(version => '2.0');
   
   # If rssFeed exists, parse it
   if (-r "$rssFeed") {
    $rss->parsefile($rssFeed);
   }
   
 $rss->channel(  $rss->channel(
  title=> $channelTitle,   title=> $channelTitle,
  link => $channelLink,   link => $channelLink,
  language => 'en',   language => 'en',
  description => $channelTitle,   description => $channelTitle,
  copyright => '(c) 2005 MSU Board of Trustees.'   copyright => '(c) 2005 MSU Board of Trustees.',
    pubDate => $pubDate 
 );  );
   
 # If rssFeed exists, parse it  
 if (-r "$rssFeed") {  
  $rss->parsefile($rssFeed);  
 }  
   
 # Limit entries in the feed to $numEntries  # Limit entries in the feed to $numEntries
 pop(@{$rss->{'items'}}) while (@{$rss->{'items'}} >= $numEntries);  pop(@{$rss->{'items'}}) while (@{$rss->{'items'}} >= $numEntries);
Line 75  $title[0] =~s/ /\//; Line 73  $title[0] =~s/ /\//;
 while (<STDIN>) {  while (<STDIN>) {
  chomp($_);   chomp($_);
  if ($_=~/^[A-Z].*:\s*$/) {   if ($_=~/^[A-Z].*:\s*$/) {
  $_ = "<br /><b>" . $_ . "</b><br />";   $_ = "<br /><b>" . &HTML::Entities::encode($_,'<>&"') . "</b><br />";
  }   }
  else {   else {
    $_ = &HTML::Entities::encode($_,'<>&"');
  $_ .= "<br />";   $_ .= "<br />";
  }   }
  $description .= $_;   $description .= $_;
Line 87  if ($cvsDiff == 1) { Line 86  if ($cvsDiff == 1) {
  # If the old version of the file is not NONE (if it isn't a new file), and if it is a .txt or .java file (that has no html)   # If the old version of the file is not NONE (if it isn't a new file), and if it is a .txt or .java file (that has no html)
  # This will rdiff it against the previous version, and include that diff in the rss feed   # This will rdiff it against the previous version, and include that diff in the rss feed
   
  if (($title[1] != "NONE") && ($title[0]=~/(.*).(txt|java)$/)){   if (($title[1] != "NONE") && ($title[0]=~/(.*).(pm)$/)){
  my $tmpFile = "/tmp/diff.$$";   my $tmpFile = "/tmp/diff.$$";
  my $cmdLine = "cvs -n rdiff -kk -r " . $title[1] .  " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile;   my $cmdLine = "cvs -n rdiff -u -kk -r " . $title[1] .  " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile;
  system($cmdLine);   system($cmdLine);
   
  $description .= "<br /><b>Differences:</b><br />";   $description .= "<br /><b>Differences:</b><br /><pre>";
  open CVSDIFF, "<" . $tmpFile;   open CVSDIFF, "<" . $tmpFile;
  foreach my $line (<CVSDIFF>) {   foreach my $line (<CVSDIFF>) {
  chomp($line);   $description .= &HTML::Entities::encode($line,'<>&"');
  $description .= $line . "<br />";  
  }   }
    $description .= "</pre>";
  unlink($tmpFile);      unlink($tmpFile);   
  }    } 
 }  }
Line 105  if ($cvsDiff == 1) { Line 104  if ($cvsDiff == 1) {
 $rss->add_item(  $rss->add_item(
  title => "/" . $title[0] . " - " . $title[1] . "/" . $title[2],   title => "/" . $title[0] . " - " . $title[1] . "/" . $title[2],
  author => $author,   author => $author,
  pubDate => $pubDate,   
  description=> $description,   description=> $description,
  mode => 'insert'   mode => 'insert',
    pubDate => $pubDate,
    link => 'http://install.loncapa.org/cgi-bin/cvsweb.cgi/'.$title[0].'.diff?r1='.$title[1].';r2='.$title[2].';f=h'
 );  );
   
 # XML::RSS doesn't like HTML in the XML so Escape the description body with <![CDATA[ ]]>  
 # This is messy and stupid, but both XML::RSS and XML are sort of dumb, and I can't figure out a way around it.  
 # Certain RSS readers will try and render the HTML regardless of if it is wrapped in a CDATA tag or not so um, deal.  
 foreach my $element (@{$rss->{'items'}}) {  foreach my $element (@{$rss->{'items'}}) {
  $element->{'description'} = "<![CDATA[" . $element->{'description'} . "]]>";   $element->{'description'} = &HTML::Entities::encode($element->{'description'},'<>&"'); 
 }  }
   
 $rss->save($rssFeed);  $rss->save($rssFeed);

Removed from v.1.1  
changed lines
  Added in v.1.7


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>