IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6876


Ignore:
Timestamp:
Apr 17, 2006, 3:03:37 PM (20 years ago)
Author:
jhoblitt
Message:

change to popen() exec of dsproductls

Location:
trunk/ippTools/src
Files:
2 edited

Legend:

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

    r6837 r6876  
     1#ifdef HAVE_CONFIG_H
     2#include <config.h>
     3#endif
     4
    15#include <stdlib.h>
    26#include <stdio.h>
     
    59#include "pzgetexp.h"
    610
    7 static bool parseInput(pxConfig *config);
     11static psArray *parseFileSets(pxConfig *config, const char *str);
    812
    913int main(int argc, char **argv)
    1014{
    11     pxConfig *config = pzgetexpConfig(config, argc, argv);
     15    pxConfig *config = pzgetexpConfig(NULL, argc, argv);
     16
     17    // find last fileset/exp_id (if we have one)
     18    bool haveLastFileSet = false;
     19    psString lastFileSet = NULL;
     20    psArray *summitExps = summitExpSelectRowObjects(config->dbh, NULL, 0);
     21    if (summitExps) {
     22        haveLastFileSet = true;
     23        summitExpRow *lastExps = summitExps->data[psArrayLength(summitExps) - 1];
     24        lastFileSet = psMemIncrRefCounter(lastExps->exp_id);
     25        psFree(summitExps);
     26    }
     27
     28    // invoke dsproductls
     29    // dsproductls --uri <> --last_fileset <> 
     30    {
     31        bool status = false;
     32        psString uri = psMetadataLookupStr(&status, config->args, "-uri");
     33        psString cmd = NULL;
     34        if (haveLastFileSet) {
     35            psStringAppend(&cmd, "dsproductls --uri %s --last_fileset %s",
     36                uri, lastFileSet);
     37        } else {
     38            psStringAppend(&cmd, "dsproductls --uri %s", uri);
     39        }
     40
     41        FILE *output = popen(cmd, "r");
     42        psFree(cmd);
     43
     44        if (!output) {
     45            psError(PS_ERR_UNKNOWN, true, "popen() failed");
     46            goto FAIL;
     47        }
     48        psString cmdOutput = fslurp(output);
     49        pclose(output);
     50        parseFileSets(config, cmdOutput);
     51    }
     52
     53    psFree(lastFileSet);
    1254
    1355    /*
    14     switch (config->mode) {
    15         case PX_MODE_SEEN:
    16             if (!seenMode(config)) {
    17                 goto FAIL;
    18             }
    19             break;
    20         default:
    21             psAbort(argv[0], "invalid option (this should not happen)");
     56    psArray *summitExps = parseInput(config);
     57    if (!summitExps) {
     58        goto FAIL;
     59    }
     60
     61    // insert new entries into the database
     62    for (long i = 0; i < psArrayLength(summitExps); i++) {
     63        if (!summitExpInsertObject(config->dbh, summitExps->data[i])) {
     64            psError(PS_ERR_UNKNOWN, false, "dbh access failed");
     65            goto FAIL;
     66        }
    2267    }
    2368    */
    2469
    25     parseInput(config);
     70    psFree(config);
    2671
    2772    exit(EXIT_SUCCESS);
    2873
    2974FAIL:
    30 //    psFree(config);
     75    psFree(config);
    3176    exit(EXIT_FAILURE);
    3277}
    3378
    34 static bool parseInput(pxConfig *config)
     79static psArray *parseFileSets(pxConfig *config, const char *str)
    3580{
    36     psString input = slurp(stdin);
    37     psList *lines = psStringSplit(input, "\n");
     81    psList *lines = psStringSplit(str, "\n");
    3882
    3983    psListIterator *lineCursor = psListIteratorAlloc(lines, 0, false);
     
    4791        psList *tokens = psStringSplit(item, " ");
    4892
     93        // check to see if this line is a comment (or if the first token is
     94        // NULL)
     95        if (!psListGet(tokens, 0) || *((char *)psListGet(tokens, 0)) == '#') {
     96            psFree(tokens);
     97            continue;
     98        }
     99
    49100        // check that we have the right number of tokens
    50101        // print "# uri fileset datetime type\n";
     
    55106
    56107        psListIterator *tokenCursor = psListIteratorAlloc(tokens, 0, false);
    57 
    58108        char *uri       = psListGetAndIncrement(tokenCursor);
    59109        char *exp_id    = psListGetAndIncrement(tokenCursor); // fileset
     
    61111        char *exp_type  = psListGetAndIncrement(tokenCursor); // type
    62112
    63         psFree(tokenCursor);
     113        bool status = false;
     114        char *camera_name = psMetadataLookupStr(&status, config->args,
     115            "-inst");
     116        char *telescope   = psMetadataLookupStr(&status, config->args,
     117            "-telescope");
    64118
    65119        summitExpRow *row = summitExpRowAlloc(
    66120            exp_id,
    67             config->camera,
    68             config->telescope,
     121            camera_name,
     122            telescope,
    69123            exp_type,
    70124            uri
    71125        );
     126
     127        psFree(tokenCursor);
     128        psFree(tokens);
     129
    72130        psArrayAdd(summitExps, 0, row);
    73131    }
     
    75133    psFree(lineCursor);
    76134    psFree(lines);
    77     psFree(input);
    78135
    79     for (long i = 0; i < psArrayLength(summitExps); i++) {
    80         if (!summitExpInsertObject(config->dbh, summitExps->data[i])) {
    81             psError(PS_ERR_UNKNOWN, false, "dbh access failed");
    82             return false;
    83         }
    84     }
    85 
    86     psFree(summitExps);
     136    return summitExps;
    87137}
  • trunk/ippTools/src/pzgetexpConfig.c

    r6837 r6876  
    2121        "telescope name", "");
    2222
    23     bool argErr = false;
    24     if (! psArgumentParse(args, &argc, argv) || argc != 2) {
    25         argErr = true;
    26         fprintf (stderr, "error parsing arguments\n");
    27     }
    28 
    29     if (argErr) {
     23    bool status = false;
     24    if (!psArgumentParse(args, &argc, argv)
     25        || argc != 1
     26        || strcmp(psMetadataLookupStr(&status, args, "-uri"), "") == 0
     27        || strcmp(psMetadataLookupStr(&status, args, "-inst"), "") == 0
     28        || strcmp(psMetadataLookupStr(&status, args, "-telescope"), "") == 0
     29    ) {
     30        fprintf(stderr, "error parsing arguments\n");
    3031        printf("\nPan-STARRS Phase Z Search Tool\n");
    3132        printf("Usage: %s -uri -inst -telescope\n\n", argv[0]);
    3233        psArgumentHelp(args);
    33         psFree(args);
     34        psFree(config);
    3435        exit(EXIT_FAILURE);
    3536    }
    3637
    3738    config->args = args;
     39    // don't free args here as it's silly to increment the ref count then
     40    // "free" it
    3841
    3942    // define Database handle, if used
    4043    config->dbh = pmConfigDB(config->site);
     44    if(!config->dbh) {
     45        psError(PS_ERR_UNKNOWN, false, "Can't connect to db\n");
     46        psFree(config);
     47        exit(EXIT_FAILURE);
     48    }
    4149
    4250    return config;
Note: See TracChangeset for help on using the changeset viewer.