Index: trunk/pstamp/scripts/pstampparse.pl
===================================================================
--- trunk/pstamp/scripts/pstampparse.pl	(revision 25776)
+++ trunk/pstamp/scripts/pstampparse.pl	(revision 25793)
@@ -72,4 +72,8 @@
 }
 
+# just deal with these arguments once and for all
+$pstamptool .= " -dbname $dbname" if $dbname;
+$pstamptool .= " -dbserver $dbserver" if $dbserver;
+
 # list_job is a deugging mode
 $no_update = 1 if $mode eq "list_job";
@@ -105,6 +109,4 @@
 if ($req_id and !$no_update) {
     my $command = "$pstamptool -listreq  -name $req_name -not_req_id $req_id";
-    $command .= " -dbname $dbname" if $dbname;
-    $command .= " -dbserver $dbserver" if $dbserver;
     # no verbose so that error message about request not found doesn't appear in parse_error.txt
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -127,6 +129,4 @@
     my $command = "$pstamptool -updatereq -req_id $req_id  -name $req_name";
     $command .= " -outProduct $product";
-    $command .= " -dbname $dbname" if $dbname;
-    $command .= " -dbserver $dbserver" if $dbserver;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         run(command => $command, verbose => $verbose);
@@ -398,14 +398,26 @@
         my $newState = "run";
         my $fault = 0;
-
-        if (($stage ne 'stack') and ($stage ne 'raw')) {
-            if (($image->{state} eq 'goto_purged') or ($image->{data_state} eq 'purged')) {
+        my $dep_id;
+
+        if ($stage ne 'raw') {
+            my $run_state = $image->{state};
+            my $data_state = $image->{data_state};
+            if (($run_state eq 'goto_purged') or ($data_state eq 'purged') or
+                ($run_state eq 'goto_scrubbed') or ($data_state eq 'scrubbed')) {
+                # image is gone and it's not coming back
                 $newState = 'stop';
                 $fault = $PSTAMP_GONE;
-            } elsif (($image->{data_state} ne 'full') or ($image->{state} ne 'full' )) {
-                # XXX here is where we need to queue an update job
-                # for now just say that the image is not available
-                $newState = 'stop';
-                $fault = $PSTAMP_NOT_AVAILABLE;
+            } elsif (($data_state ne 'full') or ($run_state ne 'full' )) {
+                my $PSTAMP_NO_UPDATE = 2048;
+                # for now just fault while I build pstampDependent
+                if ($option_mask & $PSTAMP_NO_UPDATE) {
+                    $newState = 'stop';
+                    $fault = $PSTAMP_NOT_AVAILABLE;
+                } else {
+                    # cause the image to be re-made
+                    # set up to queue an update run
+                    queue_update_run(\$newState, \$fault, \$dep_id, $image->{image_db}, 
+                        $run_state, $stage, $image->{stage_id}, $need_magic, $image->{label});
+                }
             }
         }
@@ -416,6 +428,5 @@
         $command .= " -fault $fault" if $fault;
         $command .= " -exp_id $exp_id" if $exp_id;
-        $command .= " -dbname $dbname" if $dbname;
-        $command .= " -dbserver $dbserver" if $dbserver;
+        $command .= " -dep_id $dep_id" if $dep_id;
 
         if ($mode eq "list_job") { 
@@ -594,6 +605,4 @@
     my $command = "$pstamptool -addjob  -req_id $req_id -job_type $job_type"
                         . " -rownum $rownum -state stop -fault $fault";
-    $command .= " -dbname $dbname" if $dbname;
-    $command .= " -dbserver $dbserver" if $dbserver;
 
     if ($mode eq "list_job") { 
@@ -718,4 +727,36 @@
 }
 
+sub queue_update_run 
+{
+    my ($r_jobState, $r_fault, $r_dep_id, $imagedb, $state, $stage, $stage_id, $need_magic, $label) = @_;
+
+    if (($state ne 'cleaned') and ($state ne 'update') and ($state ne 'goto_cleaned')) {
+        my_die("$stage $stage_id is in unexpected state $state", $PS_EXIT_PROG_ERROR);
+    }
+
+    my $dep_id;
+    my $command = "$pstamptool -getdependent -stage $stage -stage_id $stage_id -imagedb $imagedb";
+    $command .= " -rlabel $label" if $label;
+    $command .= " -no_magic" if !$need_magic;
+    if (!$no_update) {
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+        unless ($success) {
+            my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
+        }
+        my $output = join "", @$stdout_buf;
+        chomp $output;
+        $dep_id = $output;
+        my_die("pstamptool -getdependent returned invalid dep_id", $PS_EXIT_PROG_ERROR) if !$dep_id;
+    } else {
+        print STDERR "skipping $command\n";
+        $dep_id = 42;
+    }
+    
+    $$r_dep_id = $dep_id;
+    $r_fault = 0;
+    $r_jobState = 'blocked';
+}
+
 sub my_die
 {
