IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 30, 2009, 11:58:26 AM (17 years ago)
Author:
bills
Message:

add two now magicdstool modes

-toremove gives list of images for which back images need to be deleted
-torestore gives list of images which pending restoration of destreaked pixels

File:
1 edited

Legend:

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

    r23974 r24284  
    3838static bool revertdestreakedfileMode(pxConfig *config);
    3939static bool getskycellsMode(pxConfig *config);
     40static bool toremoveMode(pxConfig *config);
     41static bool torestoreMode(pxConfig *config);
    4042
    4143static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, const char *state);
     
    6870        MODECASE(MAGICDSTOOL_MODE_REVERTDESTREAKEDFILE,revertdestreakedfileMode);
    6971        MODECASE(MAGICDSTOOL_MODE_GETSKYCELLS,         getskycellsMode);
     72        MODECASE(MAGICDSTOOL_MODE_TOREMOVE,            toremoveMode);
     73        MODECASE(MAGICDSTOOL_MODE_TORESTORE,           torestoreMode);
    7074        default:
    7175            psAbort("invalid option (this should not happen)");
     
    889893}
    890894
     895static bool toremoveMode(pxConfig *config)
     896{
     897    PS_ASSERT_PTR_NON_NULL(config, false);
     898
     899    psMetadata *where = psMetadataAlloc();
     900    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");
     901    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     902    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
     903
     904    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     905    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     906
     907    // look for "inputs" that need to processed
     908    psString query = pxDataGet("magicdstool_toremove.sql");
     909    if (!query) {
     910        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     911        return false;
     912    }
     913
     914    if (psListLength(where->list)) {
     915        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     916        psStringAppend(&query, " WHERE %s", whereClause);
     917        psFree(whereClause);
     918    }
     919    psFree(where);
     920
     921    // treat limit == 0 as "no limit"
     922    if (limit) {
     923        psString limitString = psDBGenerateLimitSQL(limit);
     924        psStringAppend(&query, " %s", limitString);
     925        psFree(limitString);
     926    }
     927
     928    if (!p_psDBRunQuery(config->dbh, query)) {
     929        psError(PS_ERR_UNKNOWN, false, "database error");
     930        psFree(query);
     931        return false;
     932    }
     933    psFree(query);
     934
     935    psArray *output = p_psDBFetchResult(config->dbh);
     936    if (!output) {
     937        psErrorCode err = psErrorCodeLast();
     938        switch (err) {
     939            case PS_ERR_DB_CLIENT:
     940                psError(PXTOOLS_ERR_SYS, false, "database error");
     941            case PS_ERR_DB_SERVER:
     942                psError(PXTOOLS_ERR_PROG, false, "database error");
     943            default:
     944                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     945        }
     946
     947        return false;
     948    }
     949    if (!psArrayLength(output)) {
     950        psTrace("magicdstool", PS_LOG_INFO, "no rows found");
     951        psFree(output);
     952        return true;
     953    }
     954
     955    if (psArrayLength(output)) {
     956        // negative simple so the default is true
     957        if (!ippdbPrintMetadatas(stdout, output, "toremove", !simple)) {
     958            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     959            psFree(output);
     960            return false;
     961        }
     962    }
     963
     964    psFree(output);
     965
     966    return true;
     967}
     968static bool torestoreMode(pxConfig *config)
     969{
     970    PS_ASSERT_PTR_NON_NULL(config, false);
     971
     972    psMetadata *where = psMetadataAlloc();
     973    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");
     974    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     975    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
     976
     977    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     978    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     979
     980    // look for "inputs" that need to processed
     981    psString query = pxDataGet("magicdstool_torestore.sql");
     982    if (!query) {
     983        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     984        return false;
     985    }
     986
     987    if (psListLength(where->list)) {
     988        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     989        psStringAppend(&query, " WHERE %s", whereClause);
     990        psFree(whereClause);
     991    }
     992    psFree(where);
     993
     994    // treat limit == 0 as "no limit"
     995    if (limit) {
     996        psString limitString = psDBGenerateLimitSQL(limit);
     997        psStringAppend(&query, " %s", limitString);
     998        psFree(limitString);
     999    }
     1000
     1001    if (!p_psDBRunQuery(config->dbh, query)) {
     1002        psError(PS_ERR_UNKNOWN, false, "database error");
     1003        psFree(query);
     1004        return false;
     1005    }
     1006    psFree(query);
     1007
     1008    psArray *output = p_psDBFetchResult(config->dbh);
     1009    if (!output) {
     1010        psErrorCode err = psErrorCodeLast();
     1011        switch (err) {
     1012            case PS_ERR_DB_CLIENT:
     1013                psError(PXTOOLS_ERR_SYS, false, "database error");
     1014            case PS_ERR_DB_SERVER:
     1015                psError(PXTOOLS_ERR_PROG, false, "database error");
     1016            default:
     1017                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1018        }
     1019
     1020        return false;
     1021    }
     1022    if (!psArrayLength(output)) {
     1023        psTrace("magicdstool", PS_LOG_INFO, "no rows found");
     1024        psFree(output);
     1025        return true;
     1026    }
     1027
     1028    if (psArrayLength(output)) {
     1029        // negative simple so the default is true
     1030        if (!ippdbPrintMetadatas(stdout, output, "torestore", !simple)) {
     1031            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1032            psFree(output);
     1033            return false;
     1034        }
     1035    }
     1036
     1037    psFree(output);
     1038
     1039    return true;
     1040}
Note: See TracChangeset for help on using the changeset viewer.