- Timestamp:
- Mar 17, 2009, 12:08:50 PM (17 years ago)
- Location:
- branches/cnb_branches/cnb_branch_20090301
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/ipp_cleanup.pl (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/cnb_branches/cnb_branch_20090301
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk merged eligible /branches/eam_branches/eam_branch_20090303 23158-23228
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/cnb_branches/cnb_branch_20090301/ippScripts/scripts/ipp_cleanup.pl
r21371 r23352 18 18 use Pod::Usage qw( pod2usage ); 19 19 20 my $ipprc = PS::IPP::Config->new(); # this is used for PATH, NEB filename conversions21 22 20 # Parse the command-line arguments 23 21 my ($stage, $camera, $stage_id, $mode, $path_base, $dbname, $verbose, $no_op, $helplist); 24 22 GetOptions('stage=s' => \$stage, # which analysis stage to clean? 25 'camera|i=s' => \$camera, # user-supplied camera name26 '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 files29 'dbname|d=s' => \$dbname, # Database name23 '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 30 28 'verbose' => \$verbose, # Print to stdout 31 'no-op' => \$no_op, # pretend but don't actually inject32 'helplist' => \$helplist # give help listing33 ) 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 33 pod2usage( -msg => "remove temporary / all data files for an IPP analysis stage", 34 -exitval => 2) if defined $helplist; 35 36 pod2usage( -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; 40 38 41 39 pod2usage( -msg => "Required options:--camera (name) --stage (stage) --mode (mode)", 42 -exitval => 3) unless 40 -exitval => 3) unless 43 41 defined $camera and 44 42 defined $stage and 45 43 defined $mode; 46 44 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"; 50 } 45 my $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 48 # "goto_purged" goto_cleaned and goto_scrubbed both result in 49 # 'cleaned' on success ('scrubbed' allows chips without config files 50 # to be cleaned; they cannot be recovered, but the small data is left 51 # behind). XXX make 'scrubbed' a data_state? 52 unless (($mode eq "goto_cleaned") || ($mode eq "goto_scrubbed") || ($mode eq "goto_purged")) { 53 die "invalid cleanup mode $mode\n"; 54 } 55 56 my $error_state; 57 if ($mode eq "goto_cleaned") { $error_state = "error_cleaned"; } 58 if ($mode eq "goto_scrubbed") { $error_state = "error_scrubbed"; } 59 if ($mode eq "goto_purged") { $error_state = "error_purged"; } 60 51 61 52 62 my %stages = ( chip => 1, camera => 1, fake => 1, warp => 1, stack => 1, diff => 1); … … 55 65 } 56 66 57 $ipprc->define_camera($camera);58 59 67 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 60 68 61 69 # choice of files to delete depends on the stage 62 70 if ($stage eq "chip") { 63 71 64 72 die "--stage_id required for stage chip\n" if !$stage_id; 65 73 ### select the imfiles for this entry … … 78 86 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code); 79 87 } 88 89 # if there are no chipProcessedImfiles (@$stdout_buf == 0), the reset the state to 'new' 90 if (@$stdout_buf == 0) { 91 my $command = "$chiptool -chip_id $stage_id -updaterun -set_state new"; 92 $command .= " -dbname $dbname" if defined $dbname; 93 94 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 95 run(command => $command, verbose => $verbose); 96 unless ($success) { 97 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 98 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code); 99 } 100 exit 0; 101 } 102 80 103 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 81 104 &my_die("Unable to parse metadata config doc", "chip", $stage_id, $PS_EXIT_PROG_ERROR); … … 87 110 # loop over all of the imfiles, determine the path_base and class_id for each 88 111 foreach my $imfile (@$imfiles) { 89 my $class_id = $imfile->{class_id};90 my $path_base = $imfile->{path_base};112 my $class_id = $imfile->{class_id}; 113 my $path_base = $imfile->{path_base}; 91 114 my $status = 1; 92 115 93 116 # don't clean up unless the data needed to update is available 117 # modes goto_purged and goto_scrubbed will remove files even if the config is non-existent 94 118 if ($mode eq "goto_cleaned") { 95 119 my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id); … … 124 148 addFilename (\@files, "PPIMAGE.CONFIG", $path_base, $class_id); 125 149 } 126 150 127 151 # actual command to delete the files 128 152 $status = &delete_files (\@files); 129 153 } 130 154 131 if ($status) {132 my $command = "$chiptool -chip_id $stage_id -class_id $class_id";155 if ($status) { 156 my $command = "$chiptool -chip_id $stage_id -class_id $class_id"; 133 157 if ($mode eq "goto_purged") { 134 158 $command .= " -topurgedimfile"; … … 136 160 $command .= " -tocleanedimfile"; 137 161 } 162 $command .= " -dbname $dbname" if defined $dbname; 163 164 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 165 run(command => $command, verbose => $verbose); 166 unless ($success) { 167 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 168 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code); 169 } 170 } else { 171 172 # if an error happens for one chip, the chipRun will stay in goto_*, but the chips will go to error_* (matching the goto_*) 173 my $command = "$chiptool -updateprocessedimfile -chip_id $stage_id -class_id $class_id -set_state $error_state"; 138 174 $command .= " -dbname $dbname" if defined $dbname; 139 175 140 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =176 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 141 177 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 } 146 } 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 ) = 151 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") { 178 unless ($success) { 179 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 180 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code); 181 } 182 } 183 } 184 exit 0; 185 } 186 187 if ($stage eq "camera") { 160 188 die "--stage_id required for stage camera\n" if !$stage_id; 161 189 # this stage uses 'camtool' … … 210 238 211 239 if ($status) { 212 my $command = "$camtool -cam_id $stage_id -updaterun";240 my $command; 213 241 if ($mode eq "goto_cleaned") { 214 $command .= " -state cleaned"; 215 } else { 216 $command .= " -state purged"; 242 $command = "$camtool -updaterun -cam_id $stage_id -set_state cleaned"; 243 } 244 if ($mode eq "goto_scrubbed") { 245 $command = "$camtool -updaterun -cam_id $stage_id -set_state cleaned"; 246 } 247 if ($mode eq "goto_purged") { 248 $command = "$camtool -updaterun -cam_id $stage_id -set_state purged"; 217 249 } 218 250 $command .= " -dbname $dbname" if defined $dbname; … … 224 256 } 225 257 } else { 226 my $command = "$camtool -updateprocessedexp -cam_id $stage_id -code 1"; 258 # since 'camera' has only a single imfile, we can just update the run 259 my $command = "$camtool -updaterun -cam_id $stage_id -set_state $error_state"; 227 260 $command .= " -dbname $dbname" if defined $dbname; 228 261 … … 236 269 } 237 270 exit 0; 238 } elsif ($stage eq "warp") { 271 } 272 273 if ($stage eq "warp") { 239 274 die "--stage_id required for stage warp\n" if !$stage_id; 240 275 # this stage uses 'warptool' … … 295 330 } 296 331 297 if ($status) {298 my $command = "$warptool -warp_id $stage_id -skycell_id $skycell_id";332 if ($status) { 333 my $command = "$warptool -warp_id $stage_id -skycell_id $skycell_id"; 299 334 if ($mode eq "goto_purged") { 300 335 $command .= " -topurgedskyfile"; … … 302 337 $command .= " -tocleanedskyfile"; 303 338 } 304 $command .= " -dbname $dbname" if defined $dbname;305 306 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =339 $command .= " -dbname $dbname" if defined $dbname; 340 341 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 307 342 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 }343 unless ($success) { 344 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 345 &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code); 346 } 312 347 } else { 313 # 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"; 348 my $command = "$warptool -updateskyfile -warp_id $stage_id -skycell_id $skycell_id -set_state $error_state"; 315 349 $command .= " -dbname $dbname" if defined $dbname; 316 350 317 351 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 318 352 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 }353 unless ($success) { 354 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 355 &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code); 356 } 323 357 exit $PS_EXIT_UNKNOWN_ERROR; 324 }358 } 325 359 } 326 360 exit 0; … … 329 363 # left TODO 330 364 # fake : faketool : -pendingcleanupimfile (loop over imfiles) 331 # stack: stacktool : -pendingcleanupskyfile (loop over skyfiles)332 # diff: difftool : -pendingcleanupskyfile 365 # stack: stacktool : -pendingcleanupskyfile 366 # diff: difftool : -pendingcleanupskyfile (loop over skyfiles) 333 367 334 368 die "ipp_cleanup.pl -stage $stage not yet implemented\n"; 335 369 336 sub delete_files 370 sub delete_files 337 371 { 338 372 my $files = shift; # reference to a list of files to unlink 339 340 # this script is, of course, very dangerous. 373 374 # this script is, of course, very dangerous. 341 375 foreach my $file (@$files) { 342 print STDERR "unlinking $file\n";376 print STDERR "unlinking $file\n"; 343 377 $ipprc->file_delete($file); 344 378 } … … 346 380 } 347 381 348 sub addFilename 382 sub addFilename 349 383 { 350 384 my $files = shift; # reference to a list of files to unlink … … 359 393 } 360 394 395 # XXX we currently do not set the error state in the db on my_die 361 396 sub my_die 362 397 {
Note:
See TracChangeset
for help on using the changeset viewer.
