Annotation of CVSROOT/cvs2rss.pl, revision 1.13

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.13    ! raeburn    24: # Edit by Stuart Raeburn, -- eliminated earlier HTML::Entities customization.
1.1       albertel   25: 
                     26: use strict;
                     27: use XML::RSS;
                     28: use POSIX;
                     29: 
                     30: # Stuff you need to setup 
1.13    ! raeburn    31: my $cvslink = 'http://source.loncapa.org/cgi-bin/cvsweb.cgi/';
        !            32: my $rssFeed ="/home/rss/cvs.rss";
1.1       albertel   33: my $emailDomain = "loncapa.org";
                     34: my $channelTitle = "Lon-CAPA RSS Feed";
1.13    ! raeburn    35: my $channelLink = "http://source.loncapa.org/rss/cvs.rss";
1.12      albertel   36: my $numEntries = 30;
1.1       albertel   37: 
1.2       albertel   38: # Set this to 1 to enable cvs rdiff
1.1       albertel   39: my $cvsDiff = 1;
                     40: 
                     41: # Leave everything else alone
1.11      albertel   42: my $author = getpwuid(getuid());
1.1       albertel   43: my $pubDate = strftime('%a, %d %b %Y %H:%M:%S %Z',localtime(time));
1.9       albertel   44: 
                     45: my @args = split(" ", $ARGV[0]);
1.11      albertel   46: my $dir = shift(@args);
                     47: 
1.9       albertel   48: # bail when this is a new directory
                     49: &bail if $args[0] eq '-' && "$args[1] $args[2]" eq 'New directory';
                     50: # bail if this is an import
                     51: &bail if $args[0] eq '-' && $args[1] eq 'Imported';
                     52: 
1.1       albertel   53: 
                     54: my $rss = new XML::RSS(version => '2.0');
1.4       albertel   55: 
                     56: # If rssFeed exists, parse it
                     57: if (-r "$rssFeed") {
1.8       albertel   58:     $rss->parsefile($rssFeed);
1.4       albertel   59: }
                     60: 
1.1       albertel   61: $rss->channel(
1.8       albertel   62: 	      title=> $channelTitle,
                     63: 	      link => $channelLink,
                     64: 	      language => 'en',
                     65: 	      description => $channelTitle,
                     66: 	      copyright => '(c) 2005 MSU Board of Trustees.',
                     67: 	      pubDate => $pubDate 
                     68: 	      );
1.1       albertel   69: 
                     70: # Limit entries in the feed to $numEntries
                     71: pop(@{$rss->{'items'}}) while (@{$rss->{'items'}} >= $numEntries);
                     72: 
1.10      albertel   73: my $commit_msg;
                     74: while (<STDIN>) {
                     75:     chomp($_);
                     76:     if ($_=~/^[A-Z].*:\s*$/) {
1.13    ! raeburn    77: 	$_ = "<br /><b>" .$_."</b><br />";
1.10      albertel   78:     } else {
                     79: 	$_ .= "<br />";
                     80:     }
                     81:     $commit_msg .= $_;
                     82: }
                     83: 
1.11      albertel   84: $commit_msg .= '<br /><b>Author:</b><br />'.$author.'<br />';
                     85: 
1.9       albertel   86: foreach my $file (@args) {
                     87:     my @title=split(",",$file);
                     88: 
1.10      albertel   89:     my $description = $commit_msg;
1.9       albertel   90:     # Format title of the rss item
                     91:     # Remove space, append / and set title to /file/that/changed - oldversion/newversion
                     92:     $title[0] =~s/ /\//;
1.11      albertel   93:     $title[0] = $dir.'/'.$title[0];
                     94: 
1.9       albertel   95:     # Format the cvslog msg itself
1.1       albertel   96: 
1.9       albertel   97:     if ($cvsDiff == 1) { 
1.8       albertel   98: 
1.9       albertel   99: 	# If the old version of the file is not NONE (if
                    100: 	# it isn't a new file), and if it is a pm/pl/conf/tab file.
                    101: 	# This will rdiff it against the previous version, and
                    102: 	# include that diff in the rss feed
                    103: 
1.12      albertel  104: 	if (($title[1] != "NONE") 
                    105: 	    && ($title[0]=~/(.*)\.(pm|pl|conf|tab)$/)
1.13    ! raeburn   106: 	    && ($title[0]!~{/localize/localize/..\.pm}) ) {
1.9       albertel  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>) {
1.13    ! raeburn   114: 		$description .= $line;
1.9       albertel  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: 
                    136: $rss->save($rssFeed);
                    137: 
                    138: # Rsync this rss feed to another publically accessable machine.
                    139: #my $cmdLine="rsync -r -e ssh --delete /export/www/rss/html/ builder\@monkey:/export/www/rss/html/";
                    140: #system($cmdLine);
1.9       albertel  141: 
                    142: sub bail {
                    143:     my @toss = <STDIN>;
                    144:     exit @_;
                    145: }

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