Index: branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_todestreak_raw.sql
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_todestreak_raw.sql	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_todestreak_raw.sql	(revision 30812)
@@ -24,5 +24,5 @@
     re_place,
     remove,
-    10000 AS priority
+    IFNULL(Label.priority, 10000) AS priority
 FROM magicDSRun
 JOIN magicMask USING (magic_id)
@@ -35,6 +35,9 @@
     ON magicDSRun.magic_ds_id = magicDSFile.magic_ds_id
     AND magicDSFile.component = rawImfile.class_id
+LEFT JOIN Label ON magicDSRun.label = Label.label
 WHERE
     magicDSRun.state = 'new'
     AND magicDSRun.stage = 'raw'
     AND magicDSFile.component IS NULL
+    AND (Label.active OR Label.active IS NULL)
+
Index: branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_diff.sql
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_diff.sql	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_diff.sql	(revision 30812)
@@ -13,5 +13,4 @@
     magicDSFile.recovery_path_base,
     "NULL" AS cam_path_base,
-    recovery_path_base,
     CAST(diffRun.bothways AS SIGNED) AS bothways,
     0 AS bytes,
Index: branches/eam_branches/ipp-20110213/ippTools/src/addtool.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/addtool.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/addtool.c	(revision 30812)
@@ -324,5 +324,5 @@
     // pxUpdateRun gets parameters from config->args and runs the update query
     bool result = pxUpdateRun(config, where, &query, "addRun", "add_id",
-        "addProcessedExp", false);
+        "addProcessedExp", false, false);
 
     psFree(query);
Index: branches/eam_branches/ipp-20110213/ippTools/src/bgtool.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/bgtool.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/bgtool.c	(revision 30812)
@@ -501,5 +501,5 @@
     psString query = psStringCopy("UPDATE chipBackgroundRun");
     bool result = pxUpdateRun(config, where, &query, "chipBackgroundRun", "chip_bg_id",
-                              "chipBackgroundImfile", true);
+                              "chipBackgroundImfile", true, true);
 
     psFree(query);
@@ -1471,5 +1471,5 @@
     psString query = psStringCopy("UPDATE warpBackgroundRun");
     bool result = pxUpdateRun(config, where, &query, "warpBackgroundRun", "warp_bg_id",
-                              "warpBackgroundSkyfile", true);
+                              "warpBackgroundSkyfile", true, true);
 
     psFree(query);
Index: branches/eam_branches/ipp-20110213/ippTools/src/camtool.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/camtool.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/camtool.c	(revision 30812)
@@ -283,5 +283,5 @@
 
     // pxUpdateRun gets parameters from config->args and updates
-    bool result = pxUpdateRun(config, where, &query, "camRun", "cam_id", "camProcessedExp", true);
+    bool result = pxUpdateRun(config, where, &query, "camRun", "cam_id", "camProcessedExp", true, true);
     if (!result) {
         psError(psErrorCodeLast(), false, "pxUpdateRun failed");
Index: branches/eam_branches/ipp-20110213/ippTools/src/camtoolConfig.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/camtoolConfig.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/camtoolConfig.c	(revision 30812)
@@ -86,4 +86,5 @@
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_dist_group", 0,   "define new dist_group", NULL);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_note", 0,         "define new note", NULL);
+    pxmagicAddArguments(updaterunArgs);
 
     // -pendingexp
@@ -299,6 +300,6 @@
     PXOPT_ADD_MODE("-addprocessedexp",      "add a processed exposure",             CAMTOOL_MODE_ADDPROCESSEDEXP, addprocessedexpArgs);
     PXOPT_ADD_MODE("-processedexp",         "show processed exposures",             CAMTOOL_MODE_PROCESSEDEXP,  processedexpArgs);
-    PXOPT_ADD_MODE("-revertprocessedexp",   "change procesed exp properties",       CAMTOOL_MODE_REVERTPROCESSEDEXP,  revertprocessedexpArgs);
-    PXOPT_ADD_MODE("-updateprocessedexp",   "undo a processed exposure",            CAMTOOL_MODE_UPDATEPROCESSEDEXP,updateprocessedexpArgs);
+    PXOPT_ADD_MODE("-revertprocessedexp",   "undo a processed exposure",       CAMTOOL_MODE_REVERTPROCESSEDEXP,  revertprocessedexpArgs);
+    PXOPT_ADD_MODE("-updateprocessedexp",   "changed processed exp properties",            CAMTOOL_MODE_UPDATEPROCESSEDEXP,updateprocessedexpArgs);
     PXOPT_ADD_MODE("-block",                "set a label block",                    CAMTOOL_MODE_BLOCK,         blockArgs);
     PXOPT_ADD_MODE("-masked",               "show blocked labels",                  CAMTOOL_MODE_MASKED,        maskedArgs);
Index: branches/eam_branches/ipp-20110213/ippTools/src/chiptool.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/chiptool.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/chiptool.c	(revision 30812)
@@ -443,5 +443,5 @@
 
     // pxUpdateRun gets parameters from config->args and updates
-    bool result = pxUpdateRun(config, where, &query, "chipRun", "chip_id", "chipProcessedImfile", true);
+    bool result = pxUpdateRun(config, where, &query, "chipRun", "chip_id", "chipProcessedImfile", true, true);
     if (!result) {
         psError(psErrorCodeLast(), false, "pxUpdateRun failed");
Index: branches/eam_branches/ipp-20110213/ippTools/src/chiptoolConfig.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/chiptoolConfig.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/chiptoolConfig.c	(revision 30812)
@@ -99,4 +99,5 @@
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_dist_group", 0,   "set dist group", NULL);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_note", 0,         "set note", NULL);
+    pxmagicAddArguments(updaterunArgs);
 
     // -setimfiletoupdate
Index: branches/eam_branches/ipp-20110213/ippTools/src/diffphottool.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/diffphottool.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/diffphottool.c	(revision 30812)
@@ -228,5 +228,5 @@
 
     // pxUpdateRun gets parameters from config->args and updates
-    bool result = pxUpdateRun(config, where, &query, "diffPhotRun", "diff_phot_id", "diffPhotSkyfile", true);
+    bool result = pxUpdateRun(config, where, &query, "diffPhotRun", "diff_phot_id", "diffPhotSkyfile", true, false);
 
     psFree(query);
Index: branches/eam_branches/ipp-20110213/ippTools/src/difftool.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/difftool.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/difftool.c	(revision 30812)
@@ -224,5 +224,5 @@
 
     // pxUpdateRun gets parameters from config->args and updates
-    bool result = pxUpdateRun(config, where, &query, "diffRun", "diff_id", "diffSkyfile", true);
+    bool result = pxUpdateRun(config, where, &query, "diffRun", "diff_id", "diffSkyfile", true, true);
 
     psFree(query);
Index: branches/eam_branches/ipp-20110213/ippTools/src/difftoolConfig.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/difftoolConfig.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/difftoolConfig.c	(revision 30812)
@@ -73,4 +73,5 @@
     psMetadataAddS16(updaterunArgs, PS_LIST_TAIL, "-set_diff_mode", 0,    "specify type of difference (WW=1,WS=2,SW=3,SS=4)", 0);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_note", 0,         "define new note", NULL);
+    pxmagicAddArguments(updaterunArgs);
 
     // -addinputskyfile
Index: branches/eam_branches/ipp-20110213/ippTools/src/faketool.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/faketool.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/faketool.c	(revision 30812)
@@ -348,5 +348,5 @@
 
     // pxUpdateRun gets parameters from config->args and updates
-    bool result = pxUpdateRun(config, where, &query, "fakeRun", "fake_id", "fakeProcessedImfile", true);
+    bool result = pxUpdateRun(config, where, &query, "fakeRun", "fake_id", "fakeProcessedImfile", true, false);
     if (!result) {
         psError(psErrorCodeLast(), false, "pxUpdateRun failed");
Index: branches/eam_branches/ipp-20110213/ippTools/src/magicdstool.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/magicdstool.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/magicdstool.c	(revision 30812)
@@ -1395,4 +1395,5 @@
           (strcmp(state, "full") == 0) ||
           (strcmp(state, "drop") == 0) ||
+          (strcmp(state, "wait") == 0) ||
           (strcmp(state, "failed_revert") == 0) ||
           (strcmp(state, "error_cleaned") == 0) ||
Index: branches/eam_branches/ipp-20110213/ippTools/src/pubtool.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/pubtool.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/pubtool.c	(revision 30812)
@@ -37,4 +37,5 @@
 static bool addMode(pxConfig *config);
 static bool revertMode(pxConfig *config);
+static bool updaterunMode(pxConfig *config);
 
 # define MODECASE(caseName, func) \
@@ -63,4 +64,5 @@
         MODECASE(PUBTOOL_MODE_ADD, addMode);
         MODECASE(PUBTOOL_MODE_REVERT, revertMode);
+        MODECASE(PUBTOOL_MODE_UPDATERUN, updaterunMode);
       default:
         psAbort("invalid option (this should not happen)");
@@ -459,2 +461,40 @@
 }
 
+static bool updaterunMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    psMetadata *where = psMetadataAlloc(); // WHERE conditions
+    PXOPT_COPY_S64(config->args, where, "-pub_id", "pub_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-client_id", "client_id", "==");
+    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
+    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
+    PXOPT_COPY_STR(config->args, where, "-fault", "fault", "==");
+
+    PXOPT_LOOKUP_STR(state, config->args, "-set_state",  true, false);
+
+    psString query = NULL;              // Query to run
+    psStringAppend(&query, "UPDATE publishRun LEFT JOIN publishDone using(pub_id) SET state = '%s'", state);
+
+    if (psListLength(where->list)) {
+        psString clause = psDBGenerateWhereConditionSQL(where, NULL);
+        psStringAppend(&query, "\n WHERE %s", clause);
+        psFree(clause);
+    } else {
+        psError(PS_ERR_UNKNOWN, false, "select arguments are required");
+        return false;
+    }
+    psFree(where);
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    long numUpdated = psDBAffectedRows(config->dbh);
+    psLogMsg("pubtool", PS_LOG_INFO, "%ld rows updated.", numUpdated);
+
+    return true;
+}
Index: branches/eam_branches/ipp-20110213/ippTools/src/pubtool.h
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/pubtool.h	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/pubtool.h	(revision 30812)
@@ -31,4 +31,5 @@
     PUBTOOL_MODE_ADD,
     PUBTOOL_MODE_REVERT,
+    PUBTOOL_MODE_UPDATERUN,
 } pubtoolMode;
 
Index: branches/eam_branches/ipp-20110213/ippTools/src/pubtoolConfig.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/pubtoolConfig.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/pubtoolConfig.c	(revision 30812)
@@ -102,4 +102,13 @@
     psMetadataAddStr(revertArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search on label", NULL);
 
+    // -updaterun
+    psMetadata *updaterunArgs = psMetadataAlloc();
+    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0, "new value for state (required)", NULL);
+    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0, "search by state", NULL);
+    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-pub_id", 0, "search on pub_id", 0);
+    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-client_id", 0, "search on client_id", 0);
+    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label", 0, "search by label", NULL);
+    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-fault", 0, "search by fault", NULL);
+
 
     psMetadata *argSets = psMetadataAlloc();
@@ -112,4 +121,5 @@
     PXOPT_ADD_MODE("-add", "", PUBTOOL_MODE_ADD, addArgs);
     PXOPT_ADD_MODE("-revert", "", PUBTOOL_MODE_REVERT, revertArgs);
+    PXOPT_ADD_MODE("-updaterun", "", PUBTOOL_MODE_UPDATERUN, updaterunArgs);
 
     if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
Index: branches/eam_branches/ipp-20110213/ippTools/src/pxtools.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/pxtools.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/pxtools.c	(revision 30812)
@@ -278,5 +278,5 @@
 
 // shared code for updating the various strings for a Run
-bool pxUpdateRun(pxConfig *config, psMetadata *where, psString *pQuery, psString runTable, psString idColumn, psString fileTable, bool has_dist_group)
+bool pxUpdateRun(pxConfig *config, psMetadata *where, psString *pQuery, psString runTable, psString idColumn, psString fileTable, bool has_dist_group, bool has_magicked)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -360,4 +360,7 @@
     if (fileWhere) {
         psStringAppend(pQuery, "%s", fileWhere);
+    }
+    if (has_magicked) {
+        pxmagicAddWhere(config, pQuery, runTable);
     }
 
Index: branches/eam_branches/ipp-20110213/ippTools/src/pxtools.h
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/pxtools.h	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/pxtools.h	(revision 30812)
@@ -84,5 +84,5 @@
 bool pxGetOptions(FILE *stream, int argc, char **argv, pxConfig *config, psMetadata *modes, psMetadata *argSets);
 
-bool pxUpdateRun(pxConfig *config, psMetadata *where, psString *pQuery, psString runTable, psString idColumn, psString fileTable, bool has_dist_group);
+bool pxUpdateRun(pxConfig *config, psMetadata *where, psString *pQuery, psString runTable, psString idColumn, psString fileTable, bool has_dist_group, bool has_magicked);
 
 #define PXOPT_ADD_MODE(option, comment, modeval, argset) \
Index: branches/eam_branches/ipp-20110213/ippTools/src/stacktool.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/stacktool.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/stacktool.c	(revision 30812)
@@ -750,5 +750,5 @@
 
     // pxUpdateRun gets parameters from config->args and updates
-    bool result = pxUpdateRun(config, where, &query, "stackRun", "stack_id", "stackSumSkyfile", true);
+    bool result = pxUpdateRun(config, where, &query, "stackRun", "stack_id", "stackSumSkyfile", true, false);
 
     psFree(query);
Index: branches/eam_branches/ipp-20110213/ippTools/src/staticskytool.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/staticskytool.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/staticskytool.c	(revision 30812)
@@ -360,5 +360,5 @@
 
     // pxUpdateRun gets parameters from config->args and updates
-    bool result = pxUpdateRun(config, where, &query, "staticskyRun", "sky_id", "staticskyResult", true);
+    bool result = pxUpdateRun(config, where, &query, "staticskyRun", "sky_id", "staticskyResult", true, false);
     psFree(query);
     psFree(where);
Index: branches/eam_branches/ipp-20110213/ippTools/src/warptool.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/warptool.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/warptool.c	(revision 30812)
@@ -435,5 +435,5 @@
 
     // pxUpdateRun gets parameters from config->args and updates
-    bool result = pxUpdateRun(config, where, &query, "warpRun", "warp_id", "warpSkyfile", true);
+    bool result = pxUpdateRun(config, where, &query, "warpRun", "warp_id", "warpSkyfile", true, true);
 
     psFree(query);
Index: branches/eam_branches/ipp-20110213/ippTools/src/warptoolConfig.c
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/src/warptoolConfig.c	(revision 30700)
+++ branches/eam_branches/ipp-20110213/ippTools/src/warptoolConfig.c	(revision 30812)
@@ -141,5 +141,4 @@
     psMetadataAddTime(updaterunArgs, PS_LIST_TAIL, "-registered_begin", 0, "search for runs by registration time (>=)", NULL);
     psMetadataAddTime(updaterunArgs, PS_LIST_TAIL, "-registered_end", 0, "search for runs by registration time (<)", NULL);
-    psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-destreaked", 0, "search for runs that have been destreaked", false);
     psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-pretend", 0, "only pretend to run the query", false);
 
@@ -149,4 +148,5 @@
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_dist_group", 0,   "define new dist_group", NULL);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_note", 0,         "define new note", NULL);
+    pxmagicAddArguments(updaterunArgs);
 
     // -exp
