IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 17, 2026, 11:33:59 AM (8 days ago)
Author:
eugene
Message:

add -listrun option to stacktool

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-pstamp-20260421/ippTools/src/stacktool.c

    r43013 r43094  
    3434static bool definerunMode(pxConfig *config);
    3535static bool updaterunMode(pxConfig *config);
     36static bool listrunMode(pxConfig *config);
    3637static bool addinputskyfileMode(pxConfig *config);
    3738static bool inputskyfileMode(pxConfig *config);
    … …  
    7980        MODECASE(STACKTOOL_MODE_DEFINERUN,             definerunMode);
    8081        MODECASE(STACKTOOL_MODE_UPDATERUN,             updaterunMode);
     82        MODECASE(STACKTOOL_MODE_LISTRUN,               listrunMode);
    8183        MODECASE(STACKTOOL_MODE_ADDINPUTSKYFILE,       addinputskyfileMode);
    8284        MODECASE(STACKTOOL_MODE_INPUTSKYFILE,          inputskyfileMode);
    … …  
    750752}
    751753
    752 
    753754static bool updaterunMode(pxConfig *config)
    754755{
    … …  
    815816}
    816817
     818static bool listrunMode(pxConfig *config)
     819{
     820    PS_ASSERT_PTR_NON_NULL(config, false);
     821
     822    psMetadata *where = psMetadataAlloc();
     823    PXOPT_COPY_S64(config->args, where, "-stack_id",   "stackRun.stack_id", "==");
     824    PXOPT_COPY_STR(config->args, where, "-tess_id",    "stackRun.tess_id", "LIKE");
     825    PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE");
     826    PXOPT_COPY_STR(config->args, where, "-filter",     "stackRun.filter", "LIKE");
     827    PXOPT_COPY_STR(config->args, where, "-state",      "stackRun.state", "==");
     828    pxAddLabelSearchArgs(config, where, "-label",      "stackRun.label", "LIKE");
     829    pxAddLabelSearchArgs(config, where, "-data_group", "stackRun.data_group", "LIKE");
     830    pxAddLabelSearchArgs(config, where, "-dist_group", "stackRun.dist_group", "LIKE");
     831
     832    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
     833    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     834    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     835
     836    psString query = psStringCopy ("SELECT stackRun.* FROM stackRun");
     837
     838    if (psListLength(where->list)) {
     839        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     840        psStringAppend(&query, " WHERE %s", whereClause);
     841        psFree(whereClause);
     842    } else if (!all) {
     843        psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required");
     844        return false;
     845    }
     846    psFree(where);
     847
     848    // treat limit == 0 as "no limit"
     849    if (limit) {
     850        psString limitString = psDBGenerateLimitSQL(limit);
     851        psStringAppend(&query, " %s", limitString);
     852        psFree(limitString);
     853    }
     854
     855    if (!p_psDBRunQuery(config->dbh, query)) {
     856        psError(PS_ERR_UNKNOWN, false, "database error");
     857        psFree(query);
     858        return false;
     859    }
     860    psFree(query);
     861
     862    psArray *output = p_psDBFetchResult(config->dbh);
     863    if (!output) {
     864        psErrorCode err = psErrorCodeLast();
     865        switch (err) {
     866            case PS_ERR_DB_CLIENT:
     867                psError(PXTOOLS_ERR_SYS, false, "database error");
     868            case PS_ERR_DB_SERVER:
     869                psError(PXTOOLS_ERR_PROG, false, "database error");
     870            default:
     871                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     872        }
     873
     874        return false;
     875    }
     876    if (!psArrayLength(output)) {
     877        psTrace("stacktool", PS_LOG_INFO, "no rows found");
     878        psFree(output);
     879        return true;
     880    }
     881
     882    if (psArrayLength(output)) {
     883        if (!ippdbPrintMetadatas(stdout, output, "stackRun", !simple)) {
     884            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     885            psFree(output);
     886            return false;
     887        }
     888    }
     889   
     890    psFree(output);
     891
     892    return true;
     893}
    817894
    818895static bool addinputskyfileMode(pxConfig *config)
    … …  
    12111288}
    12121289
    1213 
    12141290static bool sumskyfileMode(pxConfig *config)
    12151291{
Note: See TracChangeset for help on using the changeset viewer.