[Bio] / KBaseTutorials / add_links_to_tutorials.pl Repository:
ViewVC logotype

View of /KBaseTutorials/add_links_to_tutorials.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (download) (as text) (annotate)
Wed Jun 13 21:09:01 2012 UTC (7 years, 4 months ago) by olson
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +16 -11 lines
Update of the tutorial publication stuff.

use strict;
use Data::Dumper;
use Getopt::Long;

my $linkmap;
my $in_pre_only;
my $skip_commands;
my $rc = GetOptions("linkmap=s" => \$linkmap,
		    "inpre"     => \$in_pre_only,
		    "skip-commands" => \$skip_commands);

($rc && @ARGV == 4) or die "Usage: $0 cdmi-target cdmi-entity-target idserver-target spec-dir\n";

my $cdmi_url = shift;
my $cdmi_entity_url = shift;
my $idserver_url = shift;
my $spec_dir = shift;

#my $cdmi_url = "http://bio-admin-2.mcs.anl.gov/ksite/index.php/developers/api-documentation/cdmi-test/#";
#my $cdmi_url = "http://www.mcs.anl.gov/~olson/cdmi.html#";
#my $cdmi_entity_url = "http://www.mcs.anl.gov/~olson/ksapling.html#";
#my $idserver_url = "http://www.mcs.anl.gov/~olson/idserver.html#";

my @links;
if (open(L, "<", $linkmap))
{
    while (<L>)
    {
	chomp;
	my($old, $new) = split(/\t/);
	push(@links, [$old, $new]);
    }
    close(L);
}

my %links;   

if (!$skip_commands)
{
    my @cdmi = `grep funcdef $spec_dir/CDMI-API.spec`;
    my @cdmi_entity = `grep funcdef $spec_dir/CDMI-EntityAPI.spec`;
    my @idserver  = `grep funcdef $spec_dir/IDServer-API.spec`;
    
    foreach my $line (@cdmi) {
	$line =~ /funcdef\s+(\S+?)\(/;
	my $l = $1;
	$links{$1} = "<a href=\"$cdmi_url$1\" target='_blank'>$l</a>";
    }
    foreach my $line (@cdmi_entity) {
	$line =~ /funcdef\s+(\S+?)\(/;
	my $l = $1;
	$links{$1} = "<a href=\"$cdmi_entity_url$l\" target='_blank'>$1</a>";
    }
    foreach my $line (@idserver) {
	$line =~ /funcdef\s+(\S+?)\(/;
	my $l = $1;
	$links{$1} = "<a href=\"$idserver_url$l\" target='_blank'>$1</a>";
    }
}

my $x = join("", <STDIN>);

foreach my $cmd (keys(%links)) {
    if ($in_pre_only)
    {
	$x =~ s/(<pre>\s*)\b$cmd\b/$1$links{$cmd}/g;
    }
    else
    {
	$x =~ s/\b$cmd\b/$links{$cmd}/g;
    }
}

for my $lent (@links)
{
    my($old, $new) = @$lent;
    $x =~ s/href="$old(#.*)?"/href="$new$1"/g;
}

print $x;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3