Index: trunk/pstamp/scripts/dumpvars.sh
===================================================================
--- trunk/pstamp/scripts/dumpvars.sh	(revision 16283)
+++ 	(revision )
@@ -1,15 +1,0 @@
-#!/bin/bash
-
-echo "    Command Line Arguments:"
-
-echo $*
-
-echo " "
-echo "    Environment:"
-
-env
-
-echo " "
-echo "    Shell Variables:"
-
-set
Index: trunk/pstamp/scripts/ppstamp_run.pl
===================================================================
--- trunk/pstamp/scripts/ppstamp_run.pl	(revision 16283)
+++ trunk/pstamp/scripts/ppstamp_run.pl	(revision 16358)
@@ -15,5 +15,5 @@
 my $job_id = $ARGV[0];
 
-my $verbosity = 1;
+my $verbosity = 0;
 
 use Sys::Hostname;
@@ -125,3 +125,7 @@
 
 
-exit $jobStatus;
+if ($jobStatus eq "ok") {
+    exit 0;
+} else {
+    exit $jobStatus;
+}
Index: trunk/pstamp/scripts/pstamp_dorequest.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_dorequest.pl	(revision 16283)
+++ trunk/pstamp/scripts/pstamp_dorequest.pl	(revision 16358)
@@ -1,8 +1,8 @@
 #!/bin/env perl
 ###
-### pstampdo_req.pl
+### pstamp_dorequest.pl
 ###
-###     Run the jobs for a given request
-###     This is intended for running outside pantasks environment
+###     Excecute the jobs for a given request.
+###     Note: This is intended for testing outside of pantasks environment
 ###
 
@@ -16,5 +16,5 @@
 my $request_id = $ARGV[0];
 
-my $verbosity = 1;
+my $verbosity = 0;
 
 use Sys::Hostname;
@@ -77,6 +77,5 @@
     foreach my $job (@$jobs) {
         if ($job->{req_id} == $request_id) {
-            # there must be a better way to do this
-            print STDERR "adding $job->{job_id} to the list\n";
+            # print STDERR "adding $job->{job_id} to the list\n";
             $psjobs[@psjobs] = $job;
         }
@@ -85,6 +84,6 @@
 
 if (! @psjobs) {
+    # TODO: is this always an error, what if the job is no longer pending?
     print STDERR "no pending postage stamp jobs for request $request_id found\n";
-    # TODO: is this always an error, what if the job is no longer pending?
     exit 1;
 }
@@ -103,4 +102,13 @@
 # Update the state of the request
 #
+{
+    ## TODO: what about request status
+    my $command = "$pstamptool -processedreq -req_id $request_id -state stop"; 
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbosity);
+    unless ($success) {
+        die("Unable to perform pstamptool -processedreq: $error_code");
+    }
+}
 
 exit 0;
Index: trunk/pstamp/scripts/pstamp_listjobs.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_listjobs.pl	(revision 16358)
+++ trunk/pstamp/scripts/pstamp_listjobs.pl	(revision 16358)
@@ -0,0 +1,89 @@
+#!/bin/env perl
+###
+### pstamp_listjobs.pl
+### list the job_id, state, and uri for the postage stamp jobs queued for a given 
+### postage stamp request id
+###
+
+use warnings;
+use strict;
+
+if (@ARGV != 1) {
+    die "usage: $0 request_id\n";
+}
+
+my $request_id = $ARGV[0];
+
+my $verbosity = 0;
+
+use Sys::Hostname;
+my $host = hostname();
+
+## This isn't a script to be launched by pantasks we probably want go get rid of this
+if ($verbosity) {
+    print STDERR "\n\n";
+    print STDERR "Starting script $0 on $host\n\n";
+}
+
+use IPC::Cmd 0.36 qw( can_run run );
+
+use PS::IPP::Metadata::Config;
+use PS::IPP::Metadata::Stats;
+use PS::IPP::Metadata::List qw( parse_md_list );
+
+use PS::IPP::Config qw($PS_EXIT_SUCCESS
+		       $PS_EXIT_UNKNOWN_ERROR
+		       $PS_EXIT_SYS_ERROR
+		       $PS_EXIT_CONFIG_ERROR
+		       $PS_EXIT_PROG_ERROR
+		       $PS_EXIT_DATA_ERROR
+		       $PS_EXIT_TIMEOUT_ERROR
+		       metadataLookupStr
+		       metadataLookupBool
+		       caturi
+		       );
+
+my $missing_tools;
+
+my $pstamptool  = can_run('pstamptool')  or (warn "Can't find pstamptool"  and $missing_tools = 1);
+my $ppstamp_run = can_run('ppstamp_run.pl') or (warn "Can't find ppstamp_run.pl" and $missing_tools = 1);
+
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit ($PS_EXIT_CONFIG_ERROR);
+}
+
+my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
+
+my @psjobs;
+#Look up the jobs for the given request_id
+{
+    my $command = "$pstamptool -listjob -req_id $request_id";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbosity);
+    unless ($success) {
+        die("Unable to perform pstamptool -pendingreq: $error_code");
+    }
+
+    if (@$stdout_buf == 0) {
+        print STDERR "no pstamp jobs for request $request_id\n";
+        exit 1;
+    }
+    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
+        die("Unable to parse metdata config doc");
+
+    my $jobs = parse_md_list($metadata);
+
+    @psjobs = @$jobs;
+}
+
+if (! @psjobs) {
+    print STDERR "no postage stamp jobs for request $request_id found\n";
+    exit 1;
+}
+
+foreach my $job (@psjobs) {
+    print "$job->{job_id} $job->{state} $job->{outputBase}.fits\n";
+}
+
+exit 0;
Index: trunk/pstamp/scripts/pstamp_runcommand.sh
===================================================================
--- trunk/pstamp/scripts/pstamp_runcommand.sh	(revision 16358)
+++ trunk/pstamp/scripts/pstamp_runcommand.sh	(revision 16358)
@@ -0,0 +1,70 @@
+#!/bin/sh
+###
+#
+# pstampwrapper.sh: 
+# Set up the ipp environment to run a ipp commands on behalf of hte postage stamp
+# server and execute the command given by the argument list 
+
+if [[ $# == 0 ]] ;then
+    echo "usage $0 command" >&2
+    #  EINVAL = 22
+    exit 22
+fi
+
+#### BEGIN LOCAL_CONFIGURATION
+
+# These variables need to be customized for a particular installation
+export PSCONFDIR=/export/data0/bills/psconfig
+
+# TODO shouldn't need to do this but there seems to be a psconfig problem.
+# Gene fixed this recently
+#export LD_LIBRARY_PATH=/usr/local/lib
+
+WORK_DIR=/export/data1/bills/pstamp/work
+CMD_DIR=/export/data0/bills/src/ipp/pstamp/scripts
+
+#### END LOCAL_CONFIGURATION
+
+export HOME=$WORK_DIR
+
+cd $WORK_DIR
+status=$?
+if [[ ! $status ]] ; then
+    echo $0 cannot cd to WORK_DIR: $WORK_DIR status: $status >&2
+    exit $status
+fi
+
+# TODO: I do this so that I have permissions to modify the files created by 
+# the web server user apache.
+#umask 0
+
+###
+### configure IPP
+###
+#export MANPATH=""
+
+source $PSCONFDIR/psconfig.bash default
+status=$?
+if [[ ! $status ]] ; then
+    echo error setting up IPP environment >&2
+    exit $status
+fi
+
+###
+### Add our command directory to the path. 
+### TODO: This won't be necessary once the scripts get installed as part of the IPP
+###
+PATH=${CMD_DIR}:${PATH}
+
+## This test is sort of redundant. 
+## We'll get a more useful error by just going ahead and trying the command
+## or by not suppressing the output from which
+if [[ ! -x `which $1 2> /dev/null` ]] ;then
+    status=$?
+    echo command $1 not found >&2
+    exit $status
+fi
+
+#### Finally, execute the command given by the command line arguments
+
+$*
Index: trunk/pstamp/scripts/pstamp_webrequest.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_webrequest.pl	(revision 16358)
+++ trunk/pstamp/scripts/pstamp_webrequest.pl	(revision 16358)
@@ -0,0 +1,124 @@
+#!/bin/env perl
+###
+#
+# pstampwebrequest.sh: take a postage stamp request command line and process it
+#
+# The arguments are the command line parameters for the program pstamprequest
+#
+# The output is the list of uris for the resulting postage stamp files 
+# unless the argument -list is provided.
+#
+# In that case the selected "input" uris are listed on stdout
+#
+# Note: there's nothing really web specific about this program.
+#       with the exception that we set up the environment to allow a 
+#       random user (in this case apache ) to run ipp programs
+#
+#
+###
+
+use warnings;
+use strict;
+
+my $verbosity = 0;
+
+use Sys::Hostname;
+my $host = hostname();
+
+if ($verbosity) {
+    print "\n\n";
+    print "Starting script $0 on $host\n\n";
+}
+
+use IPC::Cmd 0.36 qw( can_run run );
+
+use PS::IPP::Config qw($PS_EXIT_SUCCESS
+		       $PS_EXIT_UNKNOWN_ERROR
+		       $PS_EXIT_SYS_ERROR
+		       $PS_EXIT_CONFIG_ERROR
+		       $PS_EXIT_PROG_ERROR
+		       $PS_EXIT_DATA_ERROR
+		       $PS_EXIT_TIMEOUT_ERROR
+		       metadataLookupStr
+		       metadataLookupBool
+		       caturi
+		       );
+
+my $missing_tools;
+
+my $pstamprequest = can_run('pstamprequest')  or (warn "Can't find pstamprequest"  and $missing_tools = 1);
+my $pstamptool = can_run('pstamptool')  or (warn "Can't find pstamptool"  and $missing_tools = 1);
+my $pstampparse = can_run('pstampparse')  or (warn "Can't find pstampparse"  and $missing_tools = 1);
+my $pstampparser_run = can_run('pstampparser_run.pl')  or (warn "Can't find pstampparser_run.pl"  and $missing_tools = 1);
+
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit ($PS_EXIT_CONFIG_ERROR);
+}
+
+
+# if -list is used, it must be the first argument
+my $listMode;
+if ($ARGV[0] eq "-list" ) {
+    $listMode=1;
+} else  {
+    $listMode=0;
+}
+
+my $request_file = "request_file.$$.fits";
+{
+    my $command = "$pstamprequest $request_file @ARGV";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbosity);
+    unless ($success) {
+        print STDERR "@$stderr_buf\n";
+        die("Unable to perform pstamprequest: $error_code");
+    }
+}
+
+
+# ok at this point we have a request file add it to the database (unless we're in listMode)
+if ($listMode == 1 ) {
+    ###
+    ### In list mode just parse the file print the output and we're done
+    ###
+    my $command = "$pstampparse $request_file";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbosity);
+    unless ($success) {
+        die("Unable to perform pstampparse: $error_code");
+    }
+    ### print "Matching Images:\n";
+    print "@$stdout_buf";
+    exit 0;
+}
+
+# Queue the request
+my $request_id = 0;
+{
+
+    my $command = "$pstamptool -addreq -uri $request_file";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbosity);
+    unless ($success) {
+        print STDERR "@$stderr_buf\n";
+        die("Unable to perform pstamptool -addreq: $error_code");
+    }
+    $request_id = ${$stdout_buf}[0];
+}
+
+# parse the file to queue the jobs
+{
+    my $command = "$pstampparser_run $request_id";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbosity);
+    unless ($success) {
+        print STDERR "@$stderr_buf\n";
+        die("Unable to perform pstamparser_run -addreq: $error_code");
+    }
+}
+
+#                   note: $request_id still has a newline
+print "$request_id";
+
+exit 0;
Index: trunk/pstamp/scripts/pstampwebrequest.sh
===================================================================
--- trunk/pstamp/scripts/pstampwebrequest.sh	(revision 16283)
+++ 	(revision )
@@ -1,209 +1,0 @@
-#!/bin/bash
-###
-#
-# pstampwebrequest.sh: take a postage stamp request command line and process it
-#
-# The arguments are the command line parameters for the program pstamprequest
-#
-# The output is the list of uris for the resulting postage stamp files 
-# unless the argument -list is provided.
-#
-# In that case the selected "input" uris are listed on stdout
-#
-# Note: there's nothing really web specific about this program.
-#       with the exception that we set up the environment to allow a 
-#       random user (in this case apache ) to run ipp programs
-#
-# TODO: re-write this in perl
-#
-###
-
-function cleanup() {
-    if [[ $do_cleanup != 0 ]] ; then
-        rm -f $request_out $request_err $parse_out $parse_err $stamp_err $stamp_out
-        ### rm -f $request_file
-    fi
-}
-
-function dump_variables {
-    if [[ $do_vardump != 0 ]] ; then
-        echo $1':' >> $variable_dump
-        $CMD_DIR/dumpvars.sh >> $variable_dump
-        echo '-----------------------------------------------------------------------' >> $variable_dump
-        echo ""
-    fi
-}
-    
-
-# if do_cleanup is true we delete the temporary files that we create
-do_cleanup=0
-
-# if do_vardump is true we print enviornment and shell variables to a
-# file for debugging purposes
-do_vardump=0
-
-#### BEGIN LOCAL_CONFIGURATION
-
-# These variables need to be customized for a particular installation
-export PSCONFDIR=/export/data0/bills/psconfig
-
-# TODO shouldn't need to do this but there seems to be a psconfig problem.
-export LD_LIBRARY_PATH=/usr/local/lib
-
-WORK_DIR=/export/data1/bills/pstamp/work
-CMD_DIR=/export/data0/bills/src/ipp/pstamp/scripts
-
-#### END LOCAL_CONFIGURATION
-
-export HOME=$WORK_DIR
-
-# TODO: make sure this succeeds before proceeding
-cd $WORK_DIR
-
-# TODO: I do this so that I have permissions to modify the files created by 
-# the web server user apache.
-umask 0
-
-variable_dump=variable_dump.$$
-rm -f $variable_dump
-
-dump_variables BEFORE
-
-
-###
-### configure IPP
-###
-export MANPATH=""
-
-source $PSCONFDIR/psconfig.bash default
-
-###
-### Add our command directory to the path. This won't be necessary once the scripts get
-### installed in the IPP
-###
-PATH=${CMD_DIR}:${PATH}
-
-# if -list is used, it must be the first argument
-if [[ "$1" == "-list" ]] ; then
-    #echo List Mode
-    listMode=1
-else 
-    listMode=0
-fi
-
-dump_variables AFTER
-
-out_ext=$$.out
-err_ext=$$.err
-
-request_file=request_file.$$.fits
-request_out=req.${out_ext}
-request_err=req.${err_ext}
-
-###
-### Well after all that setup we're ready to get to work.
-### Pass the command line parameters to pstamprequest to build the request file
-
-pstamprequest $* $request_file 1> $request_out 2> $request_err
-if [[ $? != 0 ]] ;then
-    echo pstamprequest failed
-    cat $request_err
-    cleanup
-    exit 1;
-fi
-
-rm $request_out $request_err
-
-# ok at this point we have a request file add it to the database (unless we're in listMode
-if [[ $listMode == 0 ]]; then
-    pstamptool -addreq -uri ${PWD}/$request_file 1> $request_out 2> $request_err
-    if [[ $? != 0 ]] ;then
-        echo pstamptool failed
-        cat $request_err
-        cleanup
-        exit 1
-    fi
-
-    # pstamptool's only output is the request id
-    tmp_id=`cat $request_out`
-    # zap the newline
-    request_id=${tmp_id% \n}
-fi
-
-parse_out=parse.${out_ext}
-parse_err=parse.${err_ext}
-
-if [[ $listMode == 1 ]]; then
-    ###
-    ### In list mode just parse the file print the output and we're done
-    ###
-    pstampparse $request_file 1> $parse_out 2> $parse_err
-    if [[ $? != 0 ]] ;then
-        echo ppstampparse failed
-        echo ""
-        echo STDERR:
-        cat $parse_err
-        echo ""
-        echo STDOUT:
-        cat $parse_out
-        cleanup
-        exit 2;
-    fi
-
-    # in list mode so just cat the output file and we're done
-    echo Matching Images:
-    cat $parse_out
-    cleanup
-    exit 0
-fi
-
-###
-### TODO: Until we have pantasks monitoring the reuest and job table
-### run things directly
-
-
-###
-### Queue the jobs for the request
-###
-pstampparser_run.pl $request_id  1> $parse_out 2> $parse_err
-if [[ $? != 0 ]] ;then
-    echo ppstampparse failed
-    echo ""
-    echo STDERR:
-    cat $parse_err
-    echo ""
-    echo STDOUT:
-    cat $parse_out
-    cleanup
-    exit 2
-fi
-
-###
-### Ok now it's time to build the stamps
-###
-
-stamp_out=stamp.${out_ext}
-stamp_err=stamp.${err_ext}
-
-echo making stamps for request> $stamp_err
-
-###
-### Make the stamps by executing each of the jobs
-###
-pstamp_dorequest.pl $request_id 1>$stamp_out 2>>$stamp_err
-if [[ $? != 0 ]]; then
-    echo pstamp_do_request.pl failed
-    echo STDERR:
-    cat $stamp_err
-    echo STDOUT:
-    cat $stamp_out
-    cleanup
-    exit 3
-fi
-
-# Success print the urls
-pstamptool -listjob -req_id $request_id -simple | awk '{ print $6 ".fits" }'
-
-cleanup
-
-exit 0
