Annotation of CVSROOT/cvs2rss.pl, revision 1.11

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.1       albertel   37: my $numEntries = 200;
                     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: 
                    106: 	if (($title[1] != "NONE") && ($title[0]=~/(.*).(pm|pl|conf|tab)$/)){
                    107: 	    my $tmpFile = "/tmp/diff.$$";
                    108: 	    my $cmdLine = "cvs -n rdiff -u -kk -r " . $title[1] .  " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile;
                    109: 	    system($cmdLine);
                    110: 	    
                    111: 	    $description .= "<br /><b>Differences:</b><br /><pre>";
                    112: 	    open CVSDIFF, "<" . $tmpFile;
                    113: 	    foreach my $line (<CVSDIFF>) {
                    114: 		$description .= &HTML::Entities::encode($line,'<>&"');
                    115: 	    }
                    116: 	    $description .= "</pre>";
                    117: 	    unlink($tmpFile);   
1.8       albertel  118: 	}
1.9       albertel  119:     }
                    120: 
1.11    ! albertel  121:     my $link = $cvslink.$title[0];
1.9       albertel  122:     if ($title[1] != "NONE") {
                    123:         $link .= '.diff?r1='.$title[1].';r2='.$title[2].';f=h';
                    124:     }
1.1       albertel  125: 
1.9       albertel  126:     $rss->add_item(
                    127: 		   title => "/" . $title[0] . " - " . $title[1] . "/" . $title[2],
                    128: 		   author => $author,
                    129: 		   description=> $description,
                    130: 		   mode => 'insert',
                    131: 		   pubDate => $pubDate,
                    132: 		   link => $link
                    133: 		   );		
1.11    ! albertel  134: }
1.1       albertel  135: 
1.11    ! albertel  136: foreach my $element (@{$rss->{'items'}}) {
        !           137:     $element->{'description'} = 
        !           138: 	&HTML::Entities::encode($element->{'description'},'<>&"');
1.1       albertel  139: }
                    140: 
                    141: $rss->save($rssFeed);
                    142: 
                    143: # Rsync this rss feed to another publically accessable machine.
                    144: #my $cmdLine="rsync -r -e ssh --delete /export/www/rss/html/ builder\@monkey:/export/www/rss/html/";
                    145: #system($cmdLine);
1.9       albertel  146: 
                    147: sub bail {
                    148:     my @toss = <STDIN>;
                    149:     exit @_;
                    150: }

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