IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15234


Ignore:
Timestamp:
Oct 5, 2007, 5:38:27 PM (19 years ago)
Author:
jhoblitt
Message:

add pztool -datastore
add pztool -adddatastore

Location:
trunk/ippTools/src
Files:
4 edited

Legend:

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

    r14485 r15234  
    5151    }
    5252#endif
     53    CREATE_TABLE(pzDataStoreCreateTable);
    5354    CREATE_TABLE(summitExpCreateTable);
    5455    CREATE_TABLE(summitImfileCreateTable);
     
    137138
    138139//    DROP_TABLE(expTagCounterDropTable);
     140    DROP_TABLE(pzDataStoreDropTable);
    139141    DROP_TABLE(summitExpDropTable);
    140142    DROP_TABLE(summitImfileDropTable);
  • trunk/ippTools/src/pztool.c

    r15167 r15234  
    3131#include "pztool.h"
    3232
     33static bool adddatastoreMode(pxConfig *config);
     34static bool datastoreMode(pxConfig *config);
    3335static bool seenMode(pxConfig *config);
    3436static bool pendingExpMode(pxConfig *config);
     
    5961
    6062    switch (config->mode) {
     63        MODECASE(PZTOOL_MODE_ADDDATASTORE, adddatastoreMode);
     64        MODECASE(PZTOOL_MODE_DATASTORE, datastoreMode);
    6165        MODECASE(PZTOOL_MODE_SEEN, seenMode);
    6266        MODECASE(PZTOOL_MODE_PENDINGEXP, pendingExpMode);
     
    8286
    8387    exit(exit_status);
     88}
     89
     90static bool adddatastoreMode(pxConfig *config)
     91{
     92    PS_ASSERT_PTR_NON_NULL(config, false);
     93
     94    bool status = false;
     95    psString camera = psMetadataLookupStr(&status, config->args, "-inst");
     96    if (!status) {
     97        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst");
     98        return false;
     99    }
     100    if (!camera) {
     101        psError(PS_ERR_UNKNOWN, true, "-inst is required");
     102        return false;
     103    }
     104
     105    psString telescope = psMetadataLookupStr(&status, config->args, "-telescope");
     106    if (!status) {
     107        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -telescope");
     108        return false;
     109    }
     110    if (!telescope) {
     111        psError(PS_ERR_UNKNOWN, true, "-telescope is required");
     112        return false;
     113    }
     114
     115    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
     116    if (!status) {
     117        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
     118        return false;
     119    }
     120    if (!uri) {
     121        psError(PS_ERR_UNKNOWN, true, "-uri is required");
     122        return false;
     123    }
     124
     125    if (!pzDataStoreInsert(config->dbh,
     126            camera,
     127            telescope,
     128            uri
     129        )) {
     130        psError(PS_ERR_UNKNOWN, false, "database error");
     131        return false;
     132    }
     133
     134    return true;
     135}
     136
     137static bool datastoreMode(pxConfig *config)
     138{
     139    PS_ASSERT_PTR_NON_NULL(config, false);
     140
     141    if (!p_psDBRunQuery(config->dbh, "SELECT * FROM pzDataStore")) {
     142        psError(PS_ERR_UNKNOWN, false, "database error");
     143        return false;
     144    }
     145
     146    psArray *output = p_psDBFetchResult(config->dbh);
     147    if (!output) {
     148        psError(PS_ERR_UNKNOWN, false, "database error");
     149        return false;
     150    }
     151    if (!psArrayLength(output)) {
     152        psTrace("pztool", PS_LOG_INFO, "no rows found");
     153        psFree(output);
     154        return true;
     155    }
     156
     157    bool simple = false;
     158    {
     159        bool status = false;
     160        simple = psMetadataLookupBool(&status, config->args, "-simple");
     161        if (!status) {
     162            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     163            return false;
     164        }
     165    }
     166
     167    // negative simple so the default is true
     168    if (!ippdbPrintMetadatas(stdout, output, "pzDataStore", !simple)) {
     169        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     170        psFree(output);
     171        return false;
     172    }
     173
     174    psFree(output);
     175
     176    return true;
    84177}
    85178
  • trunk/ippTools/src/pztool.h

    r10025 r15234  
    2525typedef enum {
    2626    PZTOOL_MODE_NONE      = 0x0,
     27    PZTOOL_MODE_ADDDATASTORE,
     28    PZTOOL_MODE_DATASTORE,
    2729    PZTOOL_MODE_SEEN,
    2830    PZTOOL_MODE_PENDINGEXP,
  • trunk/ippTools/src/pztoolConfig.c

    r15032 r15234  
    4242        return NULL;
    4343    }
     44
     45    // -adddatastore
     46    psMetadata *adddatastoreArgs = psMetadataAlloc();
     47    psMetadataAddStr(adddatastoreArgs, PS_LIST_TAIL, "-inst", 0,
     48            "define camera ID", NULL);
     49    psMetadataAddStr(adddatastoreArgs, PS_LIST_TAIL, "-telescope", 0,
     50            "define telescope ID", NULL);
     51    psMetadataAddStr(adddatastoreArgs, PS_LIST_TAIL, "-uri", 0,
     52            "define storage uri", NULL);
     53   
     54    // -datastore
     55    psMetadata *datastoreArgs = psMetadataAlloc();
     56    psMetadataAddBool(datastoreArgs, PS_LIST_TAIL, "-simple", 0,
     57            "use the simple output format", false);
    4458
    4559    // -seen
     
    123137    psMetadata *modes = psMetadataAlloc();
    124138
     139    PXTOOL_ADD_MODE("-adddatastore",    "", PZTOOL_MODE_ADDDATASTORE, adddatastoreArgs);
     140    PXTOOL_ADD_MODE("-datastore",       "", PZTOOL_MODE_DATASTORE,    datastoreArgs);
    125141    PXTOOL_ADD_MODE("-seen",            "", PZTOOL_MODE_SEEN,         seenArgs);
    126142    PXTOOL_ADD_MODE("-pendingexp",      "", PZTOOL_MODE_PENDINGEXP,   pendingexpArgs);
Note: See TracChangeset for help on using the changeset viewer.