IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

add new summitExps to the database

File:
1 edited

Legend:

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

    r6876 r6880  
    1818    bool haveLastFileSet = false;
    1919    psString lastFileSet = NULL;
     20    // XXX this is a very ugly and brute force way of doing things need to add
     21    // a metadatadb function to retrun the last entry without removing it from
     22    // the database
    2023    psArray *summitExps = summitExpSelectRowObjects(config->dbh, NULL, 0);
    2124    if (summitExps) {
     
    2326        summitExpRow *lastExps = summitExps->data[psArrayLength(summitExps) - 1];
    2427        lastFileSet = psMemIncrRefCounter(lastExps->exp_id);
    25         psFree(summitExps);
    2628    }
    2729
    2830    // invoke dsproductls
    2931    // 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);
     32    bool status = false;
     33    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
     34    psString cmd = NULL;
     35    if (haveLastFileSet) {
     36        psStringAppend(&cmd, "dsproductls --uri %s --last_fileset %s",
     37            uri, lastFileSet);
     38        psFree(lastFileSet);
     39    } else {
     40        psStringAppend(&cmd, "dsproductls --uri %s", uri);
    5141    }
    5242
    53     psFree(lastFileSet);
     43    fprintf(stderr, "cmd is: %s\n", cmd);
    5444
    55     /*
    56     psArray *summitExps = parseInput(config);
    57     if (!summitExps) {
     45    FILE *output = popen(cmd, "r");
     46    psFree(cmd);
     47
     48    if (!output) {
     49        psError(PS_ERR_UNKNOWN, true, "popen() failed");
     50        goto FAIL;
     51    }
     52    psString cmdOutput = fslurp(output);
     53    pclose(output);
     54
     55    psArray *newSummitExps = parseFileSets(config, cmdOutput);
     56    psFree(cmdOutput);
     57    if (!newSummitExps) {
     58        // XXX not nessicarily an error
     59        psError(PS_ERR_UNKNOWN, true, "no new fileSet/exp IDs");
    5860        goto FAIL;
    5961    }
    6062
     63    // try not to insert duplicate summitExp entries
     64    // XXX this will become very expensive as the number of summitExp entry
     65    // grows -- is just blindly ignoring database errors the best thing to do?
     66    if (summitExps) {
     67        for (long i = 0; i < psArrayLength(newSummitExps); i++) {
     68            summitExpRow *newSummitExp = newSummitExps->data[i];
     69            for (long j = 0; j < psArrayLength(summitExps); j++) {
     70                summitExpRow *summitExp = summitExps->data[j];
     71                if (strcmp(newSummitExp->exp_id,
     72                           summitExp->exp_id) == 0) {
     73                    psArrayRemove(newSummitExps, newSummitExp);
     74                    // dec the counter as the array just got shorter
     75                    // and we don't want to skip elemnts
     76                    i--;
     77                    break;
     78                }
     79            }
     80        }
     81        psFree(summitExps);
     82    }
     83
    6184    // insert new entries into the database
    62     for (long i = 0; i < psArrayLength(summitExps); i++) {
    63         if (!summitExpInsertObject(config->dbh, summitExps->data[i])) {
     85    for (long i = 0; i < psArrayLength(newSummitExps); i++) {
     86        if (!summitExpInsertObject(config->dbh, newSummitExps->data[i])) {
    6487            psError(PS_ERR_UNKNOWN, false, "dbh access failed");
    6588            goto FAIL;
    6689        }
    6790    }
    68     */
    6991
    7092    psFree(config);
     
    7496FAIL:
    7597    psFree(config);
     98
    7699    exit(EXIT_FAILURE);
    77100}
     
    79102static psArray *parseFileSets(pxConfig *config, const char *str)
    80103{
     104    PS_ASSERT_PTR_NON_NULL(config, NULL);
     105    PS_ASSERT_PTR_NON_NULL(str, NULL);
     106
    81107    psList *lines = psStringSplit(str, "\n");
    82108
Note: See TracChangeset for help on using the changeset viewer.