Index: trunk/ippTasks/Makefile.am
===================================================================
--- trunk/ippTasks/Makefile.am	(revision 23232)
+++ trunk/ippTasks/Makefile.am	(revision 23248)
@@ -20,4 +20,5 @@
 	summit.copy.pro \
 	replicate.pro \
+	dist.pro \
 	pstamp.pro
 
Index: trunk/ippTasks/dist.pro
===================================================================
--- trunk/ippTasks/dist.pro	(revision 23248)
+++ trunk/ippTasks/dist.pro	(revision 23248)
@@ -0,0 +1,266 @@
+## dist.pro : support for the production of distribution bundles : -*- sh -*-
+
+# test for required global variables
+check.globals
+
+#$LOGSUBDIR = $LOGDIR/dist
+#exec mkdir -p $LOGSUBDIR
+
+### Initialise the books containing the tasks to do
+book init distToProcess
+book init distToAdvance
+
+### Database lists
+$distToProcess_DB = 0
+$distToAdvance_DB = 0
+
+### Check status of tasks
+macro dist.status
+  book listbook distToProcess
+  book listbook distToAdvance
+end
+
+### Reset tasks
+macro dist.reset
+  book init distToProcess
+  book init distToAdvance
+end
+
+### Turn tasks on
+macro dist.on
+  task dist.process.load
+    active true
+  end
+  task dist.process.run
+    active true
+  end
+  task dist.advance.load
+    active true
+  end
+  task dist.advance.run
+    active true
+  end
+end
+macro dist.off
+  task dist.process.load
+    active false
+  end
+  task dist.process.run
+    active false
+  end
+  task dist.advance.load
+    active false
+  end
+  task dist.advance.run
+    active false
+  end
+end
+
+task	       dist.process.load
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGDIR/dist.process.log
+
+  task.exec
+    $run = disttool -pendingcomponent
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$distToProcess_DB
+      $run = $run -dbname $DB:$distToProcess_DB
+      $distToProcess_DB ++
+      if ($distToProcess_DB >= $DB:n) set distToProcess_DB = 0
+    end
+    add_poll_args run
+    command $run
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout distToProcess -key dist_id:component -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook distToProcess
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup distToProcess
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+task	       dist.process.run
+  periods      -poll $RUNPOLL
+  periods      -exec $RUNEXEC
+  periods      -timeout 60
+
+  task.exec
+    book npages distToProcess -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+    
+    # look for new components to process (pantaskState == INIT)
+    book getpage distToProcess 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword distToProcess $pageName pantaskState RUN
+    book getword distToProcess $pageName dist_id -var DIST_ID
+    book getword distToProcess $pageName camera -var CAMERA
+    book getword distToProcess $pageName stage -var STAGE
+    book getword distToProcess $pageName stage_id -var STAGE_ID
+    book getword distToProcess $pageName component -var COMPONENT
+    book getword distToProcess $pageName path_base -var PATH_BASE
+    book getword distToProcess $pageName chip_path_base -var CHIP_PATH_BASE
+    book getword distToProcess $pageName state -var STATE
+    book getword distToProcess $pageName data_state -var DATA_STATE
+    book getword distToProcess $pageName magicked -var MAGICKED
+    book getword distToProcess $pageName outroot -var OUTROOT
+    book getword distToProcess $pageName dbname -var DBNAME
+
+#    set.host.for.camera $CAMERA $MAGIC_ID
+#    set.workdir.by.camera $CAMERA $MAGIC_ID $WORKDIR_TEMPLATE $default_host WORKDIR
+    host anyhost
+
+    sprintf logfile "%s/dist.%s.%s.log" $OUTROOT $DIST_ID $COMPONENT
+
+    $run = dist_component.pl --dist_id $DIST_ID --camera $CAMERA --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --path_base $PATH_BASE --chip_path_base $CHIP_PATH_BASE --state $STATE --data_state $DATA_STATE --magicked $MAGICKED --outroot $OUTROOT --logfile $logfile
+
+    add_standard_args run
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command $run
+    end
+    command $run
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit distToProcess $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword distToProcess $options:0 pantaskState TIMEOUT
+  end
+end
+
+
+task	       dist.advance.load
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGDIR/dist.advance.load.log
+
+  task.exec
+    $run = disttool -toadvance
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$distToAdvance_DB
+      $run = $run -dbname $DB:$distToAdvance_DB
+      $distToAdvance_DB ++
+      if ($distToAdvance_DB >= $DB:n) set distToAdvance_DB = 0
+    end
+    add_poll_args run
+    command $run
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout distToAdvance -key dist_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook distToAdvance
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup distToAdvance
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+task	       dist.advance.run
+  periods      -poll $RUNPOLL
+  periods      -exec $RUNEXEC
+  periods      -timeout 60
+
+  task.exec
+    book npages distToAdvance -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+    
+    # look for new components to process (pantaskState == INIT)
+    book getpage distToAdvance 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword distToAdvance $pageName pantaskState RUN
+    book getword distToAdvance $pageName dist_id -var DIST_ID
+    book getword distToAdvance $pageName stage   -var STAGE
+    book getword distToAdvance $pageName stage_id -var STAGE_ID
+    book getword distToAdvance $pageName outroot -var OUTROOT
+
+    host anyhost
+
+    sprintf logfile "%s/dist.advance.%s.log" $OUTROOT $DIST_ID
+
+    $run = dist_advancerun.pl --dist_id $DIST_ID --stage $STAGE --stage_id $STAGE_ID --outroot $OUTROOT --logfile $logfile
+    add_standard_args run
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command $run
+    end
+    command $run
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit distToAdvance $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword distToAdvance $options:0 pantaskState TIMEOUT
+  end
+end
+
