Changeset 16277
- Timestamp:
- Feb 1, 2008, 2:40:03 PM (18 years ago)
- Location:
- trunk/ippTools/src
- Files:
-
- 4 edited
-
Makefile.am (modified) (4 diffs)
-
pstamptool.c (modified) (9 diffs)
-
pstamptool.h (modified) (1 diff)
-
pstamptoolConfig.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/Makefile.am
r16242 r16277 8 8 flatcorr \ 9 9 magictool \ 10 pstamptool \ 10 11 pxadmin \ 11 12 pxinject \ … … 16 17 stacktool \ 17 18 warptool 19 18 20 19 21 bin_SCRIPTS = \ … … 44 46 guidetool.h \ 45 47 magictool.h \ 48 pstamptool.h \ 46 49 pxinject.h \ 47 50 pzgetexp.h \ … … 80 83 pztoolConfig.c 81 84 85 pstamptool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS) 86 pstamptool_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la 87 pstamptool_SOURCES = \ 88 pstamptool.c \ 89 pstamptoolConfig.c 90 82 91 caltool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS) 83 92 caltool_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la -
trunk/ippTools/src/pstamptool.c
r16134 r16277 36 36 static bool pendingReqMode(pxConfig *config); 37 37 static bool processedReqMode(pxConfig *config); 38 #ifdef notyet39 38 static bool addJobMode(pxConfig *config); 39 static bool listJobMode(pxConfig *config); 40 40 static bool pendingJobMode(pxConfig *config); 41 42 static bool copydoneMode(pxConfig *config); 43 44 static bool copydoneCompleteExp(pxConfig *config); 45 static psArray *pzGetPendingCameras(pxConfig *config); 46 static psArray *pzArrayZip(psArray *arraySet, psS64 limit); 47 #endif // notyet 41 static bool processedJobMode(pxConfig *config); 48 42 49 43 # define MODECASE(caseName, func) \ … … 71 65 MODECASE(PSTAMPTOOL_MODE_PENDINGREQ, pendingReqMode); 72 66 MODECASE(PSTAMPTOOL_MODE_PROCESSEDREQ, processedReqMode); 67 MODECASE(PSTAMPTOOL_MODE_ADDJOB, addJobMode); 68 MODECASE(PSTAMPTOOL_MODE_LISTJOB, listJobMode); 69 MODECASE(PSTAMPTOOL_MODE_PENDINGJOB, pendingJobMode); 70 MODECASE(PSTAMPTOOL_MODE_PROCESSEDJOB, processedJobMode); 73 71 default: 74 72 psAbort("invalid option (this should not happen)"); … … 206 204 } 207 205 208 char *query ="INSERT INTO ps Request"206 char *query ="INSERT INTO pstampRequest" 209 207 " (state, uri)" 210 208 " VALUES( 'new', '%s')"; … … 224 222 } 225 223 224 psS64 req_id = psDBLastInsertID(config->dbh); 225 printf("%ld\n", req_id); 226 226 227 return true; 227 228 } … … 241 242 "SELECT" 242 243 " *" 243 " FROM ps Request"244 " FROM pstampRequest" 244 245 " WHERE state = 'new'" 245 246 ); 246 247 247 248 if (config->where) { 248 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "ps Request");249 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pstampRequest"); 249 250 psStringAppend(&query, " AND %s", whereClause); 250 251 psFree(whereClause); … … 288 289 289 290 // negative simple so the default is true 290 if (!ippdbPrintMetadatas(stdout, output, "p zPendingExp", !simple)) {291 if (!ippdbPrintMetadatas(stdout, output, "pstampRequest", !simple)) { 291 292 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 292 293 psFree(output); … … 298 299 return true; 299 300 } 301 300 302 static bool processedReqMode(pxConfig *config) 301 303 { … … 325 327 // XXX: check state for a legal value 326 328 327 char *query ="UPDATE ps Request"329 char *query ="UPDATE pstampRequest" 328 330 " SET state = '%s'" 329 331 " WHERE req_id = '%s'"; … … 337 339 psU64 affected = psDBAffectedRows(config->dbh); 338 340 if (affected != 1) { 339 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" PRIu64 " rows were modified", 341 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 342 PRIu64 " rows were modified", affected); 343 return false; 344 } 345 346 return true; 347 } 348 static bool addJobMode(pxConfig *config) 349 { 350 bool status; 351 352 PS_ASSERT_PTR_NON_NULL(config, false); 353 354 psString uri = psMetadataLookupStr(&status, config->args, "-uri"); 355 if (!status) { 356 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri"); 357 return false; 358 } 359 if (!uri) { 360 psError(PS_ERR_UNKNOWN, true, "-uri is required"); 361 return false; 362 } 363 364 psString req_id = psMetadataLookupStr(&status, config->args, "-req_id"); 365 if (!status) { 366 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -req_id"); 367 return false; 368 } 369 if (!req_id) { 370 psError(PS_ERR_UNKNOWN, true, "-req_id is required"); 371 return false; 372 } 373 374 psString outputBase = psMetadataLookupStr(&status, config->args, "-outputBase"); 375 if (!status) { 376 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -outputBase"); 377 return false; 378 } 379 if (!outputBase) { 380 psError(PS_ERR_UNKNOWN, true, "-outputBase is required"); 381 return false; 382 } 383 384 psString argString = psMetadataLookupStr(&status, config->args, "-args"); 385 if (!status) { 386 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -args"); 387 return false; 388 } 389 if (!argString) { 390 psError(PS_ERR_UNKNOWN, true, "-args is required"); 391 return false; 392 } 393 394 char *query ="INSERT INTO pstampJob" 395 " (req_id, state, uri, outputBase, args)" 396 " VALUES( %s, 'new', '%s', '%s', '%s')"; 397 398 if (!p_psDBRunQuery(config->dbh, query, req_id, uri, outputBase, argString)) { 399 psError(PS_ERR_UNKNOWN, false, "database error"); 400 psFree(query); 401 return false; 402 } 403 404 psU64 affected = psDBAffectedRows(config->dbh); 405 if (affected != 1) { 406 psError(PS_ERR_UNKNOWN, false, 407 "should have affected one row but %" PRIu64 " rows were modified", 340 408 affected); 341 409 return false; 342 410 } 343 411 344 return true; 345 } 412 psS64 job_id = psDBLastInsertID(config->dbh); 413 printf("%ld\n", job_id); 414 415 return true; 416 } 417 418 static bool listJobMode(pxConfig *config) 419 { 420 PS_ASSERT_PTR_NON_NULL(config, false); 421 422 bool status = false; 423 psU64 limit = psMetadataLookupU64(&status, config->args, "-limit"); 424 if (!status) { 425 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit"); 426 return false; 427 } 428 429 psString query = NULL; 430 431 psString req_id = psMetadataLookupStr(&status, config->args, "-req_id"); 432 psString job_id = psMetadataLookupStr(&status, config->args, "-job_id"); 433 434 if (req_id) { 435 psStringAppend(&query, 436 "SELECT" 437 " *" 438 " FROM pstampJob" 439 " WHERE req_id = %s", req_id 440 ); 441 } else if (job_id) { 442 psStringAppend(&query, 443 "SELECT" 444 " *" 445 " FROM pstampJob" 446 " WHERE job_id = %s", job_id 447 ); 448 } else { 449 fprintf(stderr, "either req_id or job_id must be specified\n"); 450 exit (1); 451 } 452 453 // treat limit == 0 as "no limit" 454 if (limit) { 455 psString limitString = psDBGenerateLimitSQL(limit); 456 psStringAppend(&query, " %s", limitString); 457 psFree(limitString); 458 } 459 460 if (!p_psDBRunQuery(config->dbh, query)) { 461 psError(PS_ERR_UNKNOWN, false, "database error"); 462 psFree(query); 463 return false; 464 } 465 psFree(query); 466 467 psArray *output = p_psDBFetchResult(config->dbh); 468 if (!output) { 469 psError(PS_ERR_UNKNOWN, false, "database error"); 470 return false; 471 } 472 if (!psArrayLength(output)) { 473 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 474 psFree(output); 475 return true; 476 } 477 478 bool simple = false; 479 { 480 bool status = false; 481 simple = psMetadataLookupBool(&status, config->args, "-simple"); 482 if (!status) { 483 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 484 psFree(output); 485 return false; 486 } 487 } 488 489 // negative simple so the default is true 490 if (!ippdbPrintMetadatas(stdout, output, "pstampJob", !simple)) { 491 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 492 psFree(output); 493 return false; 494 } 495 496 psFree(output); 497 498 return true; 499 } 500 501 static bool pendingJobMode(pxConfig *config) 502 { 503 PS_ASSERT_PTR_NON_NULL(config, false); 504 505 bool status = false; 506 psU64 limit = psMetadataLookupU64(&status, config->args, "-limit"); 507 if (!status) { 508 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit"); 509 return false; 510 } 511 512 psString query = psStringCopy( 513 "SELECT" 514 " *" 515 " FROM pstampJob" 516 " WHERE state = 'new'" 517 ); 518 519 if (config->where) { 520 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pstampJob"); 521 psStringAppend(&query, " AND %s", whereClause); 522 psFree(whereClause); 523 } 524 525 // treat limit == 0 as "no limit" 526 if (limit) { 527 psString limitString = psDBGenerateLimitSQL(limit); 528 psStringAppend(&query, " %s", limitString); 529 psFree(limitString); 530 } 531 532 if (!p_psDBRunQuery(config->dbh, query)) { 533 psError(PS_ERR_UNKNOWN, false, "database error"); 534 psFree(query); 535 return false; 536 } 537 psFree(query); 538 539 psArray *output = p_psDBFetchResult(config->dbh); 540 if (!output) { 541 psError(PS_ERR_UNKNOWN, false, "database error"); 542 return false; 543 } 544 if (!psArrayLength(output)) { 545 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 546 psFree(output); 547 return true; 548 } 549 550 bool simple = false; 551 { 552 bool status = false; 553 simple = psMetadataLookupBool(&status, config->args, "-simple"); 554 if (!status) { 555 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 556 psFree(output); 557 return false; 558 } 559 } 560 561 // negative simple so the default is true 562 if (!ippdbPrintMetadatas(stdout, output, "pstampJob", !simple)) { 563 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 564 psFree(output); 565 return false; 566 } 567 568 psFree(output); 569 570 return true; 571 } 572 573 static bool processedJobMode(pxConfig *config) 574 { 575 bool status; 576 577 PS_ASSERT_PTR_NON_NULL(config, false); 578 579 psString job_id = psMetadataLookupStr(&status, config->args, "-job_id"); 580 if (!status) { 581 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -job_id"); 582 return false; 583 } 584 if (!job_id) { 585 psError(PS_ERR_UNKNOWN, true, "-job_id is required"); 586 return false; 587 } 588 psString state = psMetadataLookupStr(&status, config->args, "-state"); 589 if (!status) { 590 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state"); 591 return false; 592 } 593 if (!state) { 594 psError(PS_ERR_UNKNOWN, true, "-state is required"); 595 return false; 596 } 597 psString jobStatus = psMetadataLookupStr(&status, config->args, "-status"); 598 if (!status) { 599 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -status"); 600 return false; 601 } 602 603 psString statusStr = NULL; 604 if (!jobStatus) { 605 statusStr = psStringCopy(""); 606 } else { 607 psStringAppend(&statusStr, ", status = '%s'", jobStatus); 608 } 609 610 611 // XXX: check state for a legal value 612 613 char *query ="UPDATE pstampJob" 614 " SET state = '%s' %s" 615 " WHERE job_id = '%s'"; 616 617 if (!p_psDBRunQuery(config->dbh, query, state, statusStr, job_id)) { 618 psError(PS_ERR_UNKNOWN, false, "database error"); 619 psFree(query); 620 return false; 621 } 622 psFree(statusStr); 623 624 psU64 affected = psDBAffectedRows(config->dbh); 625 if (affected != 1) { 626 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 627 PRIu64 " rows were modified", affected); 628 return false; 629 } 630 631 return true; 632 } -
trunk/ippTools/src/pstamptool.h
r16134 r16277 31 31 PSTAMPTOOL_MODE_PROCESSEDREQ, 32 32 PSTAMPTOOL_MODE_ADDJOB, 33 PSTAMPTOOL_MODE_LISTJOB, 33 34 PSTAMPTOOL_MODE_PENDINGJOB, 34 35 PSTAMPTOOL_MODE_JOBRESULT, -
trunk/ippTools/src/pstamptoolConfig.c
r16134 r16277 74 74 "new state", NULL); 75 75 76 #ifdef notdef 77 // -pendingimfile 78 psMetadata *pendingimfileArgs = psMetadataAlloc(); 79 psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_name", 0, 80 "define exposure ID", NULL); 81 psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-inst", 0, 82 "define camera ID", NULL); 83 psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-telescope", 0, 84 "define telescope ID", NULL); 85 psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_type", 0, 86 "define exposure type", NULL); 87 psMetadataAddU64(pendingimfileArgs, PS_LIST_TAIL, "-limit", 0, 76 // -addjob 77 psMetadata *addjobArgs = psMetadataAlloc(); 78 psMetadataAddStr(addjobArgs, PS_LIST_TAIL, "-uri", 0, 79 "define job file uri", NULL); 80 psMetadataAddStr(addjobArgs, PS_LIST_TAIL, "-req_id", 0, 81 "define job req_id", NULL); 82 psMetadataAddStr(addjobArgs, PS_LIST_TAIL, "-outputBase", 0, 83 "define job outputBase", NULL); 84 psMetadataAddStr(addjobArgs, PS_LIST_TAIL, "-args", 0, 85 "define job args", NULL); 86 87 // -listjob 88 psMetadata *listjobArgs = psMetadataAlloc(); 89 psMetadataAddStr(listjobArgs, PS_LIST_TAIL, "-req_id", 0, 90 "define request", NULL); 91 psMetadataAddStr(listjobArgs, PS_LIST_TAIL, "-job_id", 0, 92 "define job", NULL); 93 psMetadataAddU64(listjobArgs, PS_LIST_TAIL, "-limit", 0, 88 94 "limit result set to N items", 0); 89 psMetadataAddBool(pendingimfileArgs, PS_LIST_TAIL, "-simple", 0, 90 "use the simple output format", false); 91 92 // -copydone 93 psMetadata *copydoneArgs = psMetadataAlloc(); 94 psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-exp_name", 0, 95 "define exposure ID (required)", NULL); 96 psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-inst", 0, 97 "define camera ID (required)", NULL); 98 psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-telescope", 0, 99 "define telescope ID (required)", NULL); 100 psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-class", 0, 101 "define class", NULL); 102 psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-class_id", 0, 103 "define class_id", NULL); 104 psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-uri", 0, 105 "define storage uri", NULL); 106 107 #endif // notyet 95 psMetadataAddBool(listjobArgs, PS_LIST_TAIL, "-simple", 0, 96 "use the simple output format", false); 97 98 // -pendingjob 99 psMetadata *pendingjobArgs = psMetadataAlloc(); 100 psMetadataAddStr(pendingjobArgs, PS_LIST_TAIL, "-job_id", 0, 101 "define job", NULL); 102 psMetadataAddU64(pendingjobArgs, PS_LIST_TAIL, "-limit", 0, 103 "limit result set to N items", 0); 104 psMetadataAddBool(pendingjobArgs, PS_LIST_TAIL, "-simple", 0, 105 "use the simple output format", false); 106 107 // -processedjob 108 psMetadata *processedjobArgs = psMetadataAlloc(); 109 psMetadataAddStr(processedjobArgs, PS_LIST_TAIL, "-job_id", 0, 110 "req_id for which to change state", NULL); 111 psMetadataAddStr(processedjobArgs, PS_LIST_TAIL, "-state", 0, 112 "new state", NULL); 113 psMetadataAddStr(processedjobArgs, PS_LIST_TAIL, "-status", 0, 114 "new status", NULL); 108 115 109 116 #define PXTOOL_MODE(option, modeval, argset) \ … … 129 136 psMetadata *modes = psMetadataAlloc(); 130 137 131 PXTOOL_ADD_MODE("-adddatastore", "", PSTAMPTOOL_MODE_ADDDATASTORE, adddatastoreArgs); 132 PXTOOL_ADD_MODE("-datastore", "", PSTAMPTOOL_MODE_DATASTORE, datastoreArgs); 133 134 PXTOOL_ADD_MODE("-addreq", "", PSTAMPTOOL_MODE_ADDREQ, addreqArgs); 135 PXTOOL_ADD_MODE("-pendingreq", "", PSTAMPTOOL_MODE_PENDINGREQ, pendingreqArgs); 136 PXTOOL_ADD_MODE("-processedreq", "", PSTAMPTOOL_MODE_PROCESSEDREQ, processedreqArgs); 138 PXOPT_ADD_MODE("-adddatastore", "", PSTAMPTOOL_MODE_ADDDATASTORE, adddatastoreArgs); 139 PXOPT_ADD_MODE("-datastore", "", PSTAMPTOOL_MODE_DATASTORE, datastoreArgs); 140 141 PXOPT_ADD_MODE("-addreq", "", PSTAMPTOOL_MODE_ADDREQ, addreqArgs); 142 PXOPT_ADD_MODE("-pendingreq", "", PSTAMPTOOL_MODE_PENDINGREQ, pendingreqArgs); 143 PXOPT_ADD_MODE("-processedreq", "", PSTAMPTOOL_MODE_PROCESSEDREQ, processedreqArgs); 144 145 PXOPT_ADD_MODE("-addjob", "", PSTAMPTOOL_MODE_ADDJOB, addjobArgs); 146 PXOPT_ADD_MODE("-listjob", "", PSTAMPTOOL_MODE_LISTJOB, listjobArgs); 147 PXOPT_ADD_MODE("-pendingjob", "", PSTAMPTOOL_MODE_PENDINGJOB, pendingjobArgs); 148 PXOPT_ADD_MODE("-processedjob", "", PSTAMPTOOL_MODE_PROCESSEDJOB, processedjobArgs); 137 149 138 150 #ifdef notyet 139 PXTOOL_ADD_MODE("-addjob", "", PSTAMPTOOL_MODE_ADDJOB, addjobArgs); 140 PXTOOL_ADD_MODE("-pendingjob", "", PSTAMPTOOL_MODE_PENDINGJOB, pendingjobArgs); 141 PXTOOL_ADD_MODE("-processedjob" "", PSTAMPTOOL_MODE_PROCESSEDJOB, processedjobArgs); 142 PXTOOL_ADD_MODE("-jobresult", "", PSTAMPTOOL_MODE_JOBRESULT, jobresultArgs); 151 PXOPT_ADD_MODE("-jobresult", "", PSTAMPTOOL_MODE_JOBRESULT, jobresultArgs); 143 152 #endif 144 153 … … 174 183 addWhereStr(job_id); 175 184 176 #ifdef notdef177 addWhereStr(exp_name);178 addWhereStr(telescope);179 // convert '-inst' to 'camera'180 {181 psString str = NULL;182 bool status = false;183 if ((str = psMetadataLookupStr(&status, config->args, "-inst"))) {184 if (!psMetadataAddStr(config->where, PS_LIST_TAIL, "camera", 0, "==", str)) {185 psError(PS_ERR_UNKNOWN, false, "failed to add item camera");186 psFree(config);187 return NULL;188 }189 }190 }191 addWhereStr(exp_type);192 addWhereStr(class);193 addWhereStr(class_id);194 #endif195 196 185 if (config->where->list->n < 1) { 197 186 psFree(config->where);
Note:
See TracChangeset
for help on using the changeset viewer.
