IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 29, 2008, 4:45:44 PM (18 years ago)
Author:
jhoblitt
Message:

add chiptool -pendingcleanup & -donecleanup

File:
1 edited

Legend:

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

    r17591 r17859  
    4545static bool unmaskedMode(pxConfig *config);
    4646static bool unblockMode(pxConfig *config);
     47static bool pendingcleanupMode(pxConfig *config);
     48static bool donecleanupMode(pxConfig *config);
    4749
    4850static bool chipProcessedCompleteExp(pxConfig *config);
     
    7678        MODECASE(CHIPTOOL_MODE_UNMASKED,                unmaskedMode);
    7779        MODECASE(CHIPTOOL_MODE_UNBLOCK,                 unblockMode);
     80        MODECASE(CHIPTOOL_MODE_PENDINGCLEANUP,          pendingcleanupMode);
     81        MODECASE(CHIPTOOL_MODE_DONECLEANUP,             donecleanupMode);
    7882        default:
    7983            psAbort("invalid option (this should not happen)");
     
    936940
    937941
     942static bool pendingcleanupMode(pxConfig *config)
     943{
     944    PS_ASSERT_PTR_NON_NULL(config, NULL);
     945
     946    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     947    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     948
     949    psMetadata *where = psMetadataAlloc();
     950    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     951
     952    psString query = pxDataGet("chiptool_pendingcleanup.sql");
     953    if (!query) {
     954        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     955        return false;
     956    }
     957
     958    if (where && psListLength(where->list)) {
     959        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     960        psStringAppend(&query, " AND %s", whereClause);
     961        psFree(whereClause);
     962    }
     963    psFree(where);
     964
     965    // treat limit == 0 as "no limit"
     966    if (limit) {
     967        psString limitString = psDBGenerateLimitSQL(limit);
     968        psStringAppend(&query, " %s", limitString);
     969        psFree(limitString);
     970    }
     971
     972    if (!p_psDBRunQuery(config->dbh, query)) {
     973        psError(PS_ERR_UNKNOWN, false, "database error");
     974        psFree(query);
     975        return false;
     976    }
     977    psFree(query);
     978
     979    psArray *output = p_psDBFetchResult(config->dbh);
     980    if (!output) {
     981        psError(PS_ERR_UNKNOWN, false, "database error");
     982        return false;
     983    }
     984    if (!psArrayLength(output)) {
     985        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     986        psFree(output);
     987        return true;
     988    }
     989
     990    if (!convertIdToStr(output)) {
     991        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
     992        psFree(output);
     993        return false;
     994    }
     995
     996    // negative simple so the default is true
     997    if (!ippdbPrintMetadatas(stdout, output, "chipPendingCleanup", !simple)) {
     998        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     999        psFree(output);
     1000        return false;
     1001    }
     1002
     1003    psFree(output);
     1004
     1005    return true;
     1006}
     1007
     1008
     1009static bool donecleanupMode(pxConfig *config)
     1010{
     1011    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1012
     1013    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1014    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1015
     1016    psMetadata *where = psMetadataAlloc();
     1017    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     1018
     1019    psString query = pxDataGet("chiptool_donecleanup.sql");
     1020    if (!query) {
     1021        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1022        return false;
     1023    }
     1024
     1025    if (where && psListLength(where->list)) {
     1026        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1027        psStringAppend(&query, " AND %s", whereClause);
     1028        psFree(whereClause);
     1029    }
     1030    psFree(where);
     1031
     1032    // treat limit == 0 as "no limit"
     1033    if (limit) {
     1034        psString limitString = psDBGenerateLimitSQL(limit);
     1035        psStringAppend(&query, " %s", limitString);
     1036        psFree(limitString);
     1037    }
     1038
     1039    if (!p_psDBRunQuery(config->dbh, query)) {
     1040        psError(PS_ERR_UNKNOWN, false, "database error");
     1041        psFree(query);
     1042        return false;
     1043    }
     1044    psFree(query);
     1045
     1046    psArray *output = p_psDBFetchResult(config->dbh);
     1047    if (!output) {
     1048        psError(PS_ERR_UNKNOWN, false, "database error");
     1049        return false;
     1050    }
     1051    if (!psArrayLength(output)) {
     1052        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     1053        psFree(output);
     1054        return true;
     1055    }
     1056
     1057    if (!convertIdToStr(output)) {
     1058        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
     1059        psFree(output);
     1060        return false;
     1061    }
     1062
     1063    // negative simple so the default is true
     1064    if (!ippdbPrintMetadatas(stdout, output, "chipDoneCleanup", !simple)) {
     1065        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1066        psFree(output);
     1067        return false;
     1068    }
     1069
     1070    psFree(output);
     1071
     1072    return true;
     1073}
     1074
     1075
    9381076static bool chipProcessedCompleteExp(pxConfig *config)
    9391077{
Note: See TracChangeset for help on using the changeset viewer.