IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:50:52 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/simtest_nebulous_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/simtest_nebulous_branches

  • branches/simtest_nebulous_branches/ippTools/src

    • Property svn:ignore
      •  

        old new  
         1*.la
         2*.lo
        13.deps
        24.gdb_history
         
        46Makefile
        57Makefile.in
         8addtool
         9caltool
         10camtool
         11chiptool
        612config.h
        713config.h.in
        8 stamp-h1
        9 *.la
        10 *.lo
         14detselect
         15dettool
         16difftool
         17disttool
         18dqstatstool
         19faketool
         20flatcorr
         21guidetool
         22magicdstool
         23magictool
         24pstamptool
         25pubtool
         26pxadmin
         27pxdata.c
         28pxinject
        1129pxtoolsErrorCodes.c
        1230pxtoolsErrorCodes.h
        13 pxadmin
        14 pxinject
        15 pztool
        1631pzgetexp
        1732pzgetimfiles
         33pztool
         34receivetool
        1835regtool
        19 guidetool
        20 chiptool
        21 camtool
         36stacktool
         37stamp-h1
        2238warptool
        23 difftool
        24 stacktool
        25 faketool
        26 dettool
        27 detselect
        28 pxdata.c
        29 magictool
        30 magicdstool
        31 caltool
        32 flatcorr
        33 pstamptool
        34 disttool
        35 receivetool
        36 
        37 pubtool
  • branches/simtest_nebulous_branches/ippTools/src/pxtools.c

    r23918 r27840  
    3737    if (!strcmp(state, "goto_cleaned")) return true;
    3838    if (!strcmp(state, "error_cleaned")) return true;
     39    if (!strcmp(state, "goto_purged")) return true;
     40    if (!strcmp(state, "error_purged")) return true;
    3941    if (!strcmp(state, "goto_scrubbed")) return true;
    4042    if (!strcmp(state, "error_scrubbed")) return true;
     
    4244    if (!strcmp(state, "update")) return true;
    4345    if (!strcmp(state, "purged")) return true;
    44     if (!strcmp(state, "goto_purged")) return true;
    45     if (!strcmp(state, "error_purged")) return true;
    46 
     46    if (!strcmp(state, "scrubbed")) return true;
    4747    return false;
    4848}
    4949
    50 // 'scrubbed' is a virtual state equivalent to cleaned, but allows files to be removed
    51 // even if the config files is missing
     50// 'scrubbed' is no longer a virtual state equivalent to cleaned, but allows files to be removed
     51// even if the config files is missing.  This change was prompted as files that are cleaned can
     52// be regenerated, but that is not certain after being scrubbed.
    5253
    5354
     
    6061        if (!state) {
    6162            psError(PS_ERR_PROGRAMMING, false, "%s not found in row %ld of table %s",
    62                     columnName, i, tableName);
     63                    columnName, i, tableName);
    6364            return false;
    6465        }
     
    6970            // if state isn't cleaned or full we can't set it to cleaned
    7071            psError(PS_ERR_PROGRAMMING, true, "%s with state %s may not be exported cleaned",
    71                     tableName, state);
     72                    tableName, state);
    7273            return false;
    7374        }
     
    8990    psAssert (entry, "%s should at least have a place-holder", name);
    9091    if (entry->data.str) {
    91         psListIterator *iter = psListIteratorAlloc (item->data.list, PS_LIST_HEAD, true);
    92         psMetadataItem *item = NULL;
    93         while ((item = psListGetAndIncrement(iter))) {
    94             // need to change the name and comment
    95             psFree (item->name);
    96             item->name = psStringCopy (field);
    97             psFree (item->comment);
    98             item->comment = psStringCopy (op);
    99             if (!psMetadataAddItem(where, item, PS_LIST_TAIL, PS_META_DUPLICATE_OK)) {
    100                 psError(PS_ERR_UNKNOWN, false, "failed to add item %s", field);
    101                 psFree(where);
    102                 return false;
    103             }
    104         }
    105         psFree (iter);
    106     }
    107     return true;
    108 }
     92        psListIterator *iter = psListIteratorAlloc (item->data.list, PS_LIST_HEAD, true);
     93        psMetadataItem *item = NULL;
     94        while ((item = psListGetAndIncrement(iter))) {
     95            // need to change the name and comment
     96            psFree (item->name);
     97            item->name = psStringCopy (field);
     98            psFree (item->comment);
     99            item->comment = psStringCopy (op);
     100            if (!psMetadataAddItem(where, item, PS_LIST_TAIL, PS_META_DUPLICATE_OK)) {
     101                psError(PS_ERR_UNKNOWN, false, "failed to add item %s", field);
     102                psFree(where);
     103                return false;
     104            }
     105        }
     106        psFree (iter);
     107    }
     108    return true;
     109}
     110
     111// shared code for updating the various strings for a Run
     112bool pxUpdateRun(pxConfig *config, psMetadata *where, psString *pQuery, psString runTable, psString idColumn, psString fileTable, bool has_dist_group)
     113{
     114    PS_ASSERT_PTR_NON_NULL(config, false);
     115    PS_ASSERT_PTR_NON_NULL(where, false);
     116    PS_ASSERT_PTR_NON_NULL(pQuery, false);
     117    PS_ASSERT_PTR_NON_NULL(*pQuery, false);
     118    PS_ASSERT_PTR_NON_NULL(runTable, false);
     119    PS_ASSERT_PTR_NON_NULL(idColumn, false);
     120    PS_ASSERT_PTR_NON_NULL(fileTable, false);
     121
     122    // make sure that -state is not the only selection parameter
     123    PXOPT_LOOKUP_STR(where_state, config->args, "-state", false, false);
     124    if (where_state && (psListLength(where->list) < 2)) {
     125        psError(PXTOOLS_ERR_CONFIG, true, "selection by -state alone is not allowed");
     126        return false;
     127    }
     128
     129    PXOPT_LOOKUP_STR(state, config->args,       "-set_state", false, false);
     130    PXOPT_LOOKUP_STR(label, config->args,       "-set_label", false, false);
     131    PXOPT_LOOKUP_STR(data_group, config->args,  "-set_data_group", false, false);
     132    PXOPT_LOOKUP_STR(note, config->args,        "-set_note", false, false);
     133
     134    psString dist_group = NULL;
     135    if (has_dist_group) {
     136        PXOPT_LOOKUP_STR(tmp_dist_group, config->args,  "-set_dist_group", false, false);
     137        dist_group = tmp_dist_group;
     138    }
     139
     140    if ((!state) && (!label) && (!data_group) && (has_dist_group && !dist_group) && !(note)) {
     141        psError(PXTOOLS_ERR_CONFIG, false, "parameters are required");
     142        return false;
     143    }
     144
     145    if (state && ! pxIsValidState(state)) {
     146        psError(PXTOOLS_ERR_CONFIG, false, "pxIsValidState failed");
     147        return false;
     148    }
     149
     150    // first paramter is added with "SET param = 'value'"
     151    // subseqent ones with ", param = 'value'"
     152    char *separator = " SET ";
     153    char *comma = ",";
     154
     155#   define addColumn(_tab, _val) \
     156        do { \
     157            if (_val) { \
     158                psStringAppend(pQuery, "%s %s.%s = '%s'", separator, _tab, #_val, _val); \
     159                separator = comma; \
     160            } \
     161        } while (0)
     162
     163    addColumn(runTable, state);
     164    addColumn(runTable, data_group);
     165    if (has_dist_group) {
     166        addColumn(runTable, dist_group);
     167    }
     168    addColumn(runTable, note);
     169    addColumn(runTable, label);
     170
     171    psString joinHook = psStringCopy("");
     172    psString fileWhere = NULL;
     173    if (state && !strcmp(state, "update")) {
     174        psStringAppend(&joinHook, "\n JOIN %s USING(%s)", fileTable, idColumn);
     175        psStringAppend(pQuery, ", %s.data_state = 'update'", fileTable);
     176        psStringAppend(&fileWhere, "AND %s.data_state = 'cleaned'", fileTable);
     177    }
     178
     179    psString whereClause =  psDBGenerateWhereSQL(where, NULL);
     180    psStringAppend(pQuery, " %s", whereClause);
     181    psFree(whereClause);
     182    if (fileWhere) {
     183        psStringAppend(pQuery, "%s", fileWhere);
     184    }
     185
     186    bool mdok;                          // Status of MD lookup
     187    if (psMetadataLookupBool(&mdok, config->args, "-pretend")) {
     188        psLogMsg("pxtools", PS_LOG_INFO, "Query to run: %s\n", *pQuery);
     189        return true;
     190    }
     191
     192    if (!p_psDBRunQueryF(config->dbh, *pQuery, joinHook)) {
     193        psError(PS_ERR_UNKNOWN, false, "database error");
     194        return false;
     195    }
     196
     197    return true;
     198}
     199
     200bool pxLookupVersion(pxConfig *config, psArray **pArray)
     201{
     202    const char *query = "SELECT * FROM dbversion";
     203
     204    if (!p_psDBRunQuery(config->dbh, query)) {
     205        psError(PS_ERR_UNKNOWN, false, "database error");
     206        return false;
     207    }
     208
     209    psArray *output = p_psDBFetchResult(config->dbh);
     210    if (!output) {
     211        psError(PS_ERR_UNKNOWN, false, "database error");
     212        return false;
     213    }
     214    if (!psArrayLength(output)) {
     215        psFree(output);
     216        psError(PS_ERR_UNKNOWN, true, "no rows in dbversion");
     217        return false;
     218    }
     219    if (psArrayLength(output) > 1) {
     220        psError(PS_ERR_UNKNOWN, true, "unexpected number of rows found in dbversion: %ld",
     221                psArrayLength(output));
     222        return false;
     223    }
     224    *pArray = output;
     225
     226    return true;
     227}
     228
     229psString pxGetDBVersion(pxConfig *config)
     230{
     231    PS_ASSERT_PTR_NON_NULL(config, NULL);
     232
     233    psArray *array = NULL;
     234    if (!pxLookupVersion(config, &array)) {
     235        psError(PS_ERR_UNKNOWN, false, "pxLookupVersion failed");
     236        return NULL;
     237    }
     238    psMetadata *md = array->data[0];
     239    if (!md) {
     240        psError(PS_ERR_UNKNOWN, true, "output of pxLookupVersion is null");
     241        return NULL;
     242    }
     243
     244    psString version = psMetadataLookupStr(NULL, md, "schema_version");
     245
     246    return version;
     247}
     248
     249bool pxExportVersion(pxConfig *config, FILE *file)
     250{
     251    PS_ASSERT_PTR_NON_NULL(config, NULL);
     252    PS_ASSERT_PTR_NON_NULL(file, NULL);
     253
     254    psArray *array = NULL;
     255    if (!pxLookupVersion(config, &array) || !array) {
     256        psError(PS_ERR_UNKNOWN, false, "pxLookupVersion failed");
     257        return false;
     258    }
     259    if (!ippdbPrintMetadatas(file, array, "dbversion", true)) {
     260        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     261        psFree(array);
     262        return false;
     263    }
     264    return true;
     265}
     266
     267bool pxCheckImportVersion(pxConfig *config, psMetadata *input)
     268{
     269    PS_ASSERT_PTR_NON_NULL(config, NULL);
     270    PS_ASSERT_PTR_NON_NULL(input, NULL);
     271
     272    // This code was adapted from the way camtool parses the structures.
     273    // Is this really the way to do it?
     274    psMetadataItem *multi_item =  psMetadataLookup(input, "dbversion");
     275    if (!multi_item || (multi_item->type != PS_DATA_METADATA_MULTI)) {
     276        psError(PS_ERR_UNKNOWN, true, "dbversion multi not found in input");
     277        return false;
     278    }
     279
     280    psMetadataItem *dbversion = psListGet(multi_item->data.list, 0);
     281    if (!dbversion) {
     282        psError(PS_ERR_UNKNOWN, true, "dbversion not found in input");
     283        return false;
     284    }
     285
     286    if (!strcmp(dbversion->name, "dbversion")) {
     287        // horray
     288        psMetadata *md = dbversion->data.md;
     289        psString schema_version = pxGetDBVersion(config);
     290        if (!schema_version) {
     291            psError(PS_ERR_UNKNOWN, false, "pxGetDBVersion failed");
     292            return false;
     293        }
     294
     295        psString import_version = psMetadataLookupStr(NULL, md, "schema_version");
     296        if (import_version && strcmp(import_version, schema_version)) {
     297            psError(PS_ERR_UNKNOWN, true, "input file schema_version: %s does not match data base: %s",
     298                import_version, schema_version);
     299            return false;
     300        } else if (!import_version) {
     301            psError(PS_ERR_UNKNOWN, true, "input file schema_version is NULL");
     302            return false;
     303        } else {
     304            // YIPPEE this file is the same version
     305        }
     306    } else {
     307        psError(PS_ERR_UNKNOWN, true, "Unexpected config dump format");
     308        return false;
     309    }
     310
     311    return true;
     312}
Note: See TracChangeset for help on using the changeset viewer.