IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 7, 2009, 4:25:35 PM (17 years ago)
Author:
watersc1
Message:

Updates to various tools to fix errors in cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/difftool.c

    r25790 r25800  
    5151
    5252static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, psS64 magicked);
     53static bool setdiffRunStateByLabel(pxConfig *config, const char* label, const char *state);
     54static bool change_skyfile_data_state(pxConfig *config, psString data_state, psString run_state);
     55static bool tocleanedskyfileMode(pxConfig *config);
     56static bool topurgedskyfileMode(pxConfig *config);
     57static bool toscrubbedskyfileMode(pxConfig *config);
     58
     59
    5360
    5461# define MODECASE(caseName, func) \
     
    8895        MODECASE(DIFFTOOL_MODE_EXPORTRUN,             exportrunMode);
    8996        MODECASE(DIFFTOOL_MODE_IMPORTRUN,             importrunMode);
     97        MODECASE(DIFFTOOL_MODE_TOCLEANEDSKYFILE,   tocleanedskyfileMode);
     98        MODECASE(DIFFTOOL_MODE_TOPURGEDSKYFILE,    topurgedskyfileMode);
     99        MODECASE(DIFFTOOL_MODE_TOSCRUBBEDSKYFILE,  toscrubbedskyfileMode);
     100
    90101        default:
    91102            psAbort("invalid option (this should not happen)");
     
    169180
    170181    // required options
    171     PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false);
     182    PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", false, false);
    172183    PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
    173 
    174     if (state) {
     184    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     185   
     186    // Copy of my hacky work around from stacktool.c
     187    if ((state)&&(diff_id)) {
    175188        // set detRun.state to state
    176189        return setdiffRunState(config, diff_id, state, false);
    177190    }
    178191
    179     return true;
     192    if ((state)&&(label)) {
     193      return setdiffRunStateByLabel(config, label, state);
     194    }
     195
     196    psError(PS_ERR_UNKNOWN, false, "Required options not found.");
     197
     198    return false;
    180199}
    181200
     
    865884    }
    866885
    867     char *query = "UPDATE diffRun SET state = '%s', magicked = %" PRId64 " WHERE diff_id = %"PRId64;
    868 
    869     if (!p_psDBRunQueryF(config->dbh, query, state, magicked, diff_id)) {
     886    if (magicked) {
     887      char *query = "UPDATE diffRun SET state = '%s', magicked = %" PRId64 " WHERE diff_id = %"PRId64;
     888     
     889      if (!p_psDBRunQueryF(config->dbh, query, state, magicked, diff_id)) {
    870890        psError(PS_ERR_UNKNOWN, false,
    871891                "failed to change state for diff_id %"PRId64, diff_id);
    872892        return false;
    873     }
    874 
     893      }
     894    }
     895    else {
     896      char *query = "UPDATE diffRun SET state = '%s' WHERE diff_id = %"PRId64;
     897     
     898      if (!p_psDBRunQueryF(config->dbh, query, state, diff_id)) {
     899        psError(PS_ERR_UNKNOWN, false,
     900                "failed to change state for diff_id %"PRId64, diff_id);
     901        return false;
     902      }
     903    }
     904   
    875905    return true;
     906}
     907
     908
     909static bool setdiffRunStateByLabel(pxConfig *config, const char *label, const char *state) {
     910  PS_ASSERT_PTR_NON_NULL(state,false);
     911
     912  // check that state is a valid string value
     913  if (!pxIsValidState(state)) {
     914    psError(PS_ERR_UNKNOWN, false, "invalid diffRun state: %s", state);
     915    return false;
     916  }
     917
     918  char *query = "UPDATE diffRun SET state = '%s' WHERE label = '%s'";
     919  if (!p_psDBRunQueryF(config->dbh,query,state,label)) {
     920    psError(PS_ERR_UNKNOWN, false,
     921            "failed to change state for label %s", label);
     922    return(false);
     923  }
     924
     925  return true;
    876926}
    877927
     
    17251775
    17261776    psMetadata *where = psMetadataAlloc();
    1727     pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "==");
     1777    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    17281778
    17291779    psString query = pxDataGet("difftool_pendingcleanuprun.sql");
     
    17471797    }
    17481798
     1799    //    fprintf(stderr,"%s",query);
    17491800    if (!p_psDBRunQuery(config->dbh, query)) {
    17501801        psError(PS_ERR_UNKNOWN, false, "database error");
     
    19181969
    19191970    return true;
     1971}
     1972
     1973static bool change_skyfile_data_state(pxConfig *config, psString data_state, psString run_state) {
     1974  PS_ASSERT_PTR_NON_NULL(config, false);
     1975
     1976  // diff_id, skycell_id are required
     1977  PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false);
     1978  PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
     1979
     1980  psString query = pxDataGet("difftool_change_skyfile_data_state.sql");
     1981
     1982  if (!psDBTransaction(config->dbh)) {
     1983    psError(PS_ERR_UNKNOWN, false, "database error");
     1984    return(false);
     1985  }
     1986
     1987  // Uses the unconstrained (diffRun.state [NEED NOT EQUAL] run_state) version from warptool.c
     1988
     1989  if (!p_psDBRunQueryF(config->dbh, query, data_state, diff_id, skycell_id)) {
     1990    psError(PS_ERR_UNKNOWN, false, "database error");
     1991    // rollback
     1992    if (!psDBRollback(config->dbh)) {
     1993      psError(PS_ERR_UNKNOWN, false, "database error");
     1994    }
     1995    psError(PS_ERR_UNKNOWN, false, "database error");
     1996    return(false);
     1997  }
     1998  psFree(query);
     1999
     2000  query = pxDataGet("difftool_change_run_state.sql");
     2001  if (!p_psDBRunQueryF(config->dbh, query, data_state, diff_id, data_state)) {
     2002    // rollback
     2003    if (!psDBRollback(config->dbh)) {
     2004      psError(PS_ERR_UNKNOWN, false, "database error");
     2005    }
     2006    psError(PS_ERR_UNKNOWN, false, "database error");
     2007    return(false);
     2008  }
     2009
     2010  if (!psDBCommit(config->dbh)) {
     2011    psError(PS_ERR_UNKNOWN, false, "database error");
     2012    return(false);
     2013  }
     2014 
     2015  return(true);
     2016}
     2017
     2018static bool tocleanedskyfileMode(pxConfig *config) {
     2019  return change_skyfile_data_state(config, "cleaned","goto_cleaned");
     2020}
     2021static bool topurgedskyfileMode(pxConfig *config) {
     2022  return change_skyfile_data_state(config, "purged", "goto_purged");
     2023}
     2024static bool toscrubbedskyfileMode(pxConfig *config) {
     2025  return change_skyfile_data_state(config, "scrubbed", "goto_scrubbed");
    19202026}
    19212027
Note: See TracChangeset for help on using the changeset viewer.