IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24210


Ignore:
Timestamp:
May 16, 2009, 2:57:23 PM (17 years ago)
Author:
bills
Message:

edit config dump files to change volume imformation
to match the destination.
I.E. neb://volume/ ===> receiveSource.workdir/

/data/ippxxx.y/ ===> receiveSource.workdir/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/receive_file.pl

    r24207 r24210  
    162162    # Rather than read it as an mdc and interptet it, we do our substitutions directly
    163163    # This is much faster. Parsing a mdc file for a chip run takes several seconds.
    164     # we are very strict on the formatting
    165 
    166     # first line tells us the run type. From this we get the stage
     164    # we are very strict about the format of the file
     165    #
     166    # First comes the data for the Run
     167    # Next is the data for each component
     168    # The component_id (class_id, skycell_id) must come before any of the paths that we edit
     169
     170    # The first line tells us the run type. From this we get the stage
    167171    #
    168172    my $line = $lines[0];
     
    170174    &my_die( "unexpected first line found in $filename: $line\n", $file_id, $PS_EXIT_UNKNOWN_ERROR)
    171175        if !$runType or ($multi ne 'MULTI');
     176
    172177    my $stage;
    173178    my $comp_name;
     
    201206    my $new_workdir_value;
    202207    if ($destdir eq 'none') {
     208        # this only appiles to rawExp
    203209        $new_workdir_value = "$workdir";
    204210    } else {
     
    213219
    214220        my ($name, $type, $value) = split " ", $line;
    215         # we only edit complete lines
     221        # only complete lines have things that we need to examine
    216222        if ($name and $type and $value) {
    217223            my $new_value;
     224            # we have a new component id, save it and look up the corresponding
     225            # component_dir
    218226            if ($name eq $comp_name) {
    219227                $current_component = $value;
     
    235243            }
    236244
     245            # if the value changed re-write the line, otherwise just print what we read
    237246            if ($new_value) {
    238247                $out_line = "   " . $name . "\t\t" . $type . "\t" . $new_value . "\n";
     
    300309        my $target = "$target_dir/$file"; # Target destination for file
    301310
     311
    302312        $ipprc->file_delete ($target);
    303313
     
    308318        }
    309319
    310         system("mv $from $to") == 0 or &my_die( "Unable to move $file into workdir $workdir: $!\n", $file_id, $PS_EXIT_UNKNOWN_ERROR);
     320        if ( $file =~ /.+\.mdc/ ) {
     321            # this file is a config dump file edit the paths
     322            edit_mdc_file($file_id, $from, $to, $workdir);
     323        } else {
     324            system("mv $from $to") == 0 or &my_die( "Unable to move $file into workdir $workdir: $!\n", $file_id, $PS_EXIT_UNKNOWN_ERROR);
     325        }
    311326    }
    312327} else {
     
    314329}
    315330
    316 if (!$save_temps) {
     331if (!$save_temps and -e $filename) {
    317332    unlink $filename or &my_die( "Unable to unlink $filename\n", $file_id, $PS_EXIT_UNKNOWN_ERROR);
    318333}
     
    372387}
    373388
     389# edit a config dump file replacing the "volume" value with the new local value: $workdir
     390sub edit_mdc_file
     391{
     392    my $file_id = shift;
     393    my $src = shift;
     394    my $dest = shift;
     395    my $workdir = shift;
     396
     397    open my $IN,  "<$src" or &my_die("failed to open $src for input", $file_id, $PS_EXIT_UNKNOWN_ERROR);
     398    open my $OUT, ">$dest" or &my_die("failed to open $dest for output", $file_id, $PS_EXIT_UNKNOWN_ERROR);
     399
     400    # Assumed file structure
     401    # stuff
     402    # FILES.INPUT metadata
     403    # FILES.OUTPUT metadata
     404    # more stuff
     405    # only the paths in the FILES.* metadata are monkeyed with
     406    my $done_editing = 0;
     407    my $numFilesMD = 0;
     408    foreach my $line (<$IN>) {
     409        my $out_line = $line;
     410        if (!$done_editing) {
     411            my (@words) = split " ", $line;
     412            if (scalar @words) {
     413                # get rid of any leading blank words
     414                while ((scalar @words) and !defined $words[0]) {
     415                    shift @words;
     416                }
     417
     418                if ($words[1] and $words[1] eq "METADATA") {
     419                    if ( $words[0] =~ /^FILES\..+/ ) {
     420                        $numFilesMD++;
     421                    }
     422                } elsif ($words[0] eq "END") {
     423                    # when we get to the end of the second FILES metadata we're done editing
     424                    if ($numFilesMD == 2) {
     425                        $done_editing = 1;
     426                    }
     427                } elsif ($numFilesMD and ($words[1] eq "STR"))  {
     428                    # we're processing one of the files metadata edit the path
     429                    my $key = shift @words;
     430                    my $type = shift @words;
     431                    my $path = shift @words;
     432                    my $extra = join " ", @words;
     433
     434                    $path = edit_path($file_id, $workdir, $path);
     435
     436                    $out_line = "\t" . $key ."\t" . "STR" . "\t" . $path;
     437                    $out_line .= "\t" . $extra if $extra;
     438                    $out_line .= "\n";
     439                }
     440            }
     441        }
     442        print $OUT $out_line;
     443    }
     444
     445    close $IN;
     446    close $OUT or &my_die("failed to close $dest", $file_id, $PS_EXIT_UNKNOWN_ERROR);
     447}
     448
     449
     450# XXX: this should go into a module
     451# Replace 'volume portion of path with $workdir/
     452# Volume is defined here by
     453#   neb://volume/
     454#   /xxx/xxxxx/         i.e. /data/ippxxx.y/
     455#   file://xxx/xxxxx/   i.e. file://data/ippxxx.y/
     456#   path://somepath/
     457sub edit_path
     458{
     459    my $file_id = shift;
     460    my $workdir = shift;
     461    my $path = shift;
     462
     463    my $scheme = file_scheme($path);
     464    my $tail;
     465    if ($scheme) {
     466            # strip off scheme://
     467        $tail = substr($path, length($scheme) + 3);
     468    } elsif (substr($path, 0, 1) eq '/') {
     469        $tail = substr($path, 1);
     470        $scheme = "";
     471    }
     472    # remove any leading / that are left
     473    while ((substr($tail, 0, 1) eq '/')) {
     474        $tail = substr($tail, 1);
     475    }
     476
     477    my @segments;
     478    if (($scheme eq 'neb') or ($scheme eq 'path')) {
     479        my $volume;
     480        ($volume, @segments) = split '/', $tail;
     481
     482    } elsif (!$scheme or ($scheme eq 'file')) {
     483
     484        # XXX Here we're assuming the /data/ipp??? structure. This won't be true when data is forwarded
     485        # by remote sites. We need a way to configure this
     486        my $volume;
     487
     488        # data/ippxxx/dirs
     489        (undef, $volume, @segments) = split '/', $tail;
     490    } else {
     491        &my_die( "unexpected workdir value: $path\n", $file_id, $PS_EXIT_PROG_ERROR);
     492    }
     493
     494    my $new_path = caturi($workdir, @segments);
     495
     496    return $new_path;
     497}
     498
    374499sub my_die
    375500{
Note: See TracChangeset for help on using the changeset viewer.