IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 30, 2008, 11:03:23 AM (18 years ago)
Author:
jhoblitt
Message:

convert chiptool to use the new cleanup states

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/cleanup/ippTools/src/chiptool.c

    r17859 r17863  
    4747static bool pendingcleanupMode(pxConfig *config);
    4848static bool donecleanupMode(pxConfig *config);
     49static bool runMode(pxConfig *config);
    4950
    5051static bool chipProcessedCompleteExp(pxConfig *config);
     
    8081        MODECASE(CHIPTOOL_MODE_PENDINGCLEANUP,          pendingcleanupMode);
    8182        MODECASE(CHIPTOOL_MODE_DONECLEANUP,             donecleanupMode);
     83        MODECASE(CHIPTOOL_MODE_RUN,                     runMode);
    8284        default:
    8385            psAbort("invalid option (this should not happen)");
     
    10741076
    10751077
     1078static bool runMode(pxConfig *config)
     1079{
     1080    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1081
     1082    PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
     1083    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1084    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1085
     1086    // make sure that the state string is valid
     1087    if (!pxIsValidState(state)) {
     1088        psError(PXTOOLS_ERR_DATA, false, "%s is not a valid state", state);
     1089        return false;
     1090    }
     1091
     1092    psMetadata *where = psMetadataAlloc();
     1093    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     1094    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
     1095
     1096    psString query = pxDataGet("chiptool_run.sql");
     1097    if (!query) {
     1098        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1099        return false;
     1100    }
     1101
     1102    if (where && psListLength(where->list)) {
     1103        psString whereClause = psDBGenerateWhereSQL(where, NULL);
     1104        psStringAppend(&query, " %s", whereClause);
     1105        psFree(whereClause);
     1106    }
     1107    psFree(where);
     1108
     1109    // treat limit == 0 as "no limit"
     1110    if (limit) {
     1111        psString limitString = psDBGenerateLimitSQL(limit);
     1112        psStringAppend(&query, " %s", limitString);
     1113        psFree(limitString);
     1114    }
     1115
     1116    if (!p_psDBRunQuery(config->dbh, query)) {
     1117        psError(PS_ERR_UNKNOWN, false, "database error");
     1118        psFree(query);
     1119        return false;
     1120    }
     1121    psFree(query);
     1122
     1123    psArray *output = p_psDBFetchResult(config->dbh);
     1124    if (!output) {
     1125        psError(PS_ERR_UNKNOWN, false, "database error");
     1126        return false;
     1127    }
     1128    if (!psArrayLength(output)) {
     1129        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     1130        psFree(output);
     1131        return true;
     1132    }
     1133
     1134    if (!convertIdToStr(output)) {
     1135        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
     1136        psFree(output);
     1137        return false;
     1138    }
     1139
     1140    // negative simple so the default is true
     1141    if (!ippdbPrintMetadatas(stdout, output, "chipDoneCleanup", !simple)) {
     1142        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1143        psFree(output);
     1144        return false;
     1145    }
     1146
     1147    psFree(output);
     1148
     1149    return true;
     1150}
     1151
     1152
    10761153static bool chipProcessedCompleteExp(pxConfig *config)
    10771154{
     
    11091186        chipRunRow *chipRun = chipRunObjectFromMetadata(row);
    11101187        // set chipRun.state to 'stop'
    1111         if (!pxchipRunSetState(config, chipRun->chip_id, "stop")) {
     1188        if (!pxchipRunSetState(config, chipRun->chip_id, "full")) {
    11121189            psError(PS_ERR_UNKNOWN, false, "failed to change chipRun.state for chip_id: %" PRId64, chipRun->chip_id);
    11131190            psFree(chipRun);
Note: See TracChangeset for help on using the changeset viewer.