- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/pxtools.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ippTools/src
- Property svn:ignore
-
old new 1 *.la 2 *.lo 1 3 .deps 2 4 .gdb_history … … 4 6 Makefile 5 7 Makefile.in 8 addtool 9 caltool 10 camtool 11 chiptool 6 12 config.h 7 13 config.h.in 8 stamp-h1 9 *.la 10 *.lo 14 detselect 15 dettool 16 difftool 17 disttool 18 dqstatstool 19 faketool 20 flatcorr 21 guidetool 22 magicdstool 23 magictool 24 pstamptool 25 pubtool 26 pxadmin 27 pxdata.c 28 pxinject 11 29 pxtoolsErrorCodes.c 12 30 pxtoolsErrorCodes.h 13 pxadmin14 pxinject15 pztool16 31 pzgetexp 17 32 pzgetimfiles 33 pztool 34 receivetool 18 35 regtool 19 guidetool 20 chiptool 21 camtool 36 stacktool 37 stamp-h1 22 38 warptool 23 difftool24 stacktool25 faketool26 dettool27 detselect28 pxdata.c29 magictool30 magicdstool31 caltool32 flatcorr33 pstamptool34 disttool35 receivetool36 37 pubtool
-
- Property svn:ignore
-
branches/simtest_nebulous_branches/ippTools/src/pxtools.c
r23918 r27840 37 37 if (!strcmp(state, "goto_cleaned")) return true; 38 38 if (!strcmp(state, "error_cleaned")) return true; 39 if (!strcmp(state, "goto_purged")) return true; 40 if (!strcmp(state, "error_purged")) return true; 39 41 if (!strcmp(state, "goto_scrubbed")) return true; 40 42 if (!strcmp(state, "error_scrubbed")) return true; … … 42 44 if (!strcmp(state, "update")) return true; 43 45 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; 47 47 return false; 48 48 } 49 49 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. 52 53 53 54 … … 60 61 if (!state) { 61 62 psError(PS_ERR_PROGRAMMING, false, "%s not found in row %ld of table %s", 62 columnName, i, tableName);63 columnName, i, tableName); 63 64 return false; 64 65 } … … 69 70 // if state isn't cleaned or full we can't set it to cleaned 70 71 psError(PS_ERR_PROGRAMMING, true, "%s with state %s may not be exported cleaned", 71 tableName, state);72 tableName, state); 72 73 return false; 73 74 } … … 89 90 psAssert (entry, "%s should at least have a place-holder", name); 90 91 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 112 bool 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 200 bool 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 229 psString 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 249 bool 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 267 bool 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.
