Changeset 30317 for trunk/pstamp/scripts/pstamp_job_run.pl
- Timestamp:
- Jan 20, 2011, 10:28:02 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/pstamp/scripts/pstamp_job_run.pl (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/scripts/pstamp_job_run.pl
r30001 r30317 14 14 use File::Basename; 15 15 use File::Copy; 16 use File::Temp qw(tempfile); 16 17 use Digest::MD5::File qw( file_md5_hex ); 17 18 use PS::IPP::PStamp::RequestFile qw( :standard ); 19 use PS::IPP::PStamp::Job qw( :standard ); 18 20 use IPC::Cmd 0.36 qw( can_run run ); 19 21 use POSIX; … … 26 28 27 29 my ($job_id, $redirect_output, $outputBase, $rownum, $jobType, $options); 28 my ($verbose, $dbname, $dbserver, $no_update );30 my ($verbose, $dbname, $dbserver, $no_update, $save_temps); 29 31 30 32 GetOptions( … … 39 41 'verbose' => \$verbose, 40 42 'no-update' => \$no_update, 43 'save-temps' => \$save_temps, 41 44 ); 42 45 … … 75 78 my $pstamp_get_image_job = can_run('pstamp_get_image_job.pl') or (warn "Can't find pstamp_get_image_job.pl" and $missing_tools = 1); 76 79 my $dqueryparse = can_run('dqueryparse.pl') or (warn "Can't find dqueryparse.pl" and $missing_tools = 1); 80 my $streaksreplace = can_run('streaksreplace') or (warn "Can't find streaksreplace" and $missing_tools = 1); 81 my $magicdstool = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1); 77 82 78 83 if ($missing_tools) { … … 88 93 my $argString; 89 94 $argString = $params->{job_args}; 95 my $stage = $params->{stage}; 90 96 91 97 # XXX: should we do any other sanity checking? 92 98 my_die("argument list is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString; 93 99 94 $argString .= " -file $params->{image}"; 100 my $nan_masked = 1; 101 my $muggle = 0; 102 if (!$params->{magicked}) { 103 $nan_masked = 0; 104 } elsif ($params->{magicked} and ($options & ($PSTAMP_REQUEST_UNCENSORED | $PSTAMP_REQUIRE_UNCENSORED))) { 105 # Attempt to find or create a muggle image 106 $nan_masked = 0; 107 $muggle = 1; 108 } 109 110 my $image = $params->{image}; 111 my $mask; 112 my $variance; 113 my $fileArgs = " -file $params->{image}"; 95 114 my @file_list = ($params->{image}); 96 115 97 my $nan_masked = 1;98 if (!$params->{magicked}) {99 $nan_masked = 0;100 }101 116 if ($nan_masked or ($options & $PSTAMP_SELECT_MASK)) { 102 $argString .= " -mask $params->{mask}"; 103 push @file_list, $params->{mask}; 117 $mask = $params->{mask}; 118 $fileArgs .= " -mask $mask"; 119 push @file_list, $mask; 104 120 } 105 121 if ($options & $PSTAMP_SELECT_VARIANCE) { 106 $argString .= " -variance $params->{weight}"; 107 push @file_list, $params->{weight}; 122 $variance = $params->{weight}; 123 $fileArgs .= " -variance $variance"; 124 push @file_list, $variance; 108 125 } 109 126 … … 113 130 } 114 131 115 check_files(@file_list); 116 117 my $command = "$ppstamp $outputBase $argString"; 132 # check that actual input files exist 133 check_files($PSTAMP_GONE, @file_list); 134 135 # find our output directory 136 my $outdir = dirname($outputBase); 137 my ($tmpImage, $tmpMask, $tmpVariance, $tmproot); 138 139 if ($muggle) { 140 # first see if the original uncensored images are around 141 if (check_for_backups($params, \$fileArgs)) { 142 # We're good to go. fileArgs has been edited to contain the paths for the original uncensored images 143 print "Making stamps from backup images\n"; 144 } elsif (($options & $PSTAMP_REQUIRE_UNCENSORED) and ($stage ne 'chip')) { 145 # user required uncensored but since stage isn't chip we can't rebuild them 146 my_die("uncensored inputs not available for job $job_id", $job_id, $PSTAMP_NOT_AVAILABLE); 147 } elsif (($options & $PSTAMP_REQUEST_UNCENSORED) and ($stage ne 'chip')) { 148 # make stamps from uncensored images 149 $muggle = 0; 150 } else { 151 # Try and replace the streaks from the recovery images 152 153 @file_list = (); 154 $tmproot = "$outdir/$job_id"; 155 mkdir $tmproot or 156 my_die( "failed to create temporary directory $tmproot", $job_id, $PS_EXIT_UNKNOWN_ERROR); 157 my $muggle_command = "$streaksreplace -stage $stage -tmproot $tmproot"; 158 # find the "directory" of the input path_base 159 my $inputdir = dirname($image); 160 my $base = basename($image); 161 $tmpImage = "$tmproot/$base"; 162 163 # XXX: We should get the recovery_path_base from the magicDSFile but that requires a bunch of file rule and 164 # stage work. Import the rule here. 165 my $recImage = "$inputdir/REC_$base"; 166 my $newFileArgs = " -file $tmpImage"; 167 $muggle_command .= " -image $image -recimage $recImage"; 168 push @file_list, $recImage; 169 170 if ($mask) { 171 $base = basename($mask); 172 $tmpMask = "$tmproot/$base"; 173 $newFileArgs .= " -mask $tmpMask"; 174 my $recMask = "$inputdir/REC_$base"; 175 $muggle_command .= " -mask $mask -recmask $recMask"; 176 push @file_list, $recMask; 177 } 178 179 if ($variance) { 180 $base = basename($variance); 181 $tmpVariance = "$tmproot/$base"; 182 $newFileArgs .= " -weight $tmpVariance"; 183 my $recVariance = "$inputdir/REC_$base"; 184 $muggle_command .= " -weight $variance -recweight $recVariance"; 185 push @file_list, $recVariance; 186 } 187 if (check_files(0, @file_list)) { 188 # recovery files exist and are accessible restore the excised pixels 189 190 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 191 run(command => $muggle_command, verbose => $verbose); 192 unless ($success) { 193 my $exitStatus = WEXITSTATUS($error_code); 194 my_die( "streaksreplace failed with error code: $exitStatus", $job_id, $exitStatus); 195 } 196 197 # set the ppstamp file arguments 198 $fileArgs = $newFileArgs; 199 } else { 200 if ($options & $PSTAMP_REQUIRE_UNCENSORED) { 201 my_die( "unable to restore uncensored images", $job_id, $PSTAMP_NOT_AVAILABLE); 202 } 203 # just make stamps from the censored images 204 print "Unable to restore uncensored images, will extract stamps from censored images\n"; 205 # these files won't be used so zap them 206 ($tmpImage, $tmpMask, $tmpVariance, $tmproot) = (undef, undef, undef, undef); 207 } 208 } 209 } 210 211 my $command = "$ppstamp $outputBase $argString $fileArgs"; 118 212 $command .= " -dbname $dbname" if $dbname; 119 213 $command .= " -dbserver $dbserver" if $dbserver; 120 $command .= " -stage $ params->{stage}" if $params->{stage};214 $command .= " -stage $stage"; 121 215 $command .= " -no_censor_masked" unless $nan_masked; 122 216 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 131 225 } 132 226 227 if (!$save_temps) { 228 unlink $tmpImage if $tmpImage; 229 unlink $tmpMask if $tmpMask; 230 unlink $tmpVariance if $tmpVariance; 231 rmdir $tmproot if $tmproot; 232 } 233 133 234 if ($exitStatus == 0) { 134 my $dir = dirname($outputBase); 135 136 my $reglist = "$dir/reglist$job_id"; 235 my $reglist = "$outdir/reglist$job_id"; 137 236 138 237 my $F; … … 363 462 364 463 sub check_files { 464 my $error_code = shift; 465 my $return_code = 1; 365 466 foreach my $f (@_) { 366 467 if (!$ipprc->file_exists($f)) { 367 my_die( "file $f does not exist:", $job_id, $PSTAMP_GONE, 'stop'); 368 } 369 } 468 if ($error_code) { 469 my_die( "file $f does not exist:", $job_id, $error_code, 'stop'); 470 } else { 471 print STDERR "file $f does not exist\n"; 472 $return_code = 0; 473 } 474 } 475 } 476 return $return_code; 477 } 478 479 sub check_for_backups { 480 my $params = shift; 481 my $r_fileArgs = shift; 482 483 my $command = "$magicdstool -destreakedfile -stage $params->{stage} -stage_id $params->{stage_id} -component $params->{component} -dbname $params->{imagedb}"; 484 my $results = runToolAndParse($command, $verbose); 485 my $dsComponent = $results->[0]; 486 487 if ($dsComponent and ($dsComponent->{data_state} eq 'full')) { 488 489 print "magicDSFile state is full. Backup images should exist\n"; 490 491 # replace the file names with the backup paths 492 # fileArgs has the form: -file imagename [-mask maskname] [-weight weightname] 493 my @args = split " ", $$r_fileArgs; 494 495 my $newFileArgs; 496 while (@args) { 497 my $a = shift @args; 498 my $f = shift @args; 499 my_die( "unexpected fileArg list $$r_fileArgs", $job_id, $PS_EXIT_PROG_ERROR, 'run') if !$a or !$f; 500 501 my $backup_image_name = $ipprc->destreaked_filename($f); 502 my_die( "failed to extract backup image name from $f", $job_id, $PS_EXIT_PROG_ERROR, 'run') if !$backup_image_name; 503 $newFileArgs .= " $a $backup_image_name"; 504 } 505 $$r_fileArgs = $newFileArgs; 506 507 return 1; 508 } 509 510 return 0; 370 511 } 371 512
Note:
See TracChangeset
for help on using the changeset viewer.
