IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 24, 2010, 2:59:09 PM (16 years ago)
Author:
Paul Price
Message:

Merging trunk in advance of reintegrating into trunk.

Location:
branches/pap
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/ippTools/src

    • Property svn:ignore
      •  

        old new  
        3939warptool
        4040staticskytool
        41 
        4241bgtool
         42diffphottool
  • branches/pap/ippTools/src/pubtool.c

    r27071 r28484  
    151151    PS_ASSERT_PTR_NON_NULL(config, false);
    152152
    153     psMetadata *where = psMetadataAlloc(); // WHERE conditions
     153    psMetadata *diffWhere = psMetadataAlloc(); // WHERE conditions for diffs
     154    psMetadata *camWhere = psMetadataAlloc(); // WHERE conditions for cams
     155    psMetadata *diffphotWhere = psMetadataAlloc(); // WHERE conditions for diffphots
    154156
    155157    // required
    156158
    157159    // optional
    158     PXOPT_COPY_S64(config->args, where, "-client_id", "client_id", "==");
    159     pxAddLabelSearchArgs(config, where, "-label", "label", "=="); // define using newExp label
     160    PXOPT_COPY_S64(config->args, diffWhere, "-client_id", "client_id", "==");
     161    pxAddLabelSearchArgs(config, diffWhere, "-label", "diffRun.label", "==");
     162    pxAddLabelSearchArgs(config, diffWhere, "-data_group", "diffRun.data_group", "LIKE");
     163    PXOPT_COPY_TIME(config->args, diffWhere, "-dateobs_begin", "rawExp.dateobs", ">=");
     164    PXOPT_COPY_TIME(config->args, diffWhere, "-dateobs_end", "rawExp.dateobs", "<=");
     165    PXOPT_COPY_STR(config->args, diffWhere, "-filter", "rawExp.filter", "LIKE");
     166    PXOPT_COPY_STR(config->args, diffWhere, "-obs_mode", "rawExp.obs_mode", "LIKE");
     167
     168    PXOPT_COPY_S64(config->args, camWhere, "-client_id", "client_id", "==");
     169    pxAddLabelSearchArgs(config, camWhere, "-label", "camRun.label", "==");
     170    pxAddLabelSearchArgs(config, camWhere, "-data_group", "camRun.data_group", "LIKE");
     171    PXOPT_COPY_TIME(config->args, camWhere, "-dateobs_begin", "rawExp.dateobs", ">=");
     172    PXOPT_COPY_TIME(config->args, camWhere, "-dateobs_end", "rawExp.dateobs", "<=");
     173    PXOPT_COPY_STR(config->args, camWhere, "-filter", "rawExp.filter", "LIKE");
     174    PXOPT_COPY_STR(config->args, camWhere, "-obs_mode", "rawExp.obs_mode", "LIKE");
     175
     176    PXOPT_COPY_S64(config->args, diffphotWhere, "-client_id", "client_id", "==");
     177    pxAddLabelSearchArgs(config, diffphotWhere, "-label", "diffphotRun.label", "==");
     178    pxAddLabelSearchArgs(config, diffphotWhere, "-data_group", "diffphotRun.data_group", "LIKE");
     179    PXOPT_COPY_TIME(config->args, diffphotWhere, "-dateobs_begin", "rawExp.dateobs", ">=");
     180    PXOPT_COPY_TIME(config->args, diffphotWhere, "-dateobs_end", "rawExp.dateobs", "<=");
     181    PXOPT_COPY_STR(config->args, diffphotWhere, "-filter", "rawExp.filter", "LIKE");
     182    PXOPT_COPY_STR(config->args, diffphotWhere, "-obs_mode", "rawExp.obs_mode", "LIKE");
     183
     184    PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
     185    PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false);
     186    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
     187    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     188    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    160189
    161190    psString query = pxDataGet("pubtool_definerun.sql"); // Query to run
    162191    if (!query) {
    163192        psError(PXTOOLS_ERR_SYS, false, "Failed to retreive SQL statement");
    164         psFree(where);
    165         return false;
     193        psFree(diffWhere);
     194        psFree(camWhere);
     195        return false;
     196    }
     197
     198    if (!rerun) {
     199        psStringAppend(&query, "\nWHERE publishRun.client_id IS NULL");
     200    }
     201
     202    if (limit) {
     203        psString limitString = psDBGenerateLimitSQL(limit);
     204        psStringAppend(&query, "\n%s", limitString);
     205        psFree(limitString);
    166206    }
    167207
    168208    if (!psDBTransaction(config->dbh)) {
    169209        psError(PS_ERR_UNKNOWN, false, "Database error");
    170         psFree(where);
    171         return false;
    172     }
    173 
    174     psString whereClause = psStringCopy(""); // Additional constraints to add to query
    175     if (psListLength(where->list)) {
    176         psString clause = psDBGenerateWhereConditionSQL(where, NULL);
    177         psStringAppend(&whereClause, "\n AND %s", clause);
     210        psFree(diffWhere);
     211        psFree(camWhere);
     212        psFree(diffphotWhere);
     213        return false;
     214    }
     215
     216    psString whereDiff = psStringCopy(""); // Additional constraints to add to query
     217    if (psListLength(diffWhere->list)) {
     218        psString clause = psDBGenerateWhereConditionSQL(diffWhere, NULL);
     219        psStringAppend(&whereDiff, "\n AND %s", clause);
    178220        psFree(clause);
    179221    }
    180     psFree(where);
    181 
    182     if (!p_psDBRunQueryF(config->dbh, query, whereClause, whereClause)) {
     222    psFree(diffWhere);
     223
     224    psString whereCam = psStringCopy(""); // Additional constraints to add to query
     225    if (psListLength(camWhere->list)) {
     226        psString clause = psDBGenerateWhereConditionSQL(camWhere, NULL);
     227        psStringAppend(&whereCam, "\n AND %s", clause);
     228        psFree(clause);
     229    }
     230    psFree(camWhere);
     231
     232    psString whereDiffphot = psStringCopy(""); // Additional constraints to add to query
     233    if (psListLength(diffphotWhere->list)) {
     234        psString clause = psDBGenerateWhereConditionSQL(diffphotWhere, NULL);
     235        psStringAppend(&whereDiffphot, "\n AND %s", clause);
     236        psFree(clause);
     237    }
     238    psFree(diffphotWhere);
     239
     240    if (!p_psDBRunQueryF(config->dbh, query, whereDiff, whereCam, whereDiffphot)) {
    183241        psError(PS_ERR_UNKNOWN, false, "Database error");
    184242        psFree(query);
    185         psFree(whereClause);
     243        psFree(whereDiff);
     244        psFree(whereCam);
     245        psFree(whereDiffphot);
    186246        if (!psDBRollback(config->dbh)) {
    187247            psError(PS_ERR_UNKNOWN, false, "Database error");
     
    190250    }
    191251    psFree(query);
    192     psFree(whereClause);
     252    psFree(whereDiff);
     253    psFree(whereCam);
     254    psFree(whereDiffphot);
    193255
    194256    psArray *output = p_psDBFetchResult(config->dbh); // Output of SELECT statement
     
    206268    }
    207269
     270    if (pretend) {
     271        if (!ippdbPrintMetadatas(stdout, output, "publishRun", !simple)) {
     272            psError(psErrorCodeLast(), false, "Failed to print array");
     273            psFree(output);
     274            return false;
     275        }
     276        psFree(output);
     277        return true;
     278    }
     279
    208280    for (int i = 0; i < output->n; i++) {
    209281        psMetadata *row = output->data[i]; // Row of interest
    210282        psS64 client = psMetadataLookupS64(NULL, row, "client_id"); // Client identifier
    211283        psS64 stage = psMetadataLookupS64(NULL, row, "stage_id");   // Stage identifier
    212         char *label = psMetadataLookupStr(NULL, row, "src_label");   // label from correct source
    213 
    214         if (!publishRunInsert(config->dbh, 0, client, stage, label, "new")) {
     284        const char *label = psMetadataLookupStr(NULL, row, "src_label");   // label from correct source
     285
     286        if (!publishRunInsert(config->dbh, 0, client, stage, set_label ? set_label : label, "new")) {
    215287            psError(PS_ERR_UNKNOWN, false, "Unable to add fileset");
    216288            psFree(output);
     
    241313    PXOPT_COPY_STR(config->args, where, "-stage", "publishClient.stage", "==");
    242314    PXOPT_COPY_STR(config->args, where, "-comment", "publishClient.comment", "LIKE");
    243     PXOPT_COPY_STR(config->args, where, "-label", "publishRun.label", "==");
     315    pxAddLabelSearchArgs(config, where, "-label", "publishRun.label", "==");
    244316
    245317    // optional
Note: See TracChangeset for help on using the changeset viewer.