Annotation of CVSROOT/cvs2rss.pl, revision 1.12

1.1       albertel    1: #!/usr/bin/perl
                      2: # Kyle Christensen <kyle@junglist.org>
                      3: # http://junglist.org/files/scripts/cvs2rss.pl
                      4: # 
                      5: # This script (when setup properly) will magically create an RSS 2.0 compliant feed
                      6: # that logs your cvs commits as well as a diff of the changes made.
                      7: #
                      8: # Run this from your CVSROOT/loginfo like:
                      9: #
                     10: #	/path/to/cvs2rss.pl %{sVv}
                     11: #
                     12: # Also, make sure your apache server has an AddType for rss like:
                     13: #
                     14: # 	AddType application/rss+xml .rss
                     15: #
                     16: # P.S. The "other" cvs2rss.pl isn't really cvs2rss, it is more like cvs2xml, boo!
                     17: # P.P.S. Parts of this are stolen from commit2rss.rb and the XML::RSS examples.
                     18: #
                     19: # Version 1.0 - 08.24.04 RSS Compliant, no cvs diff capability yet..
                     20: # Version 1.1 - 08.31.04 Adding CVS Diff capability
1.2       albertel   21: # Edit by Guy Albertelli, -- corrected the packaging of Entities
                     22: #                          - commits now <pre>ed
                     23: #                          - removed html rants
1.1       albertel   24: #
                     25: 
                     26: use strict;
1.2       albertel   27: use HTML::Entities();
1.1       albertel   28: use XML::RSS;
                     29: use POSIX;
                     30: 
                     31: # Stuff you need to setup 
1.11      albertel   32: my $cvslink = 'http://install.loncapa.org/cgi-bin/cvsweb.cgi/';
1.1       albertel   33: my $rssFeed ="/home/loninst/public_html/loncapa.rss";
                     34: my $emailDomain = "loncapa.org";
                     35: my $channelTitle = "Lon-CAPA RSS Feed";
1.2       albertel   36: my $channelLink = "http://install.loncapa.org/loncapa.rss";
1.12    ! albertel   37: my $numEntries = 30;
1.1       albertel   38: 
1.2       albertel   39: # Set this to 1 to enable cvs rdiff
1.1       albertel   40: my $cvsDiff = 1;
                     41: 
                     42: # Leave everything else alone
1.11      albertel   43: my $author = getpwuid(getuid());
1.1       albertel   44: my $pubDate = strftime('%a, %d %b %Y %H:%M:%S %Z',localtime(time));
1.9       albertel   45: 
                     46: my @args = split(" ", $ARGV[0]);
1.11      albertel   47: my $dir = shift(@args);
                     48: 
1.9       albertel   49: # bail when this is a new directory
                     50: &bail if $args[0] eq '-' && "$args[1] $args[2]" eq 'New directory';
                     51: # bail if this is an import
                     52: &bail if $args[0] eq '-' && $args[1] eq 'Imported';
                     53: 
1.1       albertel   54: 
                     55: my $rss = new XML::RSS(version => '2.0');
1.4       albertel   56: 
                     57: # If rssFeed exists, parse it
                     58: if (-r "$rssFeed") {
1.8       albertel   59:     $rss->parsefile($rssFeed);
1.4       albertel   60: }
                     61: 
1.1       albertel   62: $rss->channel(
1.8       albertel   63: 	      title=> $channelTitle,
                     64: 	      link => $channelLink,
                     65: 	      language => 'en',
                     66: 	      description => $channelTitle,
                     67: 	      copyright => '(c) 2005 MSU Board of Trustees.',
                     68: 	      pubDate => $pubDate 
                     69: 	      );
1.1       albertel   70: 
                     71: # Limit entries in the feed to $numEntries
                     72: pop(@{$rss->{'items'}}) while (@{$rss->{'items'}} >= $numEntries);
                     73: 
1.10      albertel   74: my $commit_msg;
                     75: while (<STDIN>) {
                     76:     chomp($_);
                     77:     if ($_=~/^[A-Z].*:\s*$/) {
                     78: 	$_ = "<br /><b>" . &HTML::Entities::encode($_,'<>&"') . "</b><br />";
                     79:     } else {
                     80: 	$_ = &HTML::Entities::encode($_,'<>&"');
                     81: 	$_ .= "<br />";
                     82:     }
                     83:     $commit_msg .= $_;
                     84: }
                     85: 
1.11      albertel   86: $commit_msg .= '<br /><b>Author:</b><br />'.$author.'<br />';
                     87: 
1.9       albertel   88: foreach my $file (@args) {
                     89:     my @title=split(",",$file);
                     90: 
1.10      albertel   91:     my $description = $commit_msg;
1.9       albertel   92:     # Format title of the rss item
                     93:     # Remove space, append / and set title to /file/that/changed - oldversion/newversion
                     94:     $title[0] =~s/ /\//;
1.11      albertel   95:     $title[0] = $dir.'/'.$title[0];
                     96: 
1.9       albertel   97:     # Format the cvslog msg itself
1.1       albertel   98: 
1.9       albertel   99:     if ($cvsDiff == 1) { 
1.8       albertel  100: 
1.9       albertel  101: 	# If the old version of the file is not NONE (if
                    102: 	# it isn't a new file), and if it is a pm/pl/conf/tab file.
                    103: 	# This will rdiff it against the previous version, and
                    104: 	# include that diff in the rss feed
                    105: 
1.12    ! albertel  106: 	if (($title[1] != "NONE") 
        !           107: 	    && ($title[0]=~/(.*)\.(pm|pl|conf|tab)$/)
        !           108: 	    && ($title[0]!~|/localize/localize/..\.pm|) ) {
1.9       albertel  109: 	    my $tmpFile = "/tmp/diff.$$";
                    110: 	    my $cmdLine = "cvs -n rdiff -u -kk -r " . $title[1] .  " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile;
                    111: 	    system($cmdLine);
                    112: 	    
                    113: 	    $description .= "<br /><b>Differences:</b><br /><pre>";
                    114: 	    open CVSDIFF, "<" . $tmpFile;
                    115: 	    foreach my $line (<CVSDIFF>) {
                    116: 		$description .= &HTML::Entities::encode($line,'<>&"');
                    117: 	    }
                    118: 	    $description .= "</pre>";
                    119: 	    unlink($tmpFile);   
1.8       albertel  120: 	}
1.9       albertel  121:     }
                    122: 
1.11      albertel  123:     my $link = $cvslink.$title[0];
1.9       albertel  124:     if ($title[1] != "NONE") {
                    125:         $link .= '.diff?r1='.$title[1].';r2='.$title[2].';f=h';
                    126:     }
1.1       albertel  127: 
1.9       albertel  128:     $rss->add_item(
                    129: 		   title => "/" . $title[0] . " - " . $title[1] . "/" . $title[2],
                    130: 		   author => $author,
                    131: 		   description=> $description,
                    132: 		   mode => 'insert',
                    133: 		   pubDate => $pubDate,
                    134: 		   link => $link
                    135: 		   );		
1.11      albertel  136: }
1.1       albertel  137: 
1.11      albertel  138: foreach my $element (@{$rss->{'items'}}) {
                    139:     $element->{'description'} = 
                    140: 	&HTML::Entities::encode($element->{'description'},'<>&"');
1.1       albertel  141: }
                    142: 
                    143: $rss->save($rssFeed);
                    144: 
                    145: # Rsync this rss feed to another publically accessable machine.
                    146: #my $cmdLine="rsync -r -e ssh --delete /export/www/rss/html/ builder\@monkey:/export/www/rss/html/";
                    147: #system($cmdLine);
1.9       albertel  148: 
                    149: sub bail {
                    150:     my @toss = <STDIN>;
                    151:     exit @_;
                    152: }

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