--- CVSROOT/cvs2rss.pl 2005/10/12 16:50:42 1.3 +++ CVSROOT/cvs2rss.pl 2008/11/26 18:43:30 1.13 @@ -21,92 +21,116 @@ # Edit by Guy Albertelli, -- corrected the packaging of Entities # - commits now
ed # - removed html rants -# +# Edit by Stuart Raeburn, -- eliminated earlier HTML::Entities customization. use strict; -use HTML::Entities(); use XML::RSS; use POSIX; # Stuff you need to setup -my $rssFeed ="/home/loninst/public_html/loncapa.rss"; +my $cvslink = 'http://source.loncapa.org/cgi-bin/cvsweb.cgi/'; +my $rssFeed ="/home/rss/cvs.rss"; my $emailDomain = "loncapa.org"; my $channelTitle = "Lon-CAPA RSS Feed"; -my $channelLink = "http://install.loncapa.org/loncapa.rss"; -my $numEntries = 200; +my $channelLink = "http://source.loncapa.org/rss/cvs.rss"; +my $numEntries = 30; # Set this to 1 to enable cvs rdiff my $cvsDiff = 1; # Leave everything else alone -my $author = getpwuid(getuid()) . "\@" . $emailDomain; -$author = 'guy' . "\@" . 'albertelli.com'; +my $author = getpwuid(getuid()); my $pubDate = strftime('%a, %d %b %Y %H:%M:%S %Z',localtime(time)); -my $description; -my @title=split(",",$ARGV[0]); + +my @args = split(" ", $ARGV[0]); +my $dir = shift(@args); + +# bail when this is a new directory +&bail if $args[0] eq '-' && "$args[1] $args[2]" eq 'New directory'; +# bail if this is an import +&bail if $args[0] eq '-' && $args[1] eq 'Imported'; + my $rss = new XML::RSS(version => '2.0'); -$rss->channel( - title=> $channelTitle, - link => $channelLink, - language => 'en', - description => $channelTitle, - copyright => '(c) 2005 MSU Board of Trustees.' -); # If rssFeed exists, parse it if (-r "$rssFeed") { - $rss->parsefile($rssFeed); + $rss->parsefile($rssFeed); } +$rss->channel( + title=> $channelTitle, + link => $channelLink, + language => 'en', + description => $channelTitle, + copyright => '(c) 2005 MSU Board of Trustees.', + pubDate => $pubDate + ); + # Limit entries in the feed to $numEntries pop(@{$rss->{'items'}}) while (@{$rss->{'items'}} >= $numEntries); -# Format title of the rss item -# Remove space, append / and set title to /file/that/changed - oldversion/newversion -$title[0] =~s/ /\//; - -# Format the cvslog msg itself +my $commit_msg; while () { - chomp($_); - if ($_=~/^[A-Z].*:\s*$/) { - $_ = "
" . $_ . "
"; - } - else { - $_ .= "
"; - } - $description .= $_; + chomp($_); + if ($_=~/^[A-Z].*:\s*$/) { + $_ = "
" .$_."
"; + } else { + $_ .= "
"; + } + $commit_msg .= $_; } -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) - # This will rdiff it against the previous version, and include that diff in the rss feed - - if (($title[1] != "NONE") && ($title[0]=~/(.*).(pm)$/)){ - my $tmpFile = "/tmp/diff.$$"; - my $cmdLine = "cvs -n rdiff -u -kk -r " . $title[1] . " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile; - system($cmdLine); - - $description .= "
Differences:"; - open CVSDIFF, "<" . $tmpFile; - foreach my $line ("; - unlink($tmpFile); - } -} +$commit_msg .= ') { - $description .= &HTML::Entities::encode($line,'<>&"'); - } - $description .= "
Author:
'.$author.'
'; -$rss->add_item( - title => "/" . $title[0] . " - " . $title[1] . "/" . $title[2], - author => $author, - pubDate => $pubDate, - description=> $description, - mode => 'insert' -); +foreach my $file (@args) { + my @title=split(",",$file); -foreach my $element (@{$rss->{'items'}}) { - $element->{'description'} = &HTML::Entities::encode($element->{'description'},'<>&"'); + my $description = $commit_msg; + # Format title of the rss item + # Remove space, append / and set title to /file/that/changed - oldversion/newversion + $title[0] =~s/ /\//; + $title[0] = $dir.'/'.$title[0]; + + # Format the cvslog msg itself + + 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 pm/pl/conf/tab file. + # This will rdiff it against the previous version, and + # include that diff in the rss feed + + if (($title[1] != "NONE") + && ($title[0]=~/(.*)\.(pm|pl|conf|tab)$/) + && ($title[0]!~{/localize/localize/..\.pm}) ) { + my $tmpFile = "/tmp/diff.$$"; + my $cmdLine = "cvs -n rdiff -u -kk -r " . $title[1] . " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile; + system($cmdLine); + + $description .= "
Differences:"; + open CVSDIFF, "<" . $tmpFile; + foreach my $line ("; + unlink($tmpFile); + } + } + + my $link = $cvslink.$title[0]; + if ($title[1] != "NONE") { + $link .= '.diff?r1='.$title[1].';r2='.$title[2].';f=h'; + } + + $rss->add_item( + title => "/" . $title[0] . " - " . $title[1] . "/" . $title[2], + author => $author, + description=> $description, + mode => 'insert', + pubDate => $pubDate, + link => $link + ); } $rss->save($rssFeed); @@ -114,3 +138,8 @@ $rss->save($rssFeed); # Rsync this rss feed to another publically accessable machine. #my $cmdLine="rsync -r -e ssh --delete /export/www/rss/html/ builder\@monkey:/export/www/rss/html/"; #system($cmdLine); + +sub bail { + my @toss =) { + $description .= $line; + } + $description .= " ; + exit @_; +}