IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 13, 2009, 4:32:41 PM (17 years ago)
Author:
bills
Message:

modes to disttool for creating rcDSFileset objects
tweaks to the rcDSFileset and rcDSProduct tables

File:
1 edited

Legend:

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

    r23783 r23842  
    3939static bool processedcomponentMode(pxConfig *config);
    4040static bool toadvanceMode(pxConfig *config);
     41static bool pendingfilesetMode(pxConfig *config);
     42static bool addfilesetMode(pxConfig *config);
    4143
    4244# define MODECASE(caseName, func) \
     
    6769        MODECASE(DISTTOOL_MODE_PROCESSEDCOMPONENT, processedcomponentMode);
    6870        MODECASE(DISTTOOL_MODE_TOADVANCE, toadvanceMode);
     71        MODECASE(DISTTOOL_MODE_PENDINGFILESET, pendingfilesetMode);
     72        MODECASE(DISTTOOL_MODE_ADDFILESET, addfilesetMode);
    6973        default:
    7074            psAbort("invalid option (this should not happen)");
     
    790794    return true;
    791795}
     796
     797static bool pendingfilesetMode(pxConfig *config)
     798{
     799    PS_ASSERT_PTR_NON_NULL(config, false);
     800
     801    psMetadata *where = psMetadataAlloc();
     802    PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "==");
     803    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     804
     805    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     806    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     807
     808    // look for "inputs" that need to processed
     809    psString query = pxDataGet("disttool_pendingfileset.sql");
     810    if (!query) {
     811        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     812        return false;
     813    }
     814
     815    if (psListLength(where->list)) {
     816        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     817        psStringAppend(&query, " AND %s", whereClause);
     818        psFree(whereClause);
     819    }
     820    psFree(where);
     821
     822    // treat limit == 0 as "no limit"
     823    if (limit) {
     824        psString limitString = psDBGenerateLimitSQL(limit);
     825        psStringAppend(&query, " %s", limitString);
     826        psFree(limitString);
     827    }
     828
     829    if (!p_psDBRunQuery(config->dbh, query)) {
     830        psError(PS_ERR_UNKNOWN, false, "database error");
     831        psFree(query);
     832        return false;
     833    }
     834    psFree(query);
     835
     836    psArray *output = p_psDBFetchResult(config->dbh);
     837    if (!output) {
     838        psErrorCode err = psErrorCodeLast();
     839        switch (err) {
     840            case PS_ERR_DB_CLIENT:
     841                psError(PXTOOLS_ERR_SYS, false, "database error");
     842            case PS_ERR_DB_SERVER:
     843                psError(PXTOOLS_ERR_PROG, false, "database error");
     844            default:
     845                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     846        }
     847
     848        return false;
     849    }
     850    if (!psArrayLength(output)) {
     851        psTrace("disttool", PS_LOG_INFO, "no rows found");
     852        psFree(output);
     853        return true;
     854    }
     855
     856    if (psArrayLength(output)) {
     857        // negative simple so the default is true
     858        if (!ippdbPrintMetadatas(stdout, output, "pendingfileset", !simple)) {
     859            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     860            psFree(output);
     861            return false;
     862        }
     863    }
     864
     865    psFree(output);
     866
     867    return true;
     868}
     869static bool addfilesetMode(pxConfig *config)
     870{
     871
     872    // required values
     873    PXOPT_LOOKUP_S64(dist_id, config->args, "-dist_id", true, false);
     874    PXOPT_LOOKUP_S64(prod_id, config->args, "-prod_id", true, false);
     875
     876    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
     877
     878    // unless fault code is set require name
     879    PXOPT_LOOKUP_STR(name, config->args, "-name", fault == 0, false);
     880
     881    if (!rcDSFilesetInsert(config->dbh,
     882            0,          // fs_id
     883            dist_id,
     884            prod_id,
     885            name,
     886            "full",
     887            fault)) {
     888        psError(PS_ERR_UNKNOWN, false, "database error");
     889        return false;
     890    }
     891
     892    return true;
     893}
     894
Note: See TracChangeset for help on using the changeset viewer.