Changeset 24210
- Timestamp:
- May 16, 2009, 2:57:23 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/receive_file.pl (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/receive_file.pl
r24207 r24210 162 162 # Rather than read it as an mdc and interptet it, we do our substitutions directly 163 163 # 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 167 171 # 168 172 my $line = $lines[0]; … … 170 174 &my_die( "unexpected first line found in $filename: $line\n", $file_id, $PS_EXIT_UNKNOWN_ERROR) 171 175 if !$runType or ($multi ne 'MULTI'); 176 172 177 my $stage; 173 178 my $comp_name; … … 201 206 my $new_workdir_value; 202 207 if ($destdir eq 'none') { 208 # this only appiles to rawExp 203 209 $new_workdir_value = "$workdir"; 204 210 } else { … … 213 219 214 220 my ($name, $type, $value) = split " ", $line; 215 # we only edit complete lines221 # only complete lines have things that we need to examine 216 222 if ($name and $type and $value) { 217 223 my $new_value; 224 # we have a new component id, save it and look up the corresponding 225 # component_dir 218 226 if ($name eq $comp_name) { 219 227 $current_component = $value; … … 235 243 } 236 244 245 # if the value changed re-write the line, otherwise just print what we read 237 246 if ($new_value) { 238 247 $out_line = " " . $name . "\t\t" . $type . "\t" . $new_value . "\n"; … … 300 309 my $target = "$target_dir/$file"; # Target destination for file 301 310 311 302 312 $ipprc->file_delete ($target); 303 313 … … 308 318 } 309 319 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 } 311 326 } 312 327 } else { … … 314 329 } 315 330 316 if (!$save_temps ) {331 if (!$save_temps and -e $filename) { 317 332 unlink $filename or &my_die( "Unable to unlink $filename\n", $file_id, $PS_EXIT_UNKNOWN_ERROR); 318 333 } … … 372 387 } 373 388 389 # edit a config dump file replacing the "volume" value with the new local value: $workdir 390 sub 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/ 457 sub 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 374 499 sub my_die 375 500 {
Note:
See TracChangeset
for help on using the changeset viewer.
