IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28076 for trunk/ippTools/src


Ignore:
Timestamp:
May 21, 2010, 4:39:25 PM (16 years ago)
Author:
bills
Message:

labeltool lives!

Location:
trunk/ippTools/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src

    • Property svn:ignore
      •  

        old new  
        2020flatcorr
        2121guidetool
         22labeltool
        2223magicdstool
        2324magictool
         
        3738stamp-h1
        3839warptool
         40
  • trunk/ippTools/src/labeltool.c

    r28074 r28076  
    8181static bool definelabelMode(pxConfig *config)
    8282{
    83 #ifdef notyet
    8483    PS_ASSERT_PTR_NON_NULL(config, false);
    8584
    8685    // required
    87     PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false);
    88     PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", true, false);
    89     PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", false, false);
     86    PXOPT_LOOKUP_STR(label,    config->args, "-set_label", true, false);
     87    // XXX: perhaps we should have a default priority?
     88    PXOPT_LOOKUP_S32(priority, config->args, "-set_priority", true, false);
    9089
    9190    // optional
    92     PXOPT_LOOKUP_BOOL(inverse, config->args, "-inverse", false);
    93     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    94     PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false);
    95     PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
     91    PXOPT_LOOKUP_BOOL(inactive, config->args, "-set_inactive", false);
     92    PXOPT_LOOKUP_STR(comment, config->args, "-set_comment", false, false);
    9693    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    9794
    98     magicRunRow *run = magicRunRowAlloc(
    99             0,          // ID
    100             exp_id,
    101             diff_id ? diff_id : PS_MAX_S64,
    102             inverse,
    103             "reg",      // state
    104             workdir,
    105             "dirty",    // workdir_state
     95    LabelRow *row = LabelRowAlloc(
    10696            label,
    107             NULL,       // data_group
    108             dvodb,
    109             registered,
    110             0,          // fault
    111             NULL
     97            priority,
     98            inactive ? false : true,
     99            comment
    112100    );
    113101
    114     if (!run) {
    115         psError(PS_ERR_UNKNOWN, false, "failed to alloc magicRun object");
    116         return false;
    117     }
    118     if (!magicRunInsertObject(config->dbh, run)) {
    119         psError(PS_ERR_UNKNOWN, false, "database error");
    120         psFree(run);
    121         return false;
    122     }
    123 
    124     // get the assigned magic_id
    125     psS64 magic_id = psDBLastInsertID(config->dbh);
    126     run->magic_id = magic_id;
    127 
    128     if (!magicRunPrintObject(stdout, run, !simple)) {
     102    if (!row) {
     103        psError(PS_ERR_UNKNOWN, false, "failed to allocate Label object");
     104        return false;
     105    }
     106    if (!LabelInsertObject(config->dbh, row)) {
     107        psError(PS_ERR_UNKNOWN, false, "database error");
     108        psFree(row);
     109        return false;
     110    }
     111
     112    if (!LabelPrintObject(stdout, row, !simple)) {
    129113            psError(PS_ERR_UNKNOWN, false, "failed to print object");
    130             psFree(run);
     114            psFree(row);
    131115            return false;
    132116    }
    133117
    134     psFree(run);
    135 
    136     return magic_id;
    137 #else
    138 
    139     return false;
    140 #endif
     118    psFree(row);
     119
     120    return true;
    141121}
    142122
     
    144124static bool updatelabelMode(pxConfig *config)
    145125{
    146     return false;
    147 #ifdef notyet
     126    PXOPT_LOOKUP_STR(label,    config->args, "-label", true, false);
     127
     128
     129    // optional (at least one is required)
     130    PXOPT_LOOKUP_S32(priority, config->args, "-set_priority", false, false);
     131    PXOPT_LOOKUP_BOOL(inactive, config->args, "-set_inactive", false);
     132    PXOPT_LOOKUP_BOOL(active, config->args, "-set_active", false);
     133    PXOPT_LOOKUP_STR(comment, config->args, "-set_comment", false, false);
     134
     135    if (! (priority || active || inactive || comment) ) {
     136        psError(PS_ERR_UNKNOWN, true, "at least one -set option is required\n");
     137        return false;
     138    }
     139    if (active && inactive) {
     140        psError(PS_ERR_UNKNOWN, true, "only one of -active and -inactive may be supplied");
     141        return false;
     142    }
     143
     144    psString query = psStringCopy("UPDATE Label SET");
     145    char sep = ' ';
     146
     147    if (priority) {
     148        psStringAppend(&query, "%c priority = %d", sep, priority);
     149        sep = ',';
     150    }
     151    if (active) {
     152        psStringAppend(&query, "%c active = %d", sep, 1);
     153        sep = ',';
     154    }
     155    if (inactive) {
     156        psStringAppend(&query, "%c active = %d", sep, 0);
     157        sep = ',';
     158    }
     159    if (comment) {
     160        psStringAppend(&query, "%c comment = '%s'", sep, comment);
     161        sep = ',';
     162    }
     163    if (!p_psDBRunQuery(config->dbh, query)) {
     164        psError(PS_ERR_UNKNOWN, false, "database error");
     165        psFree(query);
     166        return false;
     167    }
     168    psFree(query);
     169
     170    return true;
     171}
     172
     173static bool deletelabelMode(pxConfig *config)
     174{
    148175    PS_ASSERT_PTR_NON_NULL(config, false);
    149176
     177    PXOPT_LOOKUP_STR(label,    config->args, "-label", true, false);
     178
     179    psString query = NULL;
     180   
     181    psStringAppend(&query, "DELETE FROM Label WHERE label = '%s'", label);
     182
     183    if (!p_psDBRunQuery(config->dbh, query)) {
     184        psError(PS_ERR_UNKNOWN, false, "database error");
     185        psFree(query);
     186        return false;
     187    }
     188    psFree(query);
     189
     190    return true;
     191}
     192
     193static bool listlabelMode(pxConfig *config)
     194{
     195    PS_ASSERT_PTR_NON_NULL(config, false);
     196
    150197    psMetadata *where = psMetadataAlloc();
    151     PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
    152     PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "==");
    153     PXOPT_COPY_STR(config->args, where, "-node", "node", "==");
     198    PXOPT_COPY_STR(config->args, where, "-label", "label", "LIKE");
     199
     200    PXOPT_LOOKUP_BOOL(active, config->args,   "-active", false);
     201    PXOPT_LOOKUP_BOOL(inactive, config->args, "-inactive", false);
     202    if (active && inactive) {
     203        psError(PS_ERR_UNKNOWN, true, "only one of -active and inactive may be supplied");
     204        return false;
     205    }
     206    PXOPT_LOOKUP_BOOL(lowtohigh, config->args, "-lowtohigh", false);
     207    PXOPT_LOOKUP_BOOL(hightolow, config->args, "-hightolow", false);
     208    if (lowtohigh && hightolow) {
     209        psError(PS_ERR_UNKNOWN, true, "only one of -lowtohigh and -hightolow may be supplied");
     210        return false;
     211    }
    154212
    155213    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     
    157215
    158216    // find all rawImfiles matching the default query
    159     psString query = pxDataGet("magictool_inputskyfile.sql");
    160     if (!query) {
    161         psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    162         return false;
    163     }
    164 
     217    psString query = psStringCopy("SELECT * FROM Label\n");
     218
     219    char *sep = " WHERE ";
    165220    if (psListLength(where->list)) {
    166         psString whereClause = psDBGenerateWhereConditionSQL(where, "magicInputSkyfile");
    167         psStringAppend(&query, " AND %s", whereClause);
     221        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     222        psStringAppend(&query, " WHERE %s", whereClause);
    168223        psFree(whereClause);
     224        sep = " AND ";
    169225    }
    170226    psFree(where);
     227
     228    if (active) {
     229        psStringAppend(&query, "%s active\n", sep);
     230        sep = " AND ";
     231    } else if (inactive) {
     232        psStringAppend(&query, "%s NOT active\n", sep);
     233        sep = " AND ";
     234    }
     235
     236    if (lowtohigh || hightolow) {
     237        char *order = lowtohigh ? "" : "DESC";
     238        psStringAppend(&query, "\nORDER BY priority %s\n", order);
     239    }
    171240
    172241    // treat limit == 0 as "no limit"
     
    199268    }
    200269    if (!psArrayLength(output)) {
    201         psTrace("magictool", PS_LOG_INFO, "no rows found");
    202         psFree(output);
    203         return true;
    204     }
    205 
    206     if (psArrayLength(output)) {
    207         // negative simple so the default is true
    208         if (!ippdbPrintMetadatas(stdout, output, "magicInputSkyfile", !simple)) {
    209             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    210             psFree(output);
    211             return false;
    212         }
    213     }
    214 
    215     psFree(output);
    216 
    217     return true;
    218 #endif
    219 }
    220 
    221 static bool deletelabelMode(pxConfig *config)
    222 {
    223     return false;
    224 #ifdef notdef
    225     PS_ASSERT_PTR_NON_NULL(config, false);
    226 
    227     psMetadata *where = psMetadataAlloc();
    228     PXOPT_COPY_S64(config->args, where, "-magic_id", "magicRun.magic_id", "==");
    229     pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "==");
    230 
    231     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    232     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    233 
    234     // look for "inputs" that need to processed
    235     psString query = pxDataGet("magictool_totree.sql");
    236     if (!query) {
    237         psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    238         return false;
    239     }
    240 
    241     if (psListLength(where->list)) {
    242         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    243         psStringAppend(&query, " AND %s", whereClause);
    244         psFree(whereClause);
    245     }
    246     psFree(where);
    247 
    248     // treat limit == 0 as "no limit"
    249     if (limit) {
    250         psString limitString = psDBGenerateLimitSQL(limit);
    251         psStringAppend(&query, " %s", limitString);
    252         psFree(limitString);
    253     }
    254 
    255     if (!p_psDBRunQuery(config->dbh, query)) {
    256         psError(PS_ERR_UNKNOWN, false, "database error");
    257         psFree(query);
    258         return false;
    259     }
    260     psFree(query);
    261 
    262     psArray *output = p_psDBFetchResult(config->dbh);
    263     if (!output) {
    264         psErrorCode err = psErrorCodeLast();
    265         switch (err) {
    266             case PS_ERR_DB_CLIENT:
    267                 psError(PXTOOLS_ERR_SYS, false, "database error");
    268             case PS_ERR_DB_SERVER:
    269                 psError(PXTOOLS_ERR_PROG, false, "database error");
    270             default:
    271                 psError(PXTOOLS_ERR_PROG, false, "unknown error");
    272         }
    273 
    274         return false;
    275     }
    276     if (!psArrayLength(output)) {
    277         psTrace("magictool", PS_LOG_INFO, "no rows found");
    278         psFree(output);
    279         return true;
    280     }
    281 
    282     if (psArrayLength(output)) {
    283         // negative simple so the default is true
    284         if (!ippdbPrintMetadatas(stdout, output, "totree", !simple)) {
    285             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    286             psFree(output);
    287             return false;
    288         }
    289     }
    290 
    291     psFree(output);
    292 
    293     return true;
    294 #endif
    295 }
    296 
    297 static bool listlabelMode(pxConfig *config)
    298 {
    299     PS_ASSERT_PTR_NON_NULL(config, false);
    300     PS_ASSERT_PTR_NON_NULL(config, false);
    301 
    302     psMetadata *where = psMetadataAlloc();
    303     PXOPT_COPY_STR(config->args, where, "-label", "label", "LIKE");
    304 
    305     PXOPT_LOOKUP_BOOL(active, config->args,   "-active", false);
    306     PXOPT_LOOKUP_BOOL(inactive, config->args, "-inactive", false);
    307     if (active && inactive) {
    308         psError(PS_ERR_UNKNOWN, true, "only one of -active and inactive may be supplied");
    309         return false;
    310     }
    311     PXOPT_LOOKUP_BOOL(lowtohigh, config->args, "-lowtohigh", false);
    312     PXOPT_LOOKUP_BOOL(hightolow, config->args, "-hightolow", false);
    313     if (lowtohigh && hightolow) {
    314         psError(PS_ERR_UNKNOWN, true, "only one of -lowtohigh and -hightolow may be supplied");
    315         return false;
    316     }
    317 
    318     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    319     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    320 
    321     // find all rawImfiles matching the default query
    322     psString query = psStringCopy("SELECT * FROM Label\n");
    323 
    324     char *sep = " WHERE ";
    325     if (psListLength(where->list)) {
    326         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    327         psStringAppend(&query, " WHERE %s", whereClause);
    328         psFree(whereClause);
    329         sep = " AND ";
    330     }
    331     psFree(where);
    332 
    333     if (active) {
    334         psStringAppend(&query, "%s active\n", sep);
    335         sep = " AND ";
    336     } else if (inactive) {
    337         psStringAppend(&query, "%s NOT active\n", sep);
    338         sep = " AND ";
    339     }
    340 
    341     if (lowtohigh || hightolow) {
    342         char *order = lowtohigh ? "" : "DESC";
    343         psStringAppend(&query, "\nORDER BY priority %s\n", order);
    344     }
    345 
    346     // treat limit == 0 as "no limit"
    347     if (limit) {
    348         psString limitString = psDBGenerateLimitSQL(limit);
    349         psStringAppend(&query, " %s", limitString);
    350         psFree(limitString);
    351     }
    352 
    353     if (!p_psDBRunQuery(config->dbh, query)) {
    354         psError(PS_ERR_UNKNOWN, false, "database error");
    355         psFree(query);
    356         return false;
    357     }
    358     psFree(query);
    359 
    360     psArray *output = p_psDBFetchResult(config->dbh);
    361     if (!output) {
    362         psErrorCode err = psErrorCodeLast();
    363         switch (err) {
    364             case PS_ERR_DB_CLIENT:
    365                 psError(PXTOOLS_ERR_SYS, false, "database error");
    366             case PS_ERR_DB_SERVER:
    367                 psError(PXTOOLS_ERR_PROG, false, "database error");
    368             default:
    369                 psError(PXTOOLS_ERR_PROG, false, "unknown error");
    370         }
    371 
    372         return false;
    373     }
    374     if (!psArrayLength(output)) {
    375270        psTrace("labeltool", PS_LOG_INFO, "no rows found");
    376271        psFree(output);
  • trunk/ippTools/src/labeltoolConfig.c

    r28074 r28076  
    5353    psMetadataAddBool(definelabelArgs, PS_LIST_TAIL, "-set_inactive", 0, "set label inactive", false);
    5454    psMetadataAddStr(definelabelArgs, PS_LIST_TAIL, "-set_comment",  0, "define label comment", NULL);
     55    psMetadataAddBool(definelabelArgs, PS_LIST_TAIL, "-simple",  0, "use the simple output format", false);
    5556
    5657    // -updatelabel
    5758    psMetadata *updatelabelArgs = psMetadataAlloc();
    5859    psMetadataAddStr(updatelabelArgs, PS_LIST_TAIL, "-label", 0, "search by label (LIKE comparison) (required)", NULL);
    59     psMetadataAddStr(updatelabelArgs, PS_LIST_TAIL, "-set_label",   0, "define label", NULL);
    60     psMetadataAddS64(updatelabelArgs, PS_LIST_TAIL, "-set_priority", 0, "define priority", 0);
     60    psMetadataAddS64(updatelabelArgs, PS_LIST_TAIL, "-set_priority", 0, "define new priority", 0);
    6161    psMetadataAddBool(updatelabelArgs, PS_LIST_TAIL, "-set_active", 0, "set label active", false);
    6262    psMetadataAddBool(updatelabelArgs, PS_LIST_TAIL, "-set_inactive", 0, "set label inactive", false);
    63     psMetadataAddStr(updatelabelArgs, PS_LIST_TAIL, "-set_comment",  0, "define label comment", NULL);
     63    psMetadataAddStr(updatelabelArgs, PS_LIST_TAIL, "-set_comment",  0, "define new label comment", NULL);
    6464
    6565    // -deletelabel
Note: See TracChangeset for help on using the changeset viewer.