Changeset 6876 for trunk/ippTools/src/pzgetexp.c
- Timestamp:
- Apr 17, 2006, 3:03:37 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pzgetexp.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pzgetexp.c
r6837 r6876 1 #ifdef HAVE_CONFIG_H 2 #include <config.h> 3 #endif 4 1 5 #include <stdlib.h> 2 6 #include <stdio.h> … … 5 9 #include "pzgetexp.h" 6 10 7 static bool parseInput(pxConfig *config);11 static psArray *parseFileSets(pxConfig *config, const char *str); 8 12 9 13 int main(int argc, char **argv) 10 14 { 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); 12 54 13 55 /* 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 } 22 67 } 23 68 */ 24 69 25 p arseInput(config);70 psFree(config); 26 71 27 72 exit(EXIT_SUCCESS); 28 73 29 74 FAIL: 30 //psFree(config);75 psFree(config); 31 76 exit(EXIT_FAILURE); 32 77 } 33 78 34 static bool parseInput(pxConfig *config)79 static psArray *parseFileSets(pxConfig *config, const char *str) 35 80 { 36 psString input = slurp(stdin); 37 psList *lines = psStringSplit(input, "\n"); 81 psList *lines = psStringSplit(str, "\n"); 38 82 39 83 psListIterator *lineCursor = psListIteratorAlloc(lines, 0, false); … … 47 91 psList *tokens = psStringSplit(item, " "); 48 92 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 49 100 // check that we have the right number of tokens 50 101 // print "# uri fileset datetime type\n"; … … 55 106 56 107 psListIterator *tokenCursor = psListIteratorAlloc(tokens, 0, false); 57 58 108 char *uri = psListGetAndIncrement(tokenCursor); 59 109 char *exp_id = psListGetAndIncrement(tokenCursor); // fileset … … 61 111 char *exp_type = psListGetAndIncrement(tokenCursor); // type 62 112 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"); 64 118 65 119 summitExpRow *row = summitExpRowAlloc( 66 120 exp_id, 67 c onfig->camera,68 config->telescope,121 camera_name, 122 telescope, 69 123 exp_type, 70 124 uri 71 125 ); 126 127 psFree(tokenCursor); 128 psFree(tokens); 129 72 130 psArrayAdd(summitExps, 0, row); 73 131 } … … 75 133 psFree(lineCursor); 76 134 psFree(lines); 77 psFree(input);78 135 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; 87 137 }
Note:
See TracChangeset
for help on using the changeset viewer.
