IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 27, 2006, 2:49:13 PM (20 years ago)
Author:
Paul Price
Message:

Fixing up the process of reading recipes from the site and camera configurations, and the command line. Now supports multiple calls to pmConfigReadRecipes, only loading the appropriate data each time.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfig.c

    r7676 r7709  
    33 *  @author PAP, IfA
    44 *
    5  *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-06-24 03:25:14 $
     5 *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-06-28 00:49:13 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3131    psFree(config->camera);
    3232    psFree(config->recipes);
     33    psFree(config->recipesSource);
    3334    psFree(config->arguments);
    3435    psFree(config->database);
     
    4344    config->site = NULL;
    4445    config->camera = NULL;
    45     config->recipes = NULL;
     46    config->recipes = psMetadataAlloc();
     47    config->recipesRead = P_PM_RECIPE_SOURCE_NONE;
     48    config->recipesSource = psMetadataAlloc();
    4649    config->arguments = NULL;
    4750    config->database = NULL;
     
    284287
    285288    // Load the recipes from the camera file, if appropriate
    286     if (! config->recipes && config->camera) {
    287         pmConfigReadRecipes(config);
    288     }
    289 
     289    pmConfigReadRecipes(config);
    290290
    291291    //
     
    554554
    555555        // Now we have the camera, we can read the recipes
    556         if (!config->recipes) {
    557             pmConfigReadRecipes(config);
    558         }
     556        pmConfigReadRecipes(config);
    559557
    560558        return format;
     
    562560
    563561    // Otherwise, try the specific camera
    564     if (! formatFromHeader(&format, config->camera, header, "specified camera")) {
     562    if (!formatFromHeader(&format, config->camera, header, "specified camera")) {
    565563        psError(PS_ERR_IO, true, "Unable to find a format with the specified camera that matches the "
    566564                "given header.\n");
     
    604602
    605603
    606 // Read the recipe filenames
    607 static bool recipeFileNames(psMetadata *target, // The target metadata into which to read the recipes
    608                             psMetadata *source, // The source configuration, from which to read the filenames
    609                             const char *sourceName // The name of the source, for error messages
    610                            )
    611 {
    612     assert(target);
     604// Load the recipes
     605static bool loadRecipes(pmConfig *config, // The configuration into which to read the recipes
     606                        psMetadata *source, // The source configuration, from which to read the filenames
     607                        p_pmRecipeSource sourceType, // The source type
     608                        const char *sourceName // The name of the source, for error messages
     609                       )
     610{
     611    assert(config);
    613612
    614613    if (!source) {
     614        #if 0
    615615        psLogMsg(__func__, PS_LOG_WARN, "The %s has not been read --- cannot read recipes from this "
    616616                 "location.\n", sourceName);
     617        #endif
     618
     619        config->recipesRead &= ~sourceType;
    617620        return false;
    618621    }
     
    623626        psLogMsg(__func__, PS_LOG_WARN, "RECIPES in the %s is not of type METADATA --- ignored\n",
    624627                 sourceName);
     628        config->recipesRead &= ~sourceType;
    625629        return false;
    626630    }
     
    637641            continue;
    638642        }
    639         psMetadataAddItem(target, fileItem, PS_LIST_TAIL, PS_META_REPLACE);
     643
     644        // Check to see if it's currently defined
     645        int check = psMetadataLookupS32(&mdok, config->recipesSource, fileItem->name);
     646        if (mdok && check > sourceType) {
     647            // It's already defined with a higher priority
     648            continue;
     649        }
     650        psString comment = psStringCopy("Recipe added at ");
     651        psStringAppend(&comment, "%s from %s", sourceName, fileItem->data.V);
     652        psMetadataAddS32(config->recipesSource, PS_LIST_TAIL, fileItem->name,
     653                         PS_META_REPLACE, comment, sourceType);
     654        psFree(comment);
     655
     656        // Read the recipe
     657        psMetadata *recipe = NULL;      // Recipe from file
     658        if (readConfig(&recipe, fileItem->data.V, "recipe")) {
     659            psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name,
     660                          PS_DATA_METADATA | PS_META_REPLACE, fileItem->comment, recipe);
     661        }
     662        psFree(recipe);                 // Drop reference
    640663    }
    641664    psFree(recipesIter);
     665
     666    config->recipesRead |= sourceType;
    642667
    643668    return true;
     
    657682
    658683    // Read the recipe file names from the site configuration and camera configuration
    659     recipeFileNames(config->recipes, config->site, "site configuration");
    660     recipeFileNames(config->recipes, config->camera, "camera configuration");
    661 
    662     // Go through the command-line arguments
    663     int argNum; // Argument number for "-recipe"
    664     while ((argNum = psArgumentGet(config->argc, config->argv, "-recipe")) > 0) {
    665         psArgumentRemove(argNum, &config->argc, config->argv);
    666         if (argNum + 1 >= config->argc) {
    667             psLogMsg(__func__, PS_LOG_WARN, "-recipe command-line switch provided without the "
    668                      "required recipe and source --- ignored.\n");
    669             if (argNum == config->argc) {
    670                 // Remove the single last argument (we required two, they gave us one)
    671                 psArgumentRemove(argNum, &config->argc, config->argv);
    672             }
    673             continue;
    674         }
    675 
    676         const char *recipeName = psStringCopy(config->argv[argNum]); // Name of the recipe
    677         psArgumentRemove(argNum, &config->argc, config->argv);
    678         const char *recipeSource = psStringCopy(config->argv[argNum]); // Source of the recipe
    679         psArgumentRemove(argNum, &config->argc, config->argv);
    680 
    681         // Is the source a symbolic reference?
    682         const char *recipeFile = psMetadataLookupStr(&mdok, config->recipes, recipeSource);
    683         if (mdok && recipeFile && strlen(recipeFile) > 0) {
    684             psString comment = psStringCopy("Recipe added from command line as symbolic link to ");
    685             psStringAppend(&comment, "%s", recipeSource);
    686             psMetadataAddStr(config->recipes, PS_LIST_TAIL, recipeName, PS_META_REPLACE, comment, recipeFile);
    687         } else {
    688             // Otherwise, treat the source as a filename
    689             psMetadataAddStr(config->recipes, PS_LIST_TAIL, recipeName, PS_META_REPLACE,
    690                              "Recipe added from command line", recipeSource);
    691         }
    692     }
    693 
    694     // Read the recipes
    695     psMetadataIterator *recipesIter = psMetadataIteratorAlloc(config->recipes, PS_LIST_HEAD, NULL);// Iterator
    696     psMetadataItem *recipesItem = NULL; // Item from iteration
    697     while ((recipesItem = psMetadataGetAndIncrement(recipesIter))) {
    698         if (recipesItem->type != PS_DATA_STRING) {
    699             psLogMsg(__func__, PS_LOG_WARN, "Filename for recipe %s isn't of type STR --- ignored.\n",
    700                      recipesItem->name);
    701             continue;
    702         }
    703         psMetadata *recipe = NULL;      // Recipe from file
    704         if (readConfig(&recipe, recipesItem->data.V, "recipe")) {
    705             psMetadataAdd(config->recipes, PS_LIST_TAIL, recipesItem->name,
    706                           PS_DATA_METADATA | PS_META_REPLACE, recipesItem->comment, recipe);
    707         }
    708         psFree(recipe);                 // Drop reference
    709     }
    710     psFree(recipesIter);
     684    if (!(config->recipesRead & P_PM_RECIPE_SOURCE_SITE)) {
     685        loadRecipes(config, config->site, P_PM_RECIPE_SOURCE_SITE, "site configuration");
     686    }
     687    if (!(config->recipesRead & P_PM_RECIPE_SOURCE_CAMERA)) {
     688        loadRecipes(config, config->camera, P_PM_RECIPE_SOURCE_CAMERA, "camera configuration");
     689    }
     690    if (!(config->recipesRead & P_PM_RECIPE_SOURCE_CL)) {
     691        // Go through the command-line arguments
     692        int argNum; // Argument number for "-recipe"
     693        while ((argNum = psArgumentGet(config->argc, config->argv, "-recipe")) > 0) {
     694            psArgumentRemove(argNum, &config->argc, config->argv);
     695            if (argNum + 1 >= config->argc) {
     696                psLogMsg(__func__, PS_LOG_WARN, "-recipe command-line switch provided without the "
     697                         "required recipe and source --- ignored.\n");
     698                if (argNum == config->argc) {
     699                    // Remove the single last argument (we required two, they gave us one)
     700                    psArgumentRemove(argNum, &config->argc, config->argv);
     701                }
     702                continue;
     703            }
     704
     705            const char *recipeName = psStringCopy(config->argv[argNum]); // Name of the recipe
     706            psArgumentRemove(argNum, &config->argc, config->argv);
     707            const char *recipeSource = psStringCopy(config->argv[argNum]); // Source of the recipe
     708            psArgumentRemove(argNum, &config->argc, config->argv);
     709
     710            // Command-line has the highest priority, so we don't have to check to see if it's already there
     711            psMetadataAddS32(config->recipesSource, PS_LIST_TAIL, recipeName, PS_META_REPLACE,
     712                             "Recipe added from command line", P_PM_RECIPE_SOURCE_CL);
     713
     714            // Is the source a symbolic reference?
     715            psMetadata *extant = psMetadataLookupMD(&mdok, config->recipes, recipeSource); // Does it exist?
     716            if (mdok && extant) {
     717                psString comment = psStringCopy("Recipe added from command line as symbolic link to ");
     718                psStringAppend(&comment, "%s", recipeSource);
     719                psMetadataAdd(config->recipes, PS_LIST_TAIL, recipeName, PS_DATA_METADATA | PS_META_REPLACE,
     720                              comment, extant);
     721                psFree(comment);
     722            } else {
     723                // Otherwise, treat the source as a filename
     724                psMetadata *recipe = NULL;      // Recipe from file
     725                if (readConfig(&recipe, recipeSource, "recipe")) {
     726                    psString comment = psStringCopy("Recipe added at command line from ");
     727                    psStringAppend(&comment, "%s", recipeSource);
     728                    psMetadataAdd(config->recipes, PS_LIST_TAIL, recipeName,
     729                                  PS_DATA_METADATA | PS_META_REPLACE, comment, recipe);
     730                    psFree(comment);
     731                    psFree(recipe);                 // Drop reference
     732                }
     733            }
     734            psFree(recipeName);
     735            psFree(recipeSource);
     736        } // Iterating through the command-line arguments
     737        config->recipesRead |= P_PM_RECIPE_SOURCE_CL;
     738    }
    711739
    712740    return true;
Note: See TracChangeset for help on using the changeset viewer.