IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 4, 2009, 4:17:15 PM (17 years ago)
Author:
Paul Price
Message:

Removing the exception handling I put in the other day. We suspect it's interfering with kapa falling over when the pipe is cut. Instead, being more careful with checking return status of PS::IPP::Config->new() and 6752ipprc->redirect_output(), combined with recent change to PS::IPP::Config should mean the former trouble of Perl scripts exiting without pushing exit status into the database should still be solved.

File:
1 edited

Legend:

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

    r22750 r23186  
    1818use Pod::Usage qw( pod2usage );
    1919
    20 my $ipprc = PS::IPP::Config->new(); # this is used for PATH, NEB filename conversions
    21 
    2220# Parse the command-line arguments
    2321my ($stage, $camera, $stage_id, $mode, $path_base, $dbname, $verbose, $no_op, $helplist);
    2422GetOptions('stage=s'        => \$stage,     # which analysis stage to clean?
    25            'camera|i=s'     => \$camera,    # user-supplied camera name
    26            'stage_id=s'     => \$stage_id,  # id for this stage (only needed for certain stages)
    27            'mode|m=s'       => \$mode,      # cleanup mode (clean / purge)
    28            'path_base=s'    => \$path_base, # basename for files
    29            'dbname|d=s'     => \$dbname,    # Database name
     23           'camera|i=s'     => \$camera,    # user-supplied camera name
     24           'stage_id=s'     => \$stage_id,  # id for this stage (only needed for certain stages)
     25           'mode|m=s'       => \$mode,      # cleanup mode (clean / purge)
     26           'path_base=s'    => \$path_base, # basename for files
     27           'dbname|d=s'     => \$dbname,    # Database name
    3028           'verbose'        => \$verbose,   # Print to stdout
    31            'no-op'          => \$no_op,     # pretend but don't actually inject
    32            'helplist'       => \$helplist   # give help listing
    33            ) or pod2usage( 2 );
    34 
    35 pod2usage( -msg => "remove temporary / all data files for an IPP analysis stage", 
    36            -exitval => 2) if defined $helplist;
    37 
    38 pod2usage( -msg => "Usage: $0 --camera (name) --stage (stage) --stage_id (stage_id) --mode (mode) [--path_base (path)] [--dbname dbname] [--no-op] [--help]", 
    39            -exitval => 2 ) if scalar @ARGV;
     29           'no-op'          => \$no_op,     # pretend but don't actually inject
     30           'helplist'       => \$helplist   # give help listing
     31           ) or pod2usage( 2 );
     32
     33pod2usage( -msg => "remove temporary / all data files for an IPP analysis stage",
     34           -exitval => 2) if defined $helplist;
     35
     36pod2usage( -msg => "Usage: $0 --camera (name) --stage (stage) --stage_id (stage_id) --mode (mode) [--path_base (path)] [--dbname dbname] [--no-op] [--help]",
     37           -exitval => 2 ) if scalar @ARGV;
    4038
    4139pod2usage( -msg => "Required options:--camera (name) --stage (stage) --mode (mode)",
    42            -exitval => 3) unless
     40           -exitval => 3) unless
    4341    defined $camera and
    4442    defined $stage and
    4543    defined $mode;
    4644
     45my $ipprc = PS::IPP::Config->new( $camera ) or my_die("Unable to set up", $stage_id, $PS_EXIT_CONFIG_ERROR); # this is used for PATH, NEB filename conversions
     46
    4747# $mode must be one of "goto_cleaned", "goto_scrubbed", or "goto_purged"
    48 # goto_cleaned and goto_scrubbed both result in 'cleaned': scrubbed allows chips without config files to 
     48# goto_cleaned and goto_scrubbed both result in 'cleaned': scrubbed allows chips without config files to
    4949# be cleaned (they cannot be recovered, but the small data is left behind)
    5050unless (($mode eq "goto_cleaned") || ($mode eq "goto_scrubbed") || ($mode eq "goto_purged")) {
    51     die "invalid cleanup mode $mode\n";   
     51    die "invalid cleanup mode $mode\n";
    5252}
    5353
     
    5757}
    5858
    59 $ipprc->define_camera($camera);
    60 
    6159my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    6260
    6361# choice of files to delete depends on the stage
    6462if ($stage eq "chip") {
    65    
     63
    6664    die "--stage_id required for stage chip\n" if !$stage_id;
    6765    ### select the imfiles for this entry
     
    8987    # loop over all of the imfiles, determine the path_base and class_id for each
    9088    foreach my $imfile (@$imfiles) {
    91         my $class_id = $imfile->{class_id};
    92         my $path_base = $imfile->{path_base};
     89        my $class_id = $imfile->{class_id};
     90        my $path_base = $imfile->{path_base};
    9391        my $status = 1;
    9492
    9593        # don't clean up unless the data needed to update is available
    96         # modes goto_purged and goto_scrubbed will remove files even if the config is non-existent
     94        # modes goto_purged and goto_scrubbed will remove files even if the config is non-existent
    9795        if ($mode eq "goto_cleaned") {
    9896            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id);
     
    127125                addFilename (\@files, "PPIMAGE.CONFIG", $path_base, $class_id);
    128126            }
    129        
     127
    130128            # actual command to delete the files
    131129            $status = &delete_files (\@files);
    132130        }
    133131
    134         if ($status)  {
    135             my $command = "$chiptool -chip_id $stage_id -class_id $class_id";
     132        if ($status)  {
     133            my $command = "$chiptool -chip_id $stage_id -class_id $class_id";
    136134            if ($mode eq "goto_purged") {
    137135                $command .= " -topurgedimfile";
    138136            } elsif ($mode eq "goto_scrubbed") {
    139137                $command .= " -tocleanedimfile_from_scrubbed";
    140             } else {
     138            } else {
    141139                $command .= " -tocleanedimfile";
    142140            }
    143             $command .= " -dbname $dbname" if defined $dbname;
    144 
    145             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     141            $command .= " -dbname $dbname" if defined $dbname;
     142
     143            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    146144                    run(command => $command, verbose => $verbose);
    147             unless ($success) {
    148                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    149                 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
    150             }
     145            unless ($success) {
     146                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     147                &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
     148            }
    151149        } else {
    152             # if an error happens for one chip, the chipRun will stay in goto_*, but the chips will stop be run
    153             my $command = "$chiptool -updateprocessedimfile -chip_id $stage_id -class_id $class_id -code 1";
    154             $command .= " -dbname $dbname" if defined $dbname;
    155 
    156             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     150            # if an error happens for one chip, the chipRun will stay in goto_*, but the chips will stop be run
     151            my $command = "$chiptool -updateprocessedimfile -chip_id $stage_id -class_id $class_id -code 1";
     152            $command .= " -dbname $dbname" if defined $dbname;
     153
     154            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    157155                    run(command => $command, verbose => $verbose);
    158             unless ($success) {
    159                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    160                 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
    161             }
    162         }
     156            unless ($success) {
     157                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     158                &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
     159            }
     160        }
    163161    }
    164162    exit 0;
    165 } 
     163}
    166164
    167165if ($stage eq "camera") {
     
    244242    }
    245243    exit 0;
    246 } 
     244}
    247245
    248246if ($stage eq "warp") {
     
    305303        }
    306304
    307         if ($status)  {
    308             my $command = "$warptool -warp_id $stage_id -skycell_id $skycell_id";
     305        if ($status)  {
     306            my $command = "$warptool -warp_id $stage_id -skycell_id $skycell_id";
    309307            if ($mode eq "goto_purged") {
    310308                $command .= " -topurgedskyfile";
     
    312310                $command .= " -tocleanedskyfile";
    313311            }
    314             $command .= " -dbname $dbname" if defined $dbname;
    315 
    316             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     312            $command .= " -dbname $dbname" if defined $dbname;
     313
     314            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    317315                    run(command => $command, verbose => $verbose);
    318             unless ($success) {
    319                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    320                 &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
    321             }
     316            unless ($success) {
     317                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     318                &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
     319            }
    322320         } else {
    323321            # XXX: -updateskyfile mode does not exist, need to add it
    324             my $command = "$warptool -updateskyfile -warp_id $stage_id -skycell_id $skycell_id -code 1";
    325             $command .= " -dbname $dbname" if defined $dbname;
     322            my $command = "$warptool -updateskyfile -warp_id $stage_id -skycell_id $skycell_id -code 1";
     323            $command .= " -dbname $dbname" if defined $dbname;
    326324
    327325            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    328326                run(command => $command, verbose => $verbose);
    329             unless ($success) {
    330                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    331                 &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
    332             }
     327            unless ($success) {
     328                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     329                &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
     330            }
    333331            exit $PS_EXIT_UNKNOWN_ERROR;
    334         }
     332        }
    335333    }
    336334    exit 0;
     
    344342die "ipp_cleanup.pl -stage $stage not yet implemented\n";
    345343
    346 sub delete_files 
     344sub delete_files
    347345{
    348346    my $files = shift; # reference to a list of files to unlink
    349    
    350     # this script is, of course, very dangerous. 
     347
     348    # this script is, of course, very dangerous.
    351349    foreach my $file (@$files) {
    352         print STDERR "unlinking $file\n";
     350        print STDERR "unlinking $file\n";
    353351        $ipprc->file_delete($file);
    354352    }
     
    356354}
    357355
    358 sub addFilename 
     356sub addFilename
    359357{
    360358    my $files      = shift; # reference to a list of files to unlink
Note: See TracChangeset for help on using the changeset viewer.