IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 5, 2009, 11:24:29 AM (17 years ago)
Author:
beaumont
Message:

sync with mainline

Location:
branches/cnb_branches/cnb_branch_20090215
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branches/cnb_branch_20090215

  • branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/ipp_cleanup.pl

    r21371 r23199  
    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
    47 # $mode must be one of "goto_cleaned" or "goto_purged"
    48 unless (($mode eq "goto_cleaned") || ($mode eq "goto_purged")) {
    49     die "invalid cleanup mode $mode\n";   
     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
     47# $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
     49# be cleaned (they cannot be recovered, but the small data is left behind)
     50unless (($mode eq "goto_cleaned") || ($mode eq "goto_scrubbed") || ($mode eq "goto_purged")) {
     51    die "invalid cleanup mode $mode\n";
    5052}
    5153
     
    5557}
    5658
    57 $ipprc->define_camera($camera);
    58 
    5959my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    6060
    6161# choice of files to delete depends on the stage
    6262if ($stage eq "chip") {
    63    
     63
    6464    die "--stage_id required for stage chip\n" if !$stage_id;
    6565    ### select the imfiles for this entry
     
    8787    # loop over all of the imfiles, determine the path_base and class_id for each
    8888    foreach my $imfile (@$imfiles) {
    89         my $class_id = $imfile->{class_id};
    90         my $path_base = $imfile->{path_base};
     89        my $class_id = $imfile->{class_id};
     90        my $path_base = $imfile->{path_base};
    9191        my $status = 1;
    9292
    9393        # don't clean up unless the data needed to update is available
     94        # modes goto_purged and goto_scrubbed will remove files even if the config is non-existent
    9495        if ($mode eq "goto_cleaned") {
    9596            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id);
     
    124125                addFilename (\@files, "PPIMAGE.CONFIG", $path_base, $class_id);
    125126            }
    126        
     127
    127128            # actual command to delete the files
    128129            $status = &delete_files (\@files);
    129130        }
    130131
    131         if ($status)  {
    132             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";
    133134            if ($mode eq "goto_purged") {
    134135                $command .= " -topurgedimfile";
     136            } elsif ($mode eq "goto_scrubbed") {
     137                $command .= " -tocleanedimfile_from_scrubbed";
    135138            } else {
    136139                $command .= " -tocleanedimfile";
    137140            }
    138             $command .= " -dbname $dbname" if defined $dbname;
    139 
    140             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 ) =
    141144                    run(command => $command, verbose => $verbose);
    142             unless ($success) {
    143                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    144                 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
    145             }
     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            }
    146149        } else {
    147             my $command = "$chiptool -updateprocessedimfile -chip_id $stage_id -class_id $class_id -code 1";
    148             $command .= " -dbname $dbname" if defined $dbname;
    149 
    150             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 ) =
    151155                    run(command => $command, verbose => $verbose);
    152             unless ($success) {
    153                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    154                 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
    155             }
    156         }
    157     }
    158 
    159 } elsif ($stage eq "camera") {
     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        }
     161    }
     162    exit 0;
     163}
     164
     165if ($stage eq "camera") {
    160166    die "--stage_id required for stage camera\n" if !$stage_id;
    161167    # this stage uses 'camtool'
     
    236242    }
    237243    exit 0;
    238 } elsif ($stage eq "warp") {
     244}
     245
     246if ($stage eq "warp") {
    239247    die "--stage_id required for stage warp\n" if !$stage_id;
    240248    # this stage uses 'warptool'
     
    295303        }
    296304
    297         if ($status)  {
    298             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";
    299307            if ($mode eq "goto_purged") {
    300308                $command .= " -topurgedskyfile";
     
    302310                $command .= " -tocleanedskyfile";
    303311            }
    304             $command .= " -dbname $dbname" if defined $dbname;
    305 
    306             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 ) =
    307315                    run(command => $command, verbose => $verbose);
    308             unless ($success) {
    309                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    310                 &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
    311             }
     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            }
    312320         } else {
    313321            # XXX: -updateskyfile mode does not exist, need to add it
    314             my $command = "$warptool -updateskyfile -warp_id $stage_id -skycell_id $skycell_id -code 1";
    315             $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;
    316324
    317325            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    318326                run(command => $command, verbose => $verbose);
    319             unless ($success) {
    320                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    321                 &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
    322             }
     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            }
    323331            exit $PS_EXIT_UNKNOWN_ERROR;
    324         }
     332        }
    325333    }
    326334    exit 0;
     
    334342die "ipp_cleanup.pl -stage $stage not yet implemented\n";
    335343
    336 sub delete_files 
     344sub delete_files
    337345{
    338346    my $files = shift; # reference to a list of files to unlink
    339    
    340     # this script is, of course, very dangerous. 
     347
     348    # this script is, of course, very dangerous.
    341349    foreach my $file (@$files) {
    342         print STDERR "unlinking $file\n";
     350        print STDERR "unlinking $file\n";
    343351        $ipprc->file_delete($file);
    344352    }
     
    346354}
    347355
    348 sub addFilename 
     356sub addFilename
    349357{
    350358    my $files      = shift; # reference to a list of files to unlink
Note: See TracChangeset for help on using the changeset viewer.