Changeset 18359
- Timestamp:
- Jun 29, 2008, 2:46:10 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/ipp_cleanup.pl (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/ipp_cleanup.pl
r18141 r18359 9 9 use warnings; 10 10 use strict; 11 use Carp; 11 12 12 13 use IPC::Cmd 0.36 qw( can_run run ); 13 14 use File::Spec; 14 use PS::IPP::Config; 15 use PS::IPP::Config 1.01 qw( :standard ); 16 use PS::IPP::Metadata::List qw( parse_md_list ); 15 17 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 16 18 use Pod::Usage qw( pod2usage ); … … 19 21 20 22 # Parse the command-line arguments 21 my ($stage, $camera, $ class_id, $mode, $path_base, $dbname, $no_op, $help);23 my ($stage, $camera, $stage_id, $mode, $path_base, $dbname, $verbose, $no_op, $helplist); 22 24 GetOptions('stage=s' => \$stage, # which analysis stage to clean? 23 25 'camera|i=s' => \$camera, # user-supplied camera name 24 ' class_id=s' => \$class_id, # class_id(only needed for certain stages)26 'stage_id=s' => \$stage_id, # id for this stage (only needed for certain stages) 25 27 'mode|m=s' => \$mode, # cleanup mode (clean / purge) 26 28 'path_base=s' => \$path_base, # basename for files 27 29 'dbname|d=s' => \$dbname, # Database name 30 'verbose' => \$verbose, # Print to stdout 28 31 'no-op' => \$no_op, # pretend but don't actually inject 29 'help ' => \$help# give help listing32 'helplist' => \$helplist # give help listing 30 33 ) or pod2usage( 2 ); 31 34 32 35 pod2usage( -msg => "remove temporary / all data files for an IPP analysis stage", 33 -exitval => 2) if 34 defined $help; 36 -exitval => 2) if defined $helplist; 35 37 36 pod2usage( -msg => "Usage: $0 --camera (name) [--class_id class_id] --stage (stage) --mode (mode) --path_base (path) [--dbname dbname] [--no-op] [--help]", 37 -exitval => 2 ) if 38 scalar @ARGV == 0; 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; 39 40 40 pod2usage( -msg => "Required options:--camera (name) --stage (stage) --mode (mode) --path_base (path)",41 pod2usage( -msg => "Required options:--camera (name) --stage (stage) --mode (mode)", 41 42 -exitval => 3) unless 42 43 defined $camera and 43 44 defined $stage and 44 defined $mode and 45 defined $path_base; 45 defined $mode; 46 46 47 # $mode must be one of " clean" or "purge"48 unless (($mode eq " clean") || ($mode eq "purge")) {47 # $mode must be one of "goto_cleaned" or "goto_purged" 48 unless (($mode eq "goto_cleaned") || ($mode eq "goto_purged")) { 49 49 die "invalid cleanup mode $mode\n"; 50 50 } … … 52 52 $ipprc->define_camera($camera); 53 53 54 my $found = 0; 55 my @files = (); 54 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 55 56 my $fault = 0; 56 57 57 58 # choice of files to delete depends on the stage 58 59 if ($stage eq "chip") { 59 unless defined $class_id die "cleanup for chip stage requires class_id\n"; 60 # delete the temporary image datafiles 61 addFilename (\@files, "PPIMAGE.OUTPUT", $path_base, $class_id); 62 addFilename (\@files, "PPIMAGE.OUTPUT.MASK", $path_base, $class_id); 63 addFilename (\@files, "PPIMAGE.OUTPUT.WEIGHT", $path_base, $class_id); 64 addFilename (\@files, "PPIMAGE.CHIP", $path_base, $class_id); 65 addFilename (\@files, "PPIMAGE.CHIP.MASK", $path_base, $class_id); 66 addFilename (\@files, "PPIMAGE.CHIP.WEIGHT", $path_base, $class_id); 67 if ($mode eq "purge") { 68 # additional files to remove for 'purge' mode 69 addFilename (\@files, "PPIMAGE.OUTPUT.FPA1", $path_base, $class_id); 70 addFilename (\@files, "PPIMAGE.OUTPUT.FPA2", $path_base, $class_id); 71 addFilename (\@files, "PPIMAGE.BIN1", $path_base, $class_id); 72 addFilename (\@files, "PPIMAGE.BIN2", $path_base, $class_id); 73 addFilename (\@files, "PPIMAGE.JPEG1", $path_base, $class_id); 74 addFilename (\@files, "PPIMAGE.JPEG", $path_base, $class_id); 75 addFilename (\@files, "PPIMAGE.STATS", $path_base, $class_id); 60 61 ### select the imfiles for this entry 62 63 # this stage uses 'chiptool' 64 my $chiptool = can_run('chiptool') or die "Can't find chiptool"; 65 66 # Get list of component imfiles 67 # XXX may need a different my_die for each stage 68 my $imfiles; # Array of component files 69 my $command = "$chiptool -pendingcleanupimfile -chip_id $stage_id"; # Command to run 70 $command .= " -dbname $dbname" if defined $dbname; 71 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose); 72 unless ($success) { 73 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 74 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code); 76 75 } 77 delete_files (\@files); 78 79 # need to run command "chiptool -donecleanup" 76 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 77 &my_die("Unable to parse metadata config doc", "chip", $stage_id, $PS_EXIT_PROG_ERROR); 78 79 # extract the metadata for the files into a hash list 80 $imfiles = parse_md_list($metadata) or 81 &my_die("Unable to parse metadata list", "chip", $stage_id, $PS_EXIT_PROG_ERROR); 82 83 # loop over all of the imfiles, determine the path_base and class_id for each 84 foreach my $imfile (@$imfiles) { 85 my $class_id = $imfile->{class_id}; 86 my $path_base = $imfile->{path_base}; 87 88 # array of actual filenames to delete 89 my @files = (); 90 91 # delete the temporary image datafiles 92 addFilename (\@files, "PPIMAGE.OUTPUT", $path_base, $class_id); 93 addFilename (\@files, "PPIMAGE.OUTPUT.MASK", $path_base, $class_id); 94 addFilename (\@files, "PPIMAGE.OUTPUT.WEIGHT", $path_base, $class_id); 95 addFilename (\@files, "PPIMAGE.CHIP", $path_base, $class_id); 96 addFilename (\@files, "PPIMAGE.CHIP.MASK", $path_base, $class_id); 97 addFilename (\@files, "PPIMAGE.CHIP.WEIGHT", $path_base, $class_id); 98 if ($mode eq "goto_purged") { 99 # additional files to remove for 'purge' mode 100 addFilename (\@files, "PPIMAGE.OUTPUT.FPA1", $path_base, $class_id); 101 addFilename (\@files, "PPIMAGE.OUTPUT.FPA2", $path_base, $class_id); 102 addFilename (\@files, "PPIMAGE.BIN1", $path_base, $class_id); 103 addFilename (\@files, "PPIMAGE.BIN2", $path_base, $class_id); 104 addFilename (\@files, "PPIMAGE.JPEG1", $path_base, $class_id); 105 addFilename (\@files, "PPIMAGE.JPEG", $path_base, $class_id); 106 addFilename (\@files, "PPIMAGE.STATS", $path_base, $class_id); 107 } 108 109 # actual command to delete the files 110 my $status = &delete_files (\@files); 111 112 if (! $status) { 113 my $command = "$chiptool -updateimfile -chip_id $stage_id -class_id $class_id -code 1"; # Command to run 114 $command .= " -dbname $dbname" if defined $dbname; 115 116 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose); 117 unless ($success) { 118 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 119 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code); 120 } 121 122 $fault = 1; 123 } 124 } 125 126 if (! $fault) { 127 # set the state of the chipRun entry to "cleaned" or "purged" as needed 128 my $command = "$chiptool -updaterun -chip_id $stage_id"; 129 if ($mode eq "goto_purged") { 130 $command .= " -state purged"; 131 } else { 132 $command .= " -state cleaned"; 133 } 134 $command .= " -dbname $dbname" if defined $dbname; 135 136 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose); 137 unless ($success) { 138 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 139 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code); 140 } 141 } 80 142 exit 0; 81 143 } … … 86 148 sub delete_files 87 149 { 88 my @files = shift; # reference to a list of files to unlink150 my $files = shift; # reference to a list of files to unlink 89 151 90 152 # this script is, of course, very dangerous. 91 153 foreach my $file (@$files) { 92 echo"unlinking $file\n";93 #unlink $file;154 print STDERR "unlinking $file\n"; 155 unlink $file; 94 156 } 95 157 return 1; … … 109 171 } 110 172 173 sub my_die 174 { 175 my $msg = shift; # Warning message on die 176 my $stage = shift; # Chiptool identifier 177 my $stage_id = shift; # Chiptool identifier 178 my $exit_code = shift; # Exit code to add 179 # outputImage and outroot are globals 180 181 carp($msg); 182 exit $exit_code; 183 } 184 111 185 __END__
Note:
See TracChangeset
for help on using the changeset viewer.
