Index: /tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_poll.pl
===================================================================
--- /tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_poll.pl	(revision 37287)
+++ /tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_poll.pl	(revision 37288)
@@ -67,5 +67,5 @@
     defined($job_id);
 
-my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id);
+my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id);
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
@@ -87,5 +87,5 @@
     unless ($success) {
 	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to run remotetool to determine remote run status", $remote_id,$error_code);
+	&my_die("Unable to run remotetool to determine remote run status", $remote_id, $error_code);
     }
 
@@ -94,8 +94,8 @@
 
     my $metadata = parse_md_list($MDlist);
-    $runData = $rrData2->[0]; # There should be only one
-}
-
-# Poll the job status?
+    $runData = $metadata->[0]; # There should be only one
+}
+
+# STEP 3: Poll the job status
 my $poll_response = 0;
 my $poll_word  = "nothing";
@@ -114,7 +114,5 @@
 }
 
-# Initialize the remote side to sync things
-my $uri_return = $path_base . ".return";
-my ($ipp_return, $remote_return) = uri_convert($uri_return);
+my $remote_path = uri_local_to_remote($path_base);
 
 # transfer tool should check the existence of files on the remote end
@@ -128,5 +126,5 @@
         $iter++;
         check_ssh_connection();
-        my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset");
+        my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_path --offset $offset");
         my $return_push_output_print = join "\n", @{ $return_push_output };
         if ($return_push_output_print =~ /exited with value 255/) { $transfer_success = 0; }
@@ -134,7 +132,39 @@
     } while (($transfer_success != 1) &&  ($iter < 10));  # Try harder;
 
-    if (!$transfer_success) { &my_die ("failed to get all return files"); }
-}
-print STDERR "rsync of all files is complete, updating gpc1 database\n";
+    if (!$transfer_success) { &my_die ("failed to get all return files", $remote_id, 23); }
+}
+print STDERR "rsync of all files is complete, checking the results\n";
+
+# grab the .stats file
+
+my $uri_stats    = $path_base . ".stats";
+my $disk_stats   = $ipprc->file_resolve($uri_stats);
+my $remote_stats = uri_local_to_remote($uri_stats);
+
+scp_get($remote_stats,$disk_stats);
+
+# check for PASS / PART / FAIL : if dbinfo is PASS, go ahead and execute that.  
+
+my $Npass = 0;
+my $Npart = 0;
+my $Nfail = 0;
+my @dbinfo_files   = ();
+open (STATFILE, "$disk_stats") || &my_die("Couldn't open file? $disk_stats", $remote_id, $PS_EXIT_SYS_ERROR);
+while (my $line = <RETURN>) {
+    chomp $line;
+    unless ($_ =~ /dbinfo/) { next; }
+
+    my @words = split (" ", $line);
+    if ($words[1] eq "PASS") {
+        push @dbinfo_files, $words[0];
+	$Npass ++;
+    } elsif ($words[1] eq "FAIL") {
+	$Nfail ++;
+    } elsif ($words[1] eq "PART") {
+	$Npart ++;
+    }
+}
+close(RETURN);
+print STDERR "dbinfo files: $Npass PASS, $Nfail FAIL, $Npart PART\n";
 
 foreach my $file (@dbinfo_files) {
@@ -143,10 +173,15 @@
     close(DBF);
     chomp($cmd);
-#    print STDERR "$file $cmd\n";
+
     $cmd =~ s/-/ -/g; # This is just a safety check for missing space.
+
+    if ($cmd == "") {
+	print STDERR "problem: empty dbinfo file\n";
+	next;
+    }
+
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         run(command => $cmd, verbose => $verbose);
     unless ($success) {
-
         # This shouldn't fail, but we also can't suddenly abort if something does fail.
         # Now we're going to drop the component that owns this dbinfo, which should force a retry.
@@ -154,5 +189,5 @@
         warn("The command that shouldn't fail has failed: $file $cmd $remote_id $error_code");
         if ($poll_word ne 'Completed') {  # If the job claims it completed, then we're fighting the network.
-            drop_component($remote_id,$cmd,$file);
+            fail_component($remote_id, $cmd, $file);
         }
     }
@@ -161,9 +196,7 @@
 
 # We're done, so set the state and exit.
-&my_die("Finished",$remote_id,0,"full");
-
+&my_die("Finished", $remote_id, 0, "full");
 
 # END PROGRAM
-
 
 sub check_ssh_connection {
@@ -289,4 +322,34 @@
 
     return($local_uri);
+}
+
+sub fail_component {
+    my $remote_id = shift;
+    my $cmd = shift;
+    my $file = shift;
+
+    # Steal the stage_id from the filename.  This isn't something I'm happy about.
+    my $stage = $runData->{stage};
+    my $stage_id = $file;
+    if ($stage eq 'chip') {
+	$stage_id =~ s/^.*ch\.//;
+    }
+    elsif ($stage eq 'camera') {
+	$stage_id =~ s/^.*cm\.//;
+    }
+    elsif ($stage eq 'warp') {
+	$stage_id =~ s/^.*wrp\.//;
+    }
+    elsif ($stage eq 'stack') {
+	$stage_id =~ s/^.*stk\.//;
+    }
+    $stage_id =~ s/\..*$//;
+    
+    print STDERR "failed component: $remote_id, $stage_id\n";
+    
+    # Drop this from the database
+    ## my $drop_cmd = "$remotetool -dropcomponent -remote_id $remote_id -stage_id $stage_id ";
+    ## $drop_cmd   .= " -dbname $dbname " if defined($dbname);
+    ## system($drop_cmd);
 }
 
@@ -329,5 +392,5 @@
     my $exit_code = shift;
     my $exit_state = shift;
-    my $jobid = shift;
+
     $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
 
