IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14666


Ignore:
Timestamp:
Aug 24, 2007, 5:28:13 PM (19 years ago)
Author:
jhoblitt
Message:

-definerun & -updaterun

File:
1 edited

Legend:

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

    r14537 r14666  
    4242static bool addskyfilemaskMode(pxConfig *config);
    4343
     44static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state);
     45
    4446# define MODECASE(caseName, func) \
    4547    case caseName: \
     
    9496{
    9597    PS_ASSERT_PTR_NON_NULL(config, false);
    96     return 0;
     98
     99    // required options
     100    bool status = false;
     101    psString workdir = psMetadataLookupStr(&status, config->args, "-workdir");
     102    if (!status) {
     103        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -workdir");
     104        return false;
     105    }
     106    if (!workdir) {
     107        psError(PS_ERR_UNKNOWN, true, "-workdir is required");
     108        return false;
     109    }
     110
     111    psString label = psMetadataLookupStr(&status, config->args, "-label");
     112    if (!status) {
     113        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -label");
     114        return false;
     115    }
     116
     117    psString dvodb = psMetadataLookupStr(&status, config->args, "-dvodb");
     118    if (!status) {
     119        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -dvodb");
     120        return false;
     121    }
     122
     123    psTime *registered = NULL;
     124    {
     125        psString registeredStr = psMetadataLookupStr(&status, config->args, "-registered");
     126        if (!status) {
     127            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -registered");
     128            return false;
     129        }
     130        // pass through NULL as this is an optional field
     131        if (registeredStr) {
     132            registered = psTimeFromISO(registeredStr, PS_TIME_UTC);
     133        } else {
     134            registered = NULL;
     135        }
     136    }
     137
     138   magicRunRow *run = magicRunRowAlloc(
     139            0,          // ID
     140            "reg",      // state
     141            workdir,
     142            "dirty",    // workdir_state
     143            label,
     144            dvodb,
     145            registered
     146    );
     147    psFree(registered);
     148    if (!run) {
     149        psError(PS_ERR_UNKNOWN, false, "failed to alloc magicRun object");
     150        return true;
     151    }
     152    if (!magicRunInsertObject(config->dbh, run)) {
     153        psError(PS_ERR_UNKNOWN, false, "database error");
     154        psFree(run);
     155        return true;
     156    }
     157
     158    // get the assigned warp_id
     159    psS64 magic_id = psDBLastInsertID(config->dbh);
     160    run->magic_id = magic_id;
     161
     162    bool simple = false;
     163    {
     164        bool status = false;
     165        simple = psMetadataLookupBool(&status, config->args, "-simple");
     166        if (!status) {
     167            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     168            psFree(run);
     169            return false;
     170        }
     171    }
     172
     173    if (!magicRunPrintObject(stdout, run, !simple)) {
     174            psError(PS_ERR_UNKNOWN, false, "failed to print object");
     175            psFree(run);
     176            return false;
     177    }
     178
     179    psFree(run);
     180
     181    return magic_id;
    97182}
    98183
     
    101186{
    102187    PS_ASSERT_PTR_NON_NULL(config, false);
     188
     189    bool status = false;
     190    psString magic_id = psMetadataLookupStr(&status, config->args, "-magic_id");
     191    if (!status) {
     192        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -magic_id");
     193        return false;
     194    }
     195    if (!magic_id) {
     196        psError(PS_ERR_UNKNOWN, true, "-magic_id is required");
     197        return false;
     198    }
     199
     200    psString state = psMetadataLookupStr(&status, config->args, "-state");
     201    if (!status) {
     202        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state");
     203        return false;
     204    }
     205    if (!state) {
     206        psError(PS_ERR_UNKNOWN, true, "-state is required");
     207        return false;
     208    }
     209
     210    if (state) {
     211        // set detRun.state to state
     212        return setmagicRunState(config, (psS64)atoll(magic_id), state);
     213    }
     214
    103215    return true;
    104216}
     
    12841396    return true;
    12851397}
    1286 
    1287 
    1288 static bool setwarpRunState(pxConfig *config, psS64 warp_id, const char *state)
     1398#endif
     1399
     1400
     1401static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state)
    12891402{
    12901403    PS_ASSERT_PTR_NON_NULL(state, false);
     
    12981411    ) {
    12991412        psError(PS_ERR_UNKNOWN, false,
    1300                 "invalid warpRun state: %s", state);
    1301         return false;
    1302     }
    1303 
    1304     char *query = "UPDATE warpRun SET state = '%s' WHERE warp_id = %" PRId64;
    1305     if (!p_psDBRunQuery(config->dbh, query, state, warp_id)) {
     1413                "invalid magicRun state: %s", state);
     1414        return false;
     1415    }
     1416
     1417    char *query = "UPDATE magicRun SET state = '%s' WHERE magic_id = %" PRId64;
     1418    if (!p_psDBRunQuery(config->dbh, query, state, magic_id)) {
    13061419        psError(PS_ERR_UNKNOWN, false,
    1307                 "failed to change state for warp_id %" PRId64, warp_id);
    1308         return false;
    1309     }
    1310 
    1311     return true;
    1312 }
    1313 
    1314 
     1420                "failed to change state for magic_id %" PRId64, magic_id);
     1421        return false;
     1422    }
     1423
     1424    return true;
     1425}
     1426
     1427
     1428#if 0
    13151429static bool isValidMode(pxConfig *config, const char *mode)
    13161430{
Note: See TracChangeset for help on using the changeset viewer.