Index: trunk/pstamp/scripts/pstamp_job_run.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_job_run.pl	(revision 18543)
+++ trunk/pstamp/scripts/pstamp_job_run.pl	(revision 18544)
@@ -11,4 +11,13 @@
 use Sys::Hostname;
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use File::Basename;
+use Digest::MD5::File qw( file_md5_hex );
+
+# values for OPTION_MASK
+# XXX put these in a module
+use constant PSTAMP_SELECT_IMAGE  => 1;
+use constant PSTAMP_SELECT_MASK   => 2;
+use constant PSTAMP_SELECT_WEIGHT => 4;
+
 
 my $verbose;
@@ -92,4 +101,5 @@
 }
 
+my $rownum = $psjob->{rownum};
 my $uri = $psjob->{uri};
 my $outputBase = $psjob->{outputBase};
@@ -105,4 +115,33 @@
 
     if ($success) {
+        # XXX shouldn't need to do this, review schema`
+        my $dir = dirname($outputBase);
+
+        my $reglist = "$dir/reglist$job_id";
+
+        open F, ">$reglist" or die "can't open $reglist for output";
+
+        # we are assuming an interface with ppstamp here.
+        my @extensions = ( "fits", "mk.fits", "wt.fits");
+
+        # XXX TODO: add mask of expected file types to pstampJob so we know what to expect
+
+        my $output_mask = PSTAMP_SELECT_IMAGE;
+        my $m = 1;  # XXX we're getting a bit intimate with the bit field definitions here. do better use a hash
+        foreach my $extension (@extensions) {
+            my $do_this_one = $m & $output_mask;
+            $m = $m << 1;
+            next if (! $do_this_one);
+
+            my $basename = basename($outputBase);
+
+            my $filename = "${basename}.${extension}";
+            my $path  = "${outputBase}.${extension}";
+
+            # XXX is pstamp always the right file type, if not where can we get the right one?
+            print F file_registration_line($filename, $path, "pstamp") . "\n";
+        }
+
+        close F;
         $jobStatus = $PS_EXIT_SUCCESS;
     } else {
@@ -111,6 +150,6 @@
     }
 } elsif ($jobType eq "get_image") {
-    my $command = "$pstamp_get_image_job --uri $uri --out_dir $outputBase";
-    $command .= " -dbname $dbname" if $dbname;
+    my $command = "$pstamp_get_image_job --job_id $job_id --uri $uri --out_dir $outputBase --rownum $rownum";
+    $command .= " --dbname $dbname" if $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         run(command => $command, verbose => $verbose);
@@ -126,8 +165,7 @@
 }
 
-
 # stop the job and set the result value
 {
-    my $command = "$pstamptool -processedjob -job_id $job_id -state stop -result $jobStatus";
+    my $command = "$pstamptool -processedjob -job_id $job_id -state stop -fault $jobStatus";
     $command .= " -dbname $dbname" if $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -139,2 +177,19 @@
 
 exit $jobStatus;
+
+# XXX move this to a module so it can be shared
+sub file_registration_line {
+    my $filename = shift;
+    my $path     = shift;
+    my $filetype = shift;
+    if (-e $path) {
+        my @finfo = stat($path);
+        die "failed to stat $path" unless (@finfo);    # XXX clean up
+        my $bytes = $finfo[7];
+        my $md5sum = file_md5_hex($path);
+
+        return "$filename|$bytes|$md5sum|$filetype|";
+    } else {
+        die "$filename not found at $path";
+    }
+}
