ITK/Release 4/Wrapping/Tasks/WrapITKModular

From KitwarePublic
Jump to navigationJump to search

Modular WrapITK

Mapping of files

Script used to obtain the mapping

#!/usr/bin/perl 
require 5.004;

$input = "Ashish_wrapfiles.txt";
$output = "Ashish_headerfiles.txt";
$mapping = "Ashish_mapping.txt";

# First, prepare the input INPUT
open(FILE2, ">$input") || die "Could not open $input\n";
system("find . -name \*\.wrap -print >> $input")  == 0 || die "system error $?"; 
close(FILE2);

# Next, process and write it in the output INPUT
open(INPUT, "$input") || die "Could not open $input\n";
open (OUTPUT, ">$output") || die "Could not open $output\n";

#$pattern = '^\.\/Wrapping\/WrapITK\/Libraries\/(\w*)\/(\w*)\.wrap';
$pattern = '^\.\/(((\w*)\/)+)(\w*)\.wrap';


while ($line = <INPUT>) { 
    chomp($line);
    if($line=~/$pattern/)  {
        #(@output) = `find . -iname \'$4.h\' -print`;
        #$out = pop(@output);
        $out = `find . -iname \'$4.h\' -print`;
        #chomp($out);
        $out =~ s/\n/,/g;
        $out =~ s/,$//; # get rid of last comma
        if($out) {
            print OUTPUT "$out\n";

        } else {
            print OUTPUT "<No Mapping available>\n";
        }
    }
} 
close(OUTPUT);
close(INPUT);

# Merge two files line by line
open (OUTPUT, "$output") || die "Could not open $output\n";
open (MAPPING, ">$mapping") || die "Could not open $output\n";
open (INPUT, "$input") || die "Could not open $input\n";

while ($line = <INPUT>) { 
    $line2 = <OUTPUT>;
    print MAPPING $line, " => ", $line2, "\n";
} 
close(OUTPUT);
close(INPUT);
close(MAPPING);

# git move the wrap files to the corresponding folders
$log = "Ashish_Log.txt";
open (LOG, ">$log") || die "Could not open $log\n";
open (OUTPUT, "$output") || die "Could not open $output\n";
open (INPUT, "$input") || die "Could not open $input\n";

while ($line = <INPUT>) { 
        $line2 = <OUTPUT>;
        if($line2 =~ /^\<No Mapping available\>$/) {
            ; # do nothing
        }
        else { # move files
            chomp($line);
            $line2 =~ s/\n/,/g;
            $line2 =~ s/\s/,/g;
            $line2 =~ s/,$//; # get rid of last comma
            $line2 =~ s/^\.\///g;
            @temp = split(/\//, $line2);
            pop(@temp); pop(@temp);
            $rootdir = `pwd`;chomp($rootdir);
            $libdir = "$rootdir/Wrapping/WrapITK/Libraries";
            $t = $libdir;
            while($sdir = shift(@temp)) {
                if (-d "$t/$sdir") {
                    $t = "$t/$sdir";
                    next;
                }
                else {
                    system("mkdir $t/$sdir") ==0 || die "Could not create directory $sdir of $t\n";
                    $t = "$t/$sdir";
                }
            }
            system("cp $line $t/") == 0 || die "Could not copy INPUT:$line to directory:$t\n";
        }
}

close(LOG);
close(OUTPUT);
close(INPUT);