IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25792


Ignore:
Timestamp:
Oct 7, 2009, 12:40:12 PM (17 years ago)
Author:
bills
Message:

changes to magicdstool -updaterun to allow run state changes by label, stage, and stage_id
(for safety at least 2 arguments are required);

Location:
trunk/ippTools/src
Files:
2 edited

Legend:

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

    r25513 r25792  
    4444static bool completedrevertMode(pxConfig *config);
    4545
    46 static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, const char *state);
     46static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, psMetadata *where, const char *state);
    4747static bool magicDSGetIDs(pxConfig *config, psString stage, psS64 magic_id, psS64 *stage_id, psS64 *cam_id);
    4848
     
    381381
    382382    // required
    383     PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false);
    384     PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
    385 
    386     if (state) {
    387         // set detRun.state to state
    388         return setmagicDSRunState(config, magic_ds_id, state);
    389     }
    390 
    391     return true;
     383    PXOPT_LOOKUP_STR(state, config->args, "-set_state", true, false);
     384
     385    PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", false, false);
     386    if (magic_ds_id) {
     387
     388        return setmagicDSRunState(config, magic_ds_id, NULL, state);
     389
     390    } else if (!strcmp(state, "full")) {
     391        psError(PS_ERR_UNKNOWN, true, "magic_ds_id is required to update run state to full");
     392        return false;
     393    }
     394    // we can transition by query as well
     395
     396    psMetadata *where = psMetadataAlloc();
     397    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     398    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     399    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     400
     401
     402    if (psListLength(where->list) < 2) {
     403        psError(PS_ERR_UNKNOWN, true, "at least 2 search arguments are required");
     404        return false;
     405    }
     406
     407
     408    PXOPT_LOOKUP_BOOL(noreplace, config->args, "-noreplace", false);
     409    if (!noreplace) {
     410        psMetadataAddS32(where, PS_LIST_TAIL, "re_place", 0, ">", 0);
     411    }
     412    bool result = setmagicDSRunState(config, magic_ds_id, where, state);
     413    psFree(where);
     414
     415    return result;
    392416}
    393417
     
    796820
    797821        // set magicDSRun.state to 'full'
    798         if (!setmagicDSRunState(config, magic_ds_id, "full")) {
     822        if (!setmagicDSRunState(config, magic_ds_id, NULL, "full")) {
    799823            psError(PS_ERR_UNKNOWN, false, "failed to change magicDSRun.state for magic_ds_id: %" PRId64,
    800824                magic_ds_id);
     
    9941018}
    9951019
    996 static bool setmagicDSRunState(pxConfig *config, psS64 magic_ds_id, const char *state)
    997 {
    998     PS_ASSERT_PTR_NON_NULL(state, false);
    999 
    1000     // check that state is a valid string value
     1020static bool validDSRunState(const char *state)
     1021{
    10011022    if (!((strcmp(state, "new") == 0) ||
    10021023          (strcmp(state, "full") == 0) ||
     
    10081029          (strcmp(state, "goto_purged") == 0))
    10091030        ) {
     1031        return false;
     1032    } else {
     1033        return true;
     1034    }
     1035}
     1036
     1037static bool setmagicDSRunState(pxConfig *config, psS64 magic_ds_id, psMetadata *where, const char *state)
     1038{
     1039    PS_ASSERT_PTR_NON_NULL(state, false);
     1040
     1041    if (!validDSRunState(state)) {
    10101042        psError(PS_ERR_UNKNOWN, false,
    10111043                "invalid magicDSRun state: %s", state);
     
    10131045    }
    10141046
    1015     char *query = "UPDATE magicDSRun SET state = '%s' WHERE magic_ds_id = %" PRId64;
    1016     if (!p_psDBRunQueryF(config->dbh, query, state, magic_ds_id)) {
     1047    psString query = psStringCopy("UPDATE magicDSRun SET state = '%s'");
     1048    if (magic_ds_id) {
     1049        psStringAppend(&query, " WHERE magic_ds_id = %" PRId64, magic_ds_id);
     1050    } else if (where && psListLength(where->list)) {
     1051        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1052        psStringAppend(&query, " WHERE %s", whereClause);
     1053        psFree(whereClause);
     1054    } else {
     1055        psError(PS_ERR_UNKNOWN, true, "search arugments are required");
     1056        return false;
     1057    }
     1058
     1059    if (!p_psDBRunQueryF(config->dbh, query, state)) {
    10171060        psError(PS_ERR_UNKNOWN, false,
    10181061                "failed to change state for magic_id %" PRId64, magic_ds_id);
  • trunk/ippTools/src/magicdstoolConfig.c

    r25492 r25792  
    8282    // -updaterun
    8383    psMetadata *updaterunArgs = psMetadataAlloc();
    84     psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "define magictool ID (required)", 0);
    85     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0, "set state (required)", NULL);
     84    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0, "set state (required)", NULL);
     85    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "define magictool ID", 0);
     86    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-stage",     0, "define stage", NULL);
     87    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-stage_id", 0, "define stage_id", 0);
     88    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label",     0, "define label", NULL);
     89    psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-noreplace", 0, "only update runs with replace not set", false);
    8690
    8791    // -addinputskyfile
Note: See TracChangeset for help on using the changeset viewer.