Index: trunk/ippScripts/scripts/ipp_cleanup.pl
===================================================================
--- trunk/ippScripts/scripts/ipp_cleanup.pl	(revision 22750)
+++ trunk/ippScripts/scripts/ipp_cleanup.pl	(revision 23186)
@@ -18,36 +18,36 @@
 use Pod::Usage qw( pod2usage );
 
-my $ipprc = PS::IPP::Config->new(); # this is used for PATH, NEB filename conversions
-
 # Parse the command-line arguments
 my ($stage, $camera, $stage_id, $mode, $path_base, $dbname, $verbose, $no_op, $helplist);
 GetOptions('stage=s'        => \$stage,     # which analysis stage to clean?
-	   'camera|i=s'     => \$camera,    # user-supplied camera name
-	   'stage_id=s'     => \$stage_id,  # id for this stage (only needed for certain stages)
-	   'mode|m=s'       => \$mode,      # cleanup mode (clean / purge)
-	   'path_base=s'    => \$path_base, # basename for files
-	   'dbname|d=s'     => \$dbname,    # Database name
+           'camera|i=s'     => \$camera,    # user-supplied camera name
+           'stage_id=s'     => \$stage_id,  # id for this stage (only needed for certain stages)
+           'mode|m=s'       => \$mode,      # cleanup mode (clean / purge)
+           'path_base=s'    => \$path_base, # basename for files
+           'dbname|d=s'     => \$dbname,    # Database name
            'verbose'        => \$verbose,   # Print to stdout
-	   'no-op'          => \$no_op,     # pretend but don't actually inject
-	   'helplist'       => \$helplist   # give help listing
-	   ) or pod2usage( 2 );
-
-pod2usage( -msg => "remove temporary / all data files for an IPP analysis stage", 
-	   -exitval => 2) if defined $helplist;
-
-pod2usage( -msg => "Usage: $0 --camera (name) --stage (stage) --stage_id (stage_id) --mode (mode) [--path_base (path)] [--dbname dbname] [--no-op] [--help]", 
-	   -exitval => 2 ) if scalar @ARGV;
+           'no-op'          => \$no_op,     # pretend but don't actually inject
+           'helplist'       => \$helplist   # give help listing
+           ) or pod2usage( 2 );
+
+pod2usage( -msg => "remove temporary / all data files for an IPP analysis stage",
+           -exitval => 2) if defined $helplist;
+
+pod2usage( -msg => "Usage: $0 --camera (name) --stage (stage) --stage_id (stage_id) --mode (mode) [--path_base (path)] [--dbname dbname] [--no-op] [--help]",
+           -exitval => 2 ) if scalar @ARGV;
 
 pod2usage( -msg => "Required options:--camera (name) --stage (stage) --mode (mode)",
-	   -exitval => 3) unless 
+           -exitval => 3) unless
     defined $camera and
     defined $stage and
     defined $mode;
 
+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
+
 # $mode must be one of "goto_cleaned", "goto_scrubbed", or "goto_purged"
-# goto_cleaned and goto_scrubbed both result in 'cleaned': scrubbed allows chips without config files to 
+# goto_cleaned and goto_scrubbed both result in 'cleaned': scrubbed allows chips without config files to
 # be cleaned (they cannot be recovered, but the small data is left behind)
 unless (($mode eq "goto_cleaned") || ($mode eq "goto_scrubbed") || ($mode eq "goto_purged")) {
-    die "invalid cleanup mode $mode\n";    
+    die "invalid cleanup mode $mode\n";
 }
 
@@ -57,11 +57,9 @@
 }
 
-$ipprc->define_camera($camera);
-
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
 # choice of files to delete depends on the stage
 if ($stage eq "chip") {
-    
+
     die "--stage_id required for stage chip\n" if !$stage_id;
     ### select the imfiles for this entry
@@ -89,10 +87,10 @@
     # loop over all of the imfiles, determine the path_base and class_id for each
     foreach my $imfile (@$imfiles) {
-	my $class_id = $imfile->{class_id};
-	my $path_base = $imfile->{path_base};
+        my $class_id = $imfile->{class_id};
+        my $path_base = $imfile->{path_base};
         my $status = 1;
 
         # don't clean up unless the data needed to update is available
-	# modes goto_purged and goto_scrubbed will remove files even if the config is non-existent
+        # modes goto_purged and goto_scrubbed will remove files even if the config is non-existent
         if ($mode eq "goto_cleaned") {
             my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id);
@@ -127,41 +125,41 @@
                 addFilename (\@files, "PPIMAGE.CONFIG", $path_base, $class_id);
             }
-	
+
             # actual command to delete the files
             $status = &delete_files (\@files);
         }
 
-	if ($status)  {
-	    my $command = "$chiptool -chip_id $stage_id -class_id $class_id";
+        if ($status)  {
+            my $command = "$chiptool -chip_id $stage_id -class_id $class_id";
             if ($mode eq "goto_purged") {
                 $command .= " -topurgedimfile";
             } elsif ($mode eq "goto_scrubbed") {
                 $command .= " -tocleanedimfile_from_scrubbed";
-	    } else {
+            } else {
                 $command .= " -tocleanedimfile";
             }
-	    $command .= " -dbname $dbname" if defined $dbname;
-
-	    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            $command .= " -dbname $dbname" if defined $dbname;
+
+            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
                     run(command => $command, verbose => $verbose);
-	    unless ($success) {
-		$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-		&my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
-	    }
+            unless ($success) {
+                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
+            }
         } else {
-	    # if an error happens for one chip, the chipRun will stay in goto_*, but the chips will stop be run
-	    my $command = "$chiptool -updateprocessedimfile -chip_id $stage_id -class_id $class_id -code 1";
-	    $command .= " -dbname $dbname" if defined $dbname;
-
-	    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            # if an error happens for one chip, the chipRun will stay in goto_*, but the chips will stop be run
+            my $command = "$chiptool -updateprocessedimfile -chip_id $stage_id -class_id $class_id -code 1";
+            $command .= " -dbname $dbname" if defined $dbname;
+
+            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
                     run(command => $command, verbose => $verbose);
-	    unless ($success) {
-		$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-		&my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
-	    }
-	}
+            unless ($success) {
+                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
+            }
+        }
     }
     exit 0;
-} 
+}
 
 if ($stage eq "camera") {
@@ -244,5 +242,5 @@
     }
     exit 0;
-} 
+}
 
 if ($stage eq "warp") {
@@ -305,6 +303,6 @@
         }
 
-	if ($status)  {
-	    my $command = "$warptool -warp_id $stage_id -skycell_id $skycell_id";
+        if ($status)  {
+            my $command = "$warptool -warp_id $stage_id -skycell_id $skycell_id";
             if ($mode eq "goto_purged") {
                 $command .= " -topurgedskyfile";
@@ -312,25 +310,25 @@
                 $command .= " -tocleanedskyfile";
             }
-	    $command .= " -dbname $dbname" if defined $dbname;
-
-	    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            $command .= " -dbname $dbname" if defined $dbname;
+
+            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
                     run(command => $command, verbose => $verbose);
-	    unless ($success) {
-		$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-		&my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
-	    }
+            unless ($success) {
+                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
+            }
          } else {
             # XXX: -updateskyfile mode does not exist, need to add it
-	    my $command = "$warptool -updateskyfile -warp_id $stage_id -skycell_id $skycell_id -code 1";
-	    $command .= " -dbname $dbname" if defined $dbname;
+            my $command = "$warptool -updateskyfile -warp_id $stage_id -skycell_id $skycell_id -code 1";
+            $command .= " -dbname $dbname" if defined $dbname;
 
             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
                 run(command => $command, verbose => $verbose);
-	    unless ($success) {
-		$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-		&my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
-	    }
+            unless ($success) {
+                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
+            }
             exit $PS_EXIT_UNKNOWN_ERROR;
-	}
+        }
     }
     exit 0;
@@ -344,11 +342,11 @@
 die "ipp_cleanup.pl -stage $stage not yet implemented\n";
 
-sub delete_files 
+sub delete_files
 {
     my $files = shift; # reference to a list of files to unlink
-    
-    # this script is, of course, very dangerous.  
+
+    # this script is, of course, very dangerous.
     foreach my $file (@$files) {
-	print STDERR "unlinking $file\n";
+        print STDERR "unlinking $file\n";
         $ipprc->file_delete($file);
     }
@@ -356,5 +354,5 @@
 }
 
-sub addFilename 
+sub addFilename
 {
     my $files      = shift; # reference to a list of files to unlink
