[LON-CAPA-cvs] cvs: CVSROOT / cvs2rss.pl

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 24 Oct 2005 21:53:20 -0000


albertel		Mon Oct 24 17:53:20 2005 EDT

  Modified files:              
    /CVSROOT	cvs2rss.pl 
  Log:
  - should hanlde the multiple file commit more correctly
  
  
Index: CVSROOT/cvs2rss.pl
diff -u CVSROOT/cvs2rss.pl:1.8 CVSROOT/cvs2rss.pl:1.9
--- CVSROOT/cvs2rss.pl:1.8	Mon Oct 24 17:38:14 2005
+++ CVSROOT/cvs2rss.pl	Mon Oct 24 17:53:20 2005
@@ -43,7 +43,14 @@
 $author = 'guy' . "\@" . 'albertelli.com';
 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]);
+# 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');
 
@@ -61,59 +68,68 @@
 	      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
-while (<STDIN>) {
-    chomp($_);
-    if ($_=~/^[A-Z].*:\s*$/) {
-	$_ = "<br /><b>" . &HTML::Entities::encode($_,'<>&"') . "</b><br />";
-    } else {
-	$_ = &HTML::Entities::encode($_,'<>&"');
-	$_ .= "<br />";
+foreach my $file (@args) {
+    my @title=split(",",$file);
+
+
+    # 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
+    while (<STDIN>) {
+	chomp($_);
+	if ($_=~/^[A-Z].*:\s*$/) {
+	    $_ = "<br /><b>" . &HTML::Entities::encode($_,'<>&"') . "</b><br />";
+	} else {
+	    $_ = &HTML::Entities::encode($_,'<>&"');
+	    $_ .= "<br />";
+	}
+	$description .= $_;
     }
-    $description .= $_;
-}
 
-if ($cvsDiff == 1) { 
+    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)$/)){
-	my $tmpFile = "/tmp/diff.$$";
-	my $cmdLine = "cvs -n rdiff -u -kk -r " . $title[1] .  " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile;
-	system($cmdLine);
-	
-	$description .= "<br /><b>Differences:</b><br /><pre>";
-	open CVSDIFF, "<" . $tmpFile;
-	foreach my $line (<CVSDIFF>) {
-	    $description .= &HTML::Entities::encode($line,'<>&"');
+	# 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)$/)){
+	    my $tmpFile = "/tmp/diff.$$";
+	    my $cmdLine = "cvs -n rdiff -u -kk -r " . $title[1] .  " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile;
+	    system($cmdLine);
+	    
+	    $description .= "<br /><b>Differences:</b><br /><pre>";
+	    open CVSDIFF, "<" . $tmpFile;
+	    foreach my $line (<CVSDIFF>) {
+		$description .= &HTML::Entities::encode($line,'<>&"');
+	    }
+	    $description .= "</pre>";
+	    unlink($tmpFile);   
 	}
-	$description .= "</pre>";
-	unlink($tmpFile);   
-    } 
-}
+    }
+
+    my $link = 'http://install.loncapa.org/cgi-bin/cvsweb.cgi/'.$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 => 'http://install.loncapa.org/cgi-bin/cvsweb.cgi/'.$title[0].'.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
+		   );		
 
-foreach my $element (@{$rss->{'items'}}) {
-    $element->{'description'} = &HTML::Entities::encode($element->{'description'},'<>&"'); 
+    foreach my $element (@{$rss->{'items'}}) {
+	$element->{'description'} = &HTML::Entities::encode($element->{'description'},'<>&"'); 
+    }
 }
 
 $rss->save($rssFeed);
@@ -121,3 +137,8 @@
 # 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 = <STDIN>;
+    exit @_;
+}