IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 21013


Ignore:
Timestamp:
Dec 16, 2008, 11:19:52 AM (17 years ago)
Author:
Paul Price
Message:

Ensure temporary images are deleted in event of an error.

File:
1 edited

Legend:

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

    r20929 r21013  
    7575my $stacktool = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1);
    7676my $ppStack = can_run('ppStack') or (warn "Can't find ppStack" and $missing_tools = 1);
     77my $ppConfigDump = can_run('ppConfigDump') or (warp "Can't find ppConfigDump" and $missing_tools = 1);
    7778my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    7879if ($missing_tools) {
     
    291292
    292293    carp($msg);
     294
     295    unless ($save_temps) {
     296        print "Ensuring temporary images are deleted.";
     297        delete_temps();
     298    }
     299
    293300    if (defined $stack_id and not $no_update) {
    294301        my $command = "$stacktool -stack_id $stack_id -code $exit_code";
     
    307314}
    308315
     316# Ensure temporary images are deleted
     317sub delete_temps
     318{
     319    my $command = "$ppConfigDump -camera $camera -recipe PPSTACK $recipe_ppStack -dump-recipe PPSTACK -";
     320    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     321        run(command => $command, verbose => $verbose);
     322    unless ($success) {
     323        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     324        &my_die("Unable to perform ppConfigDump: $error_code", $stack_id, $error_code);
     325    }
     326    my $md = $mdcParser->parse(join "", @$stdout_buf) or
     327        &my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR);
     328
     329    my $temp_delete = metadataLookupBool($md, 'TEMP.DELETE'); # Delete temporary files?
     330    if ($temp_delete) {
     331        my $temp_dir = metadataLookupStr($md, 'TEMP.DIR'); # Directory with temporary files
     332        my $temp_image = metadataLookupStr($md, 'TEMP.IMAGE'); # Suffix for image
     333        my $temp_mask = metadataLookupStr($md, 'TEMP.IMAGE'); # Suffix for mask
     334        my $temp_weight = metadataLookupStr($md, 'TEMP.WEIGHT'); # Suffix for weight
     335        my $temp_root = basename($outroot); # Root name for temporary files
     336
     337        if (not defined $temp_dir or not defined $temp_image or not defined $temp_mask or
     338            not defined $temp_weight) {
     339            &my_die("Unable to find details for temporary images.", $stack_id, $PS_EXIT_CONFIG_ERROR);
     340        }
     341
     342        for (my $i = 0; $i < $num; $i++) {
     343            foreach my $ext ( $temp_image, $temp_mask, $temp_weight ) {
     344                my $file = $temp_dir . '/' . $temp_root . '.' . $i . '.' . $ext;
     345                unlink $file if -e $file;
     346            }
     347        }
     348    }
     349}
     350
     351
    309352END {
    310353    my $exit = $?;
Note: See TracChangeset for help on using the changeset viewer.