Annotation of CVSROOT/cvs2rss.pl, revision 1.9

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 
                     32: my $rssFeed ="/home/loninst/public_html/loncapa.rss";
                     33: my $emailDomain = "loncapa.org";
                     34: my $channelTitle = "Lon-CAPA RSS Feed";
1.2       albertel   35: my $channelLink = "http://install.loncapa.org/loncapa.rss";
1.1       albertel   36: my $numEntries = 200;
                     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
                     42: my $author = getpwuid(getuid()) . "\@" . $emailDomain;
                     43: $author = 'guy' . "\@" . 'albertelli.com';
                     44: my $pubDate = strftime('%a, %d %b %Y %H:%M:%S %Z',localtime(time));
                     45: my $description;
1.9     ! albertel   46: 
        !            47: 
        !            48: my @args = split(" ", $ARGV[0]);
        !            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.9     ! albertel   74: foreach my $file (@args) {
        !            75:     my @title=split(",",$file);
        !            76: 
        !            77: 
        !            78:     # Format title of the rss item
        !            79:     # Remove space, append / and set title to /file/that/changed - oldversion/newversion
        !            80:     $title[0] =~s/ /\//;
        !            81:     
        !            82:     # Format the cvslog msg itself
        !            83:     while (<STDIN>) {
        !            84: 	chomp($_);
        !            85: 	if ($_=~/^[A-Z].*:\s*$/) {
        !            86: 	    $_ = "<br /><b>" . &HTML::Entities::encode($_,'<>&"') . "</b><br />";
        !            87: 	} else {
        !            88: 	    $_ = &HTML::Entities::encode($_,'<>&"');
        !            89: 	    $_ .= "<br />";
        !            90: 	}
        !            91: 	$description .= $_;
1.8       albertel   92:     }
1.1       albertel   93: 
1.9     ! albertel   94:     if ($cvsDiff == 1) { 
1.8       albertel   95: 
1.9     ! albertel   96: 	# If the old version of the file is not NONE (if
        !            97: 	# it isn't a new file), and if it is a pm/pl/conf/tab file.
        !            98: 	# This will rdiff it against the previous version, and
        !            99: 	# include that diff in the rss feed
        !           100: 
        !           101: 	if (($title[1] != "NONE") && ($title[0]=~/(.*).(pm|pl|conf|tab)$/)){
        !           102: 	    my $tmpFile = "/tmp/diff.$$";
        !           103: 	    my $cmdLine = "cvs -n rdiff -u -kk -r " . $title[1] .  " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile;
        !           104: 	    system($cmdLine);
        !           105: 	    
        !           106: 	    $description .= "<br /><b>Differences:</b><br /><pre>";
        !           107: 	    open CVSDIFF, "<" . $tmpFile;
        !           108: 	    foreach my $line (<CVSDIFF>) {
        !           109: 		$description .= &HTML::Entities::encode($line,'<>&"');
        !           110: 	    }
        !           111: 	    $description .= "</pre>";
        !           112: 	    unlink($tmpFile);   
1.8       albertel  113: 	}
1.9     ! albertel  114:     }
        !           115: 
        !           116:     my $link = 'http://install.loncapa.org/cgi-bin/cvsweb.cgi/'.$title[0];
        !           117:     if ($title[1] != "NONE") {
        !           118:         $link .= '.diff?r1='.$title[1].';r2='.$title[2].';f=h';
        !           119:     }
1.1       albertel  120: 
1.9     ! albertel  121:     $rss->add_item(
        !           122: 		   title => "/" . $title[0] . " - " . $title[1] . "/" . $title[2],
        !           123: 		   author => $author,
        !           124: 		   description=> $description,
        !           125: 		   mode => 'insert',
        !           126: 		   pubDate => $pubDate,
        !           127: 		   link => $link
        !           128: 		   );		
1.1       albertel  129: 
1.9     ! albertel  130:     foreach my $element (@{$rss->{'items'}}) {
        !           131: 	$element->{'description'} = &HTML::Entities::encode($element->{'description'},'<>&"'); 
        !           132:     }
1.1       albertel  133: }
                    134: 
                    135: $rss->save($rssFeed);
                    136: 
                    137: # Rsync this rss feed to another publically accessable machine.
                    138: #my $cmdLine="rsync -r -e ssh --delete /export/www/rss/html/ builder\@monkey:/export/www/rss/html/";
                    139: #system($cmdLine);
1.9     ! albertel  140: 
        !           141: sub bail {
        !           142:     my @toss = <STDIN>;
        !           143:     exit @_;
        !           144: }

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