[system] / trunk / admintools / ww-make-docs-from-cvs Repository:
ViewVC logotype

View of /trunk/admintools/ww-make-docs-from-cvs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5550 - (download) (annotate)
Tue Oct 2 20:27:44 2007 UTC (12 years, 3 months ago) by sh002i
File size: 4633 byte(s)
remove each dest dir before regenerating docs

    1 #!/usr/bin/perl -sT
    2 ################################################################################
    3 # WeBWorK Online Homework Delivery System
    4 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
    5 # $CVSHeader: admintools/ww-make-docs-from-cvs,v 1.4 2007/10/02 20:11:00 sh002i Exp $
    6 # 
    7 # This program is free software; you can redistribute it and/or modify it under
    8 # the terms of either: (a) the GNU General Public License as published by the
    9 # Free Software Foundation; either version 2, or (at your option) any later
   10 # version, or (b) the "Artistic License" which comes with this package.
   11 # 
   12 # This program is distributed in the hope that it will be useful, but WITHOUT
   13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   14 # FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
   15 # Artistic License for more details.
   16 ################################################################################
   17 
   18 =head1 NAME
   19 
   20 ww-make-docs-from-cvs - make WeBWorK documentation from CVS viewable over the web
   21 
   22 =cut
   23 
   24 use strict;
   25 use warnings;
   26 use IO::File;
   27 
   28 $ENV{PATH} = "";
   29 $ENV{ENV} = "";
   30 
   31 our $CHECKOUT_DIR = '/webwork/docs2html';
   32 our $DOC_DIR = '/webwork/www/main/doc/cvs';
   33 #our $CHECKOUT_DIR = '/home/sam/work/admintools/checkoutdir';
   34 #our $DOC_DIR = '/home/sam/work/admintools/docdir';
   35 
   36 our $CVS = "/usr/bin/cvs";
   37 our $MKDIR = "/bin/mkdir";
   38 our $RM = "/bin/rm";
   39 our $WW_MAKE_DOCS = '/home/sh002i/work/admintools/ww-make-docs';
   40 #our $WW_MAKE_DOCS = '/home/sam/work/admintools/ww-make-docs';
   41 
   42 our $v; # for verbose switch
   43 
   44 my @dirs;
   45 my %index;
   46 
   47 if (@ARGV) {
   48 	@dirs = map "$CHECKOUT_DIR/$_", @ARGV;
   49 } else {
   50 	@dirs = glob("$CHECKOUT_DIR/*");
   51 }
   52 
   53 foreach my $dir (@dirs) {
   54 	next unless -d $dir;
   55 	if ($dir =~ m/^([^\!\$\^\&\*\(\)\~\[\]\|\{\}\'\"\;\<\>\?]+)$/) {
   56 		print "\n-----> $dir <-----\n\n" if $v;
   57 		update_cvs($1);
   58 		process_dir($1);
   59 		update_index($1);
   60 	} else {
   61 		warn "'$dir' insecure.\n";
   62 	}
   63 }
   64 
   65 my $fh = new IO::File("$DOC_DIR/index.html", 'w')
   66 	or die "failed to open '$DOC_DIR/index.html' for writing: $!\n";
   67 write_index($fh);
   68 
   69 sub update_cvs {
   70 	my ($dir) = @_;
   71 	
   72 	system "cd \"$dir\" && $CVS -q update -dP" and die "cvs failed: $!\n";
   73 }
   74 
   75 sub process_dir {
   76 	my ($source_dir) = @_;
   77 	my $dest_dir = $source_dir;
   78 	$dest_dir =~ s/^$CHECKOUT_DIR/$DOC_DIR/;
   79 	
   80 	system $RM, '-rf', $dest_dir;
   81 	system $MKDIR, '-p', $dest_dir;
   82 	if ($?) {
   83 		my $exit = $? >> 8;
   84 		my $signal = $? & 127;
   85 		my $core = $? & 128;
   86 		die "/bin/mkdir -p $dest_dir failed (exit=$exit signal=$signal core=$core)\n";
   87 	}
   88 	
   89 	system $WW_MAKE_DOCS, $source_dir, $dest_dir;
   90 	if ($?) {
   91 		my $exit = $? >> 8;
   92 		my $signal = $? & 127;
   93 		my $core = $? & 128;
   94 		die "$WW_MAKE_DOCS $source_dir $dest_dir failed (exit=$exit signal=$signal core=$core)\n";
   95 	}
   96 }
   97 
   98 sub update_index {
   99 	my $dir = shift;
  100 	$dir =~ s/^.*\///;
  101 	if ($dir =~ /^(.+)_(.+?)(?:--(.*))?$/) {
  102 		my ($module, $version, $extra) = ($1, $2, $3);
  103 		if ($version =~ /^rel-(\d+)-(\d+)(?:-(\d+))?$/) {
  104 			my ($major, $minor, $patch) = ($1, $2, $3);
  105 			if (defined $patch) {
  106 				$version = "$major.$minor.$patch";
  107 			} else {
  108 				$version = "$major.$minor.0";
  109 			}
  110 		} elsif ($version =~ /^rel-(\d+)-(\d)-(?:patches|dev)$/) {
  111 			my ($major, $minor) = ($1, $2);
  112 			$version = "$major.$minor.x (bugfixes)";
  113 		} elsif ($version eq "HEAD") {
  114 			$version = 'HEAD (development)';
  115 		} else {
  116 			warn "unfamiliar version string '$version' for dir '$dir' -- not adding to index.\n";
  117 			return;
  118 		}
  119 		$module =~ s/^pg$/PG/;
  120 		$module =~ s/^webwork2$/WeBWorK/;
  121 		if (defined $extra) {
  122 			$index{$module}{$version}{$extra} = $dir;
  123 		} else {
  124 			$index{$module}{$version} = $dir;
  125 		}
  126 	} else {
  127 		warn "unfamiliary dir format '$dir' -- not adding to index.\n";
  128 	}
  129 }
  130 
  131 sub write_index {
  132 	my $fh = shift;
  133 	print $fh "<html><head><title>WeBWorK Documentation from CVS</title></head><body>\n";
  134 	print $fh "<h1>WeBWorK Documentation from CVS</h1>\n";
  135 	print $fh "<ul>\n";
  136 	print $fh map { "<li><a href=\"#$_\">$_</a></li>\n" } sort keys %index;
  137 	print $fh "</ul>\n";
  138 	for my $module (sort keys %index) {
  139 		print $fh "<hr/>\n";
  140 		print $fh "<h2><a name=\"$module\">$module</a></h2>\n";
  141 		print $fh "<ul>\n";
  142 		for my $version (sort keys %{$index{$module}}) {
  143 			if (ref $index{$module}{$version}) {
  144 				print $fh "<li>$version<ul>\n";
  145 				for my $extra (sort keys %{$index{$module}{$version}}) {
  146 					print $fh "<li><a href=\"$index{$module}{$version}{$extra}\">$extra</a></li>\n";
  147 				}
  148 				print $fh "</ul></li>\n";
  149 			} else {
  150 				print $fh "<li><a href=\"$index{$module}{$version}\">$version</a></li>\n";
  151 			}
  152 		}
  153 		print $fh "</ul>\n";
  154 		print $fh "</body></html>\n";
  155 	}
  156 }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9