IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

add pztool -datastore
add pztool -adddatastore

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.