Changeset 2438 for XIOS3/trunk


Ignore:
Timestamp:
12/07/22 13:07:07 (19 months ago)
Author:
jderouillat
Message:

Add the ability to specify the location of iodef through an environment variable XIOS_IODEF_PATH. Included XML sources can integrates environment variables

Location:
XIOS3/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • XIOS3/trunk/src/cxios.cpp

    r2420 r2438  
    1515#include "servers_ressource.hpp" 
    1616#include "mem_checker.hpp" 
     17#include <unistd.h> 
    1718 
    1819namespace xios 
     
    7172  { 
    7273    set_new_handler(noMemory); 
     74    char startPath[256]; 
     75    getcwd(startPath, sizeof(startPath)); 
     76    if(const char* userPath = std::getenv("XIOS_IODEF_PATH")) 
     77    { 
     78      if ( chdir( userPath ) != 0) 
     79      { 
     80        ERROR("CXios::initialize()", << "XIOS_IODEF_PATH not defined correctly : " << userPath << endl ); 
     81      } 
     82    } 
    7383    parseFile(rootFile); 
    7484    parseXiosConfig(); 
     85    chdir( startPath ); 
    7586  } 
    7687 
     
    199210    std::set<StdString> parseList; 
    200211    parseList.insert("xios"); 
     212    char startPath[256]; 
     213    getcwd(startPath, sizeof(startPath)); 
     214    if(const char* userPath = std::getenv("XIOS_IODEF_PATH")) 
     215    { 
     216      if ( chdir( userPath ) != 0) 
     217      { 
     218        ERROR("CXios::initialize()", << "XIOS_IODEF_PATH not defined correctly : " << userPath << endl ); 
     219      } 
     220    } 
    201221    xml::CXMLParser::ParseFile(rootFile, parseList); 
    202222    parseXiosConfig(); 
     223    chdir( startPath ); 
    203224  } 
    204225 
  • XIOS3/trunk/src/node/context.cpp

    r2426 r2438  
    3535#include <chrono> 
    3636#include <random> 
     37#include <unistd.h> 
    3738 
    3839namespace xios 
     
    162163      if (attributes.end() != attributes.find("src")) 
    163164      { 
    164          StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in ); 
     165         string srcString = attributes["src"].c_str(); 
     166 
     167         // check if environment variables 
     168         string srcKey;          
     169         if (srcString.find("${") == 0) // src start wit 
     170         { 
     171           size_t envVarStart = srcString.find("${")+2; // +2 for ${ 
     172           if (srcString.find("}") != std::string::npos) 
     173           { 
     174             size_t envVarEnd = srcString.find("}")-2;  // -2 (start @ srcString begining, not after ${ 
     175             if(const char* var_path = std::getenv( srcString.substr( envVarStart, envVarEnd ).c_str() ) ) 
     176             { 
     177               srcKey=string(var_path)+"/"+srcString.substr( srcString.find("}")+1, srcString.size()-srcString.find("}") ); 
     178             } 
     179             else 
     180             { 
     181               ERROR("void CContext::parse(xml::CXMLNode & node)", 
     182                     <<endl<< "The src key " << attributes["src"].c_str()<< " contains an undefined variable." ); 
     183             } 
     184           } 
     185           else 
     186           { 
     187             ERROR("void CContext::parse(xml::CXMLNode & node)", 
     188                   <<endl<< "The src key " << attributes["src"].c_str()<< " not defined correctly." ); 
     189           } 
     190         } 
     191         else if (srcString.find("${") != 0) 
     192         { 
     193           ERROR("void CContext::parse(xml::CXMLNode & node)", 
     194                   <<endl<< "The src key " << attributes["src"].c_str()<< " should start with $" ); 
     195         } 
     196         else if (srcString.find("$") != std::string::npos) 
     197         { 
     198           ERROR("void CContext::parse(xml::CXMLNode & node)", 
     199                   <<endl<< "The src key " << attributes["src"].c_str()<< " need { and }." ); 
     200         } 
     201         else // standard behavor, without environment variable 
     202         { 
     203           srcKey = attributes["src"].c_str(); 
     204         } 
     205          
     206         StdIFStream ifs ( srcKey , StdIFStream::in ); 
    165207         if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) 
     208         { 
     209            char currentPath[256]; 
     210            getcwd(currentPath, sizeof(currentPath)); 
    166211            ERROR("void CContext::parse(xml::CXMLNode & node)", 
    167                   <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" ); 
     212                  <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file " 
     213                  << "from iodef path : " << currentPath ); 
     214         } 
    168215         if (!ifs.good()) 
    169216            ERROR("CContext::parse(xml::CXMLNode & node)", 
Note: See TracChangeset for help on using the changeset viewer.