Index: trunk/ippTools/src/addtool.c
===================================================================
--- trunk/ippTools/src/addtool.c	(revision 25789)
+++ trunk/ippTools/src/addtool.c	(revision 25816)
@@ -40,9 +40,4 @@
 static bool maskedMode(pxConfig *config);
 static bool unblockMode(pxConfig *config);
-static bool pendingcleanuprunMode(pxConfig *config);
-static bool pendingcleanupexpMode(pxConfig *config);
-static bool donecleanupMode(pxConfig *config);
-static bool exportrunMode(pxConfig *config);
-static bool importrunMode(pxConfig *config);
 
 # define MODECASE(caseName, func) \
@@ -74,9 +69,4 @@
         MODECASE(ADDTOOL_MODE_MASKED,               maskedMode);
         MODECASE(ADDTOOL_MODE_UNBLOCK,              unblockMode);
-        MODECASE(ADDTOOL_MODE_PENDINGCLEANUPRUN,    pendingcleanuprunMode);
-        MODECASE(ADDTOOL_MODE_PENDINGCLEANUPEXP,    pendingcleanupexpMode);
-        MODECASE(ADDTOOL_MODE_DONECLEANUP,          donecleanupMode);
-        MODECASE(ADDTOOL_MODE_EXPORTRUN,            exportrunMode);
-        MODECASE(ADDTOOL_MODE_IMPORTRUN,            importrunMode);
         default:
             psAbort("invalid option (this should not happen)");
@@ -118,10 +108,11 @@
     }
 
-    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", false, false);
-    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
-    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
-    PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false);
-    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
-    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+    PXOPT_LOOKUP_STR(workdir,     config->args, "-set_workdir", false, false);
+    PXOPT_LOOKUP_STR(dvodb,       config->args, "-set_dvodb", false, false);
+    PXOPT_LOOKUP_STR(label,       config->args, "-set_label", false, false);
+    PXOPT_LOOKUP_STR(reduction,   config->args, "-set_reduction", false, false);
+    PXOPT_LOOKUP_BOOL(image_only, config->args, "-image_only", false);
+    PXOPT_LOOKUP_BOOL(pretend,    config->args, "-pretend", false);
+    PXOPT_LOOKUP_BOOL(simple,     config->args, "-simple", false);
 
     // find the cam_id of all the exposures that we want to queue up.
@@ -170,4 +161,29 @@
     }
 
+    // loop over our list of camRun rows to check the supplied and selected dvodb and workdir values:
+    for (long i = 0; i < psArrayLength(output); i++) {
+        psMetadata *md = output->data[i];
+
+        camRunRow *row = camRunObjectFromMetadata(md);
+        if (!row) {
+            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
+            psFree(output);
+            return false;
+        }
+
+        if (!dvodb && !row->dvodb) {
+            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, cam_id %" PRId64, row->label, row->cam_id);
+            psFree(output);
+            return false;
+        }
+        if (!workdir && !row->workdir) {
+            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, cam_id %" PRId64, row->label, row->cam_id);
+            psFree(output);
+            return false;
+        }
+
+        psFree(row);
+    }
+
     // start a transaction so we don't end up with an exp without any associted
     // imfiles
@@ -183,6 +199,5 @@
     // old values in place (i.e., passing the values through).
 
-
-    // loop over our list of addRun rows
+    // loop over our list of camRun rows
     for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
@@ -190,5 +205,5 @@
         camRunRow *row = camRunObjectFromMetadata(md);
         if (!row) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into addRun");
+            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
             psFree(output);
             return false;
@@ -199,8 +214,8 @@
 			       row->cam_id,
 			       workdir     ? workdir   : row->workdir,
+			       reduction   ? reduction : row->reduction,
 			       label       ? label     : row->label,
-			       "RECIPE",
-			       dvodb       ? dvodb     : row->dvodb
-			       
+			       dvodb       ? dvodb     : row->dvodb,
+			       image_only
         )) {
             if (!psDBRollback(config->dbh)) {
@@ -234,5 +249,4 @@
     PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id", "==");
     pxcamGetSearchArgs (config, where); // most search arguments based on camera
-
     PXOPT_COPY_STR(config->args, where, "-label",     "addRun.label", "==");
     PXOPT_COPY_STR(config->args, where, "-state",     "addRun.state", "==");
@@ -287,5 +301,4 @@
     pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "==");
     PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");
-
     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
@@ -349,8 +362,7 @@
 
     // optional
-    PXOPT_LOOKUP_F32(dtime_addstar, config->args,  "-dtime_addstar", false, false);
-    PXOPT_LOOKUP_S32(n_stars, config->args,        "-n_stars", false, false);
-    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false);
-    PXOPT_LOOKUP_S64(magicked, config->args, "-magicked", false, false);
+    PXOPT_LOOKUP_STR(path_base,     config->args, "-path_base", false, false);
+    PXOPT_LOOKUP_F32(dtime_addstar, config->args, "-dtime_addstar", false, false);
+    PXOPT_LOOKUP_S16(fault,         config->args, "-fault", false, false);
 
     // generate restrictions
@@ -401,7 +413,6 @@
         pendingRow->add_id,
         dtime_addstar,
-        n_stars,
         path_base,
-	0
+	fault
         );
 
@@ -418,5 +429,5 @@
 
     // since there is only one exp per 'new' set addRun.state = 'full'
-    if (!pxaddRunSetState(config, row->add_id, "full", magicked)) {
+    if (!pxaddRunSetState(config, row->add_id, "full")) {
         psError(PS_ERR_UNKNOWN, false, "failed to change addRun.state for add_id: %" PRId64, row->add_id);
         psFree(row);
@@ -439,8 +450,4 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
-
-    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
-    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
 
     // generate restrictions
@@ -451,4 +458,8 @@
     pxAddLabelSearchArgs (config, where, "-label",    "addRun.label",     "==");
     PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");
+
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
 
     if (!psListLength(where->list) &&
@@ -628,9 +639,8 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
-
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_S64(config->args, where, "-add_id",   "add_id",   "==");
     PXOPT_COPY_S64(config->args, where, "-cam_id",  "cam_id",  "==");
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
 
     if (!pxSetFaultCode(config->dbh, "addProcessedExp", where, fault)) {
@@ -713,324 +723,2 @@
     return true;
 }
-
-static bool pendingcleanuprunMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
-    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-
-    psMetadata *where = psMetadataAlloc();
-    pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "==");
-
-    psString query = pxDataGet("addtool_pendingcleanuprun.sql");
-    if (!query) {
-        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-        return false;
-    }
-
-    if (where && psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
-    }
-    psFree(where);
-
-    // treat limit == 0 as "no limit"
-    if (limit) {
-        psString limitString = psDBGenerateLimitSQL(limit);
-        psStringAppend(&query, " %s", limitString);
-        psFree(limitString);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psTrace("addtool", PS_LOG_INFO, "no rows found");
-        psFree(output);
-        return true;
-    }
-
-    // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "addPendingCleanupRun", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print array");
-        psFree(output);
-        return false;
-    }
-
-    psFree(output);
-
-    return true;
-}
-
-
-static bool pendingcleanupexpMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-    PXOPT_LOOKUP_S64(add_id, config->args, "-add_id", false, false);
-    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
-    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-
-    psMetadata *where = psMetadataAlloc();
-    if (add_id) {
-        PXOPT_COPY_S64(config->args, where, "-add_id", "add_id", "==");
-    }
-    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
-
-    psString query = pxDataGet("addtool_pendingcleanupexp.sql");
-    if (!query) {
-        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-        return false;
-    }
-
-    if (where && psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
-    }
-    psFree(where);
-
-    // treat limit == 0 as "no limit"
-    if (limit) {
-        psString limitString = psDBGenerateLimitSQL(limit);
-        psStringAppend(&query, " %s", limitString);
-        psFree(limitString);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psTrace("chiptool", PS_LOG_INFO, "no rows found");
-        psFree(output);
-        return true;
-    }
-
-    // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "addPendingCleanupExp", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print array");
-        psFree(output);
-        return false;
-    }
-
-    psFree(output);
-
-    return true;
-}
-
-
-static bool donecleanupMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
-    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-
-    psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
-
-    psString query = pxDataGet("addtool_donecleanup.sql");
-    if (!query) {
-        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-        return false;
-    }
-
-    if (where && psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
-    }
-    psFree(where);
-
-    // treat limit == 0 as "no limit"
-    if (limit) {
-        psString limitString = psDBGenerateLimitSQL(limit);
-        psStringAppend(&query, " %s", limitString);
-        psFree(limitString);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psTrace("addtool", PS_LOG_INFO, "no rows found");
-        psFree(output);
-        return true;
-    }
-
-    // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "addDoneCleanup", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print array");
-        psFree(output);
-        return false;
-    }
-
-    psFree(output);
-
-    return true;
-}
-
-bool exportrunMode(pxConfig *config)
-{
-  typedef struct ExportTable {
-    char tableName[80];
-    char sqlFilename[80];
-  } ExportTable;
-
-  int numExportTables = 2;
-
-  PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-  PXOPT_LOOKUP_S64(det_id, config->args, "-add_id", true,  false);
-  PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true,  false);
-  PXOPT_LOOKUP_U64(limit,   config->args, "-limit",   false, false);
-  PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
-
-  FILE *f = fopen (outfile, "w");
-  if (f == NULL) {
-    psError(PS_ERR_UNKNOWN, false, "failed to open output file");
-    return false;
-  }
-
-  psMetadata *where = psMetadataAlloc();
-  PXOPT_COPY_S64(config->args, where, "-add_id", "add_id", "==");
-
-  ExportTable tables [] = {
-    {"addRun", "addtool_export_run.sql"},
-    {"addProcessedExp", "addtool_export_processed_exp.sql"},
-  };
-
-  for (int i=0; i < numExportTables; i++) {
-    psString query = pxDataGet(tables[i].sqlFilename);
-    if (!query) {
-      psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-      return false;
-    }
-
-    if (where && psListLength(where->list)) {
-      psString whereClause = psDBGenerateWhereSQL(where, NULL);
-      psStringAppend(&query, " %s", whereClause);
-      psFree(whereClause);
-    }
-
-    // treat limit == 0 as "no limit"
-    if (limit) {
-      psString limitString = psDBGenerateLimitSQL(limit);
-      psStringAppend(&query, " %s", limitString);
-      psFree(limitString);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-      psError(PS_ERR_UNKNOWN, false, "database error");
-      psFree(query);
-      return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-      psError(PS_ERR_UNKNOWN, false, "database error");
-      return false;
-    }
-    if (!psArrayLength(output)) {
-      psError(PS_ERR_UNKNOWN, true, "no rows found");
-      psFree(output);
-      return false;
-    }
-
-    if (clean) {
-        if (!strcmp(tables[i].tableName, "addRun")) {
-            if (!pxSetStateCleaned("addRun", "state", output)) {
-                psFree(output);
-                psError(PS_ERR_UNKNOWN, false, "pxSetStateClean failed for table %s",  tables[i].tableName);
-                return false;
-            }
-        }
-    }
-
-    // we must write the export table in non-simple (true) format
-    if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) {
-      psError(PS_ERR_UNKNOWN, false, "failed to print array");
-      psFree(output);
-      return false;
-    }
-    psFree(output);
-  }
-
-  fclose (f);
-
-  return true;
-}
-
-bool importrunMode(pxConfig *config)
-{
-  unsigned int nFail;
-
-  PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-  PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
-
-  psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
-
-  fprintf (stdout, "---- input ----\n");
-  psMetadataPrint (stderr, input, 1);
-
-  psMetadataItem *item = psMetadataLookup (input, "addRun");
-  psAssert (item, "entry not in input?");
-  psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
-
-  psMetadataItem *entry = psListGet (item->data.list, 0);
-  assert (entry);
-  assert (entry->type == PS_DATA_METADATA);
-  addRunRow *addRun = addRunObjectFromMetadata (entry->data.md);
-  addRunInsertObject (config->dbh, addRun);
-
-  // fprintf (stdout, "---- add run ----\n");
-  // psMetadataPrint (stderr, entry->data.md, 1);
-
-  item = psMetadataLookup (input, "addProcessedExp");
-  psAssert (item, "entry not in input?");
-  psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
-
-  for (int i = 0; i < item->data.list->n; i++) {
-    psMetadataItem *entry = psListGet (item->data.list, i);
-    assert (entry);
-    assert (entry->type == PS_DATA_METADATA);
-    addProcessedExpRow *addProcessedExp = addProcessedExpObjectFromMetadata (entry->data.md);
-    addProcessedExpInsertObject (config->dbh, addProcessedExp);
-
-    // fprintf (stdout, "---- row %d ----\n", i);
-    // psMetadataPrint (stderr, entry->data.md, 1);
-  }
-
-  return true;
-}
