Index: /branches/eam_branch_00/ippTasks/phase2.pro
===================================================================
--- /branches/eam_branch_00/ippTasks/phase2.pro	(revision 11000)
+++ /branches/eam_branch_00/ippTasks/phase2.pro	(revision 11001)
@@ -6,4 +6,6 @@
 ## queue keys are counted from 0
 
+# XXX change book names to match ippTool values?
+# XXX replace with book init p2pending
 queueinit Phase2Imfiles
 if ($?network == 0)
@@ -47,30 +49,18 @@
   task.exec
     # command p2tool -pendingimfile -simple -limit {$Phase2ImfileFail + 20}
-    command p2tool -pendingimfile -simple
+    command p2tool -pendingimfile
   end
 
   # success
   task.exit    0
-    local i Nqueue
-
-    # save stdout and stderr
-
-    # compare output with Phase2Imfiles queue
-    # only add entries which don't exist in queue
-    queuesize stdout -var Nqueue
-    for i 0 $Nqueue
-      queuepop stdout -var line
-      if ($VERBOSE > 2)
-        echo $line
-      end
-      list word -split $line
-      $EXP_TAG  = $word:0
-      $CLASS_ID = $word:1
-      $URI      = $word:2
-      queuepush Phase2Imfiles -uniq -key 1:2 "NEW $EXP_TAG $CLASS_ID $URI"
+    # convert output to book format
+    # only add entries which don't exist in the book
+    ipptool2book stdout p2pending -key exp_tag:class_id -uniq
+    if ($VERBOSE > 2)
+      book listbook p2pending
     end
 
     # delete existing entries which are DONE
-    queuedrop Phase2Imfiles -key 0 DONE
+    book delpage p2pending -key state DONE
   end
 
@@ -93,23 +83,19 @@
 
   task.exec
-    queuesize Phase2Imfiles -var N
+    # XXX make equiv book command:
+    book npages p2pending -var N
     if ($N == 0) break
     if ($network == 0) break
     
-    # look for new images on the internal DetrendImfilesToProcess queue
+    # look for new images on the internal p2pending book
     # caution with these 'if' statements: syntax errors 
     # will make the task fail without given a good status
-    queuepop Phase2Imfiles -var line -key 0 NEW
-    if ("$line" == "NULL") break
+    # XXX pop off the bottom or the top?
+    book getpage p2pending 0 -var pageName
+    book setword p2pending $pageName status RUN
 
-    strpop line state
-    queuepush Phase2Imfiles -replace -key 1:2 "RUN $line"
-
-    ## the Phase2Imfiles queue contains (line has popped STATE)
-    ## STATE EXP_TAG CLASS CLASS_ID URI-FITS
-    list word -split $line
-    $EXP_TAG  = $word:0
-    $CLASS_ID = $word:1
-    $URI      = $word:2
+    book getword p2pending $pageName exp_tag -var EXP_TAG
+    book getword p2pending $pageName class_id -var CLASS_ID
+    book getword p2pending $pageName uri -var URI
 
     # specify choice of remote host:(need to choose based on chips)
@@ -122,4 +108,5 @@
     ## add 'p2' to the log files?
     # XXX this is still a lame rule
+    # make 'basename' an opihi function?
     $word = `basename $EXP_TAG | tr '.' ' '`
     list word -split $word
@@ -129,6 +116,8 @@
     exec mkdir -p $LOGSUBDIR/$base
 
+    # save the p2pending book pageName for future reference below
+    options $pageName
+
     # create the command line
-    options "$line"
     if ($VERBOSE > 1)
       echo command phase2.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI
@@ -141,5 +130,6 @@
   task.exit 0
     # phase2imfile.pl updates DB tables, here we just update the queue
-    queuepush Phase2Imfiles -replace -key 1:2 "DONE $options:0"
+    book setword p2pending $options:0 status DONE
+    # queuepush Phase2Imfiles -replace -key 1:2 "DONE $options:0"
   end
 
@@ -147,5 +137,6 @@
   task.exit    default
     showcommand failure
-    queuepush Phase2Imfiles -replace -key 1:2 "FAIL $options:0"
+    book setword p2pending $options:0 status FAIL
+    # queuepush Phase2Imfiles -replace -key 1:2 "FAIL $options:0"
     $Phase2ImfileFail ++
   end
@@ -154,5 +145,6 @@
   task.exit    timeout
     showcommand timeout
-    queuepush Phase2Imfiles -replace -key 1:2 "TIMEOUT $options:0"
+    book setword p2pending $options:0 status TIMEOUT
+    # queuepush Phase2Imfiles -replace -key 1:2 "TIMEOUT $options:0"
     $Phase2ImfileFail ++
   end
