VisIt 2.0 changes for host profiles

From VisItusers.org

Jump to: navigation, search

The following perl script will take a pre-2.0 config file and extract the host profiles, converting to the new machine/launch profile format, including extracting "-dir" from the engine arguments for the new "directory" field, and tracking the default profile correctly.

Note that it expects a valid host nickname, as this is what it uses for the file name for the machine profiles. The main output file will be the old config file with the host profiles removed.

#! /usr/bin/env perl
 
$in = shift @ARGV;
$out = shift @ARGV;
 
if (! defined($in) or ! defined($out) or ! -e $in)
{
    die "Usage: $0 <in> <out>\n\n";
}
 
open(IN, "<$in");
open(OUT, ">$out");
 
# get the line ending
$header = <IN>;
print OUT $header;
$eol = $header;
$eol =~ s/.*\>(.*)/$1/;
 
# Parse modes:
#   0 = before host profile list
#   1 = in host profile list
#   2 = in host profile
#   3 = after host profile list
$firstmachine = 1;
$parsemode = 0;
$ctr = 0;
while (<IN>)
{
    if ($parsemode    == 0 and m|<Object name="HostProfileList"|)
    {
        $parsemode = 1;
        $launchcount = 0;
        %lastmachinehash = ();
        $activeindex = 0;
        #print OUT $_;
    }
    elsif ($parsemode == 1 and m|<Object name="HostProfile"|)
    {
        $parsemode = 2;
        $activelaunch = 0;
        $curlaunch = ();
    }
    elsif ($parsemode == 1 and m|</Object>|)
    {
        # Ending host profile list
        $parsemode = 3;
        if (not $firstmachine)
        {
            print HPOUT "    <Field name=\"activeProfile\" type=\"int\">$activeindex</Field>$eol";
            print HPOUT "</Object>$eol";
        }
        #print OUT $_;
        close(HPOUT);
    }
    elsif ($parsemode == 2 and m|</Object>|)
    {
        # Ending a host profile
        $parsemode = 1;
 
        $samehost = 1;
        foreach $m (@curmachine)
        {
            $key  = $m;  $key  =~ s/.*<Field name="([^"]*)"\s+type=.*>.*<\/Field>.*$/$1/;
            $val  = $m;  $val  =~ s/.*<Field name="[^"]*"\s+type=.*>(.*)<\/Field>.*$/$1/;
            chomp($key);
            chomp($val);
 
            if (! defined $lastmachinehash{$key} or
                $lastmachinehash{$key} ne $val)
            {
                $samehost = 0;
                last;
            }
        }
        if ($samehost == 0)
        {
            if (not $firstmachine)
            {
                print HPOUT "    <Field name=\"activeProfile\" type=\"int\">$activeindex</Field>$eol";
                print HPOUT "</Object>$eol";
                close(HPOUT);
            }
            $firstmachine = 0;
            %lastmachinehash = ();
            foreach $m (@curmachine)
            {
                $key  = $m;  $key  =~ s/.*<Field name="([^"]*)"\s+type=.*>.*<\/Field>.*$/$1/;
                $val  = $m;  $val  =~ s/.*<Field name="[^"]*"\s+type=.*>(.*)<\/Field>.*$/$1/;
                chomp($key);
                chomp($val);
                $lastmachinehash{$key} = $val;
            }
            $nick = $lastmachinehash{'hostNickname'};
            if (!defined $nick)
            {
                $nick = "unknown" . $ctr;
                $ctr++;
            }
            else
            {
                $nick =~ tr/\ \/\\\t\[\]\.[A-Z]/_______[a-z]/;
            }
            open(HPOUT, ">host_$nick.xml");
            print HPOUT $header;
            print HPOUT "<Object name=\"MachineProfile\">$eol";
            foreach $m (@curmachine)
            {
                $m =~ s/^\s*//;
                print HPOUT "    " . $m;
            }
 
            $launchcount = 0;
        }
        if ($activelaunch)
        {
            $activeindex = $launchcount;
            $activelaunch = 0;
        }
        $launchcount++;
        print HPOUT "    <Object name=\"LaunchProfile\">$eol";
        foreach $l (@curlaunch)
        {
            $l =~ s/^\s*//;
            print HPOUT "        " . $l;
        }
        print HPOUT "    </Object>$eol";
        @curlaunch = ();
        @curmachine = ();
    }
    elsif ($parsemode == 2)
    {
        if (m|<Field name="arguments"|)
        {
            $dir = $_;
            $arg = $_;
            $dir =~ s/(.*name=)"arguments"(.*)stringVector">.*"-dir"\s+"([^"]*)".*(<[\/\\]Field>.*)/$1"directory"$2string">$3$4/;
            $arg =~ s/(.*stringVector">.*)"-dir"\s+"[^"]*"(.*)/$1$2/;
 
            push @curmachine, $dir;
            push @curlaunch,  $arg;
        }
        elsif (m|<Field name="host"| or
               m|<Field name="hostAliases"| or
               m|<Field name="hostNickname"| or
               m|<Field name="shareOneBatchJob"| or
               m|<Field name="sshPortSpecified"| or
               m|<Field name="sshPort"| or
               m|<Field name="clientHostDetermination"| or
               m|<Field name="manualClientHostName"| or
               m|<Field name="tunnelSSH"| or
               m|<Field name="arguments"|)
        {
            push @curmachine, $_;
        }
        elsif (m|<Field name="active"| and m|true|)
        {
            $activelaunch = 1;
        }
        else
        {
            push @curlaunch, $_;
        }
    }
    elsif (m|<Field name="activeProfile"|)
    {
        # drop it
    }
    else
    {
        print OUT $_;
    }
}
 
close(IN);
close(OUT);
Personal tools