X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FResourcesManager%2FResourcesManager.cxx;h=6ff79f3fdfc6c659e2debf41ad28b948aa42f733;hb=b3f6bd51caa213b97097ac31c6350c613403720d;hp=0603eb51debcf2af8fd0336e86208a1a003b0734;hpb=b4f7f7b5ca2813062b2328697572c09546eeb40f;p=modules%2Fkernel.git diff --git a/src/ResourcesManager/ResourcesManager.cxx b/src/ResourcesManager/ResourcesManager.cxx index 0603eb51d..6ff79f3fd 100644 --- a/src/ResourcesManager/ResourcesManager.cxx +++ b/src/ResourcesManager/ResourcesManager.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -148,19 +148,23 @@ ResourcesManager_cpp::ResourcesManager_cpp() throw(ResourcesException) default_file += "/"; default_file += getenv("APPLI"); default_file += "/CatalogResources.xml"; - _path_resources.push_back(default_file); - } - else - { - if(!getenv("KERNEL_ROOT_DIR")) - throw ResourcesException("you must define KERNEL_ROOT_DIR environment variable!! -> cannot load a CatalogResources.xml"); - default_file = getenv("KERNEL_ROOT_DIR"); - default_file += "/share/salome/resources/kernel/CatalogResources.xml"; - _path_resources.push_back(default_file); + std::ifstream ifile(default_file.c_str(), std::ifstream::in ); + if (ifile) { + // The file exists, and is open for input + _path_resources.push_back(default_file); + default_catalog_resource=false; + } } } - - _lasttime=0; + if (default_catalog_resource) + { + std::string default_file(""); + if(!getenv("KERNEL_ROOT_DIR")) + throw ResourcesException("you must define KERNEL_ROOT_DIR environment variable!! -> cannot load a CatalogResources.xml"); + default_file = getenv("KERNEL_ROOT_DIR"); + default_file += "/share/salome/resources/kernel/CatalogResources.xml"; + _path_resources.push_back(default_file); + } ParseXmlFiles(); RES_MESSAGE("ResourcesManager_cpp constructor end"); @@ -327,8 +331,21 @@ void ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resource) { if (new_resource.Name == DEFAULT_RESOURCE_NAME){ - std::string error("Cannot modify default local resource \"" + DEFAULT_RESOURCE_NAME + "\""); - throw ResourcesException(error); + ParserResourcesType default_resource = _resourcesList[DEFAULT_RESOURCE_NAME]; + // some of the properties of the default resource shouldn't be modified + std::string check; + if( default_resource.HostName != new_resource.HostName) + check += "The Hostname property of the default resource can not be modified.\n"; + if( default_resource.AppliPath != new_resource.AppliPath) + check += "The Applipath property of the default resource can not be modified.\n"; + if( !new_resource.can_run_containers) + check += "The default resource should be able to run containers.\n"; + if( !new_resource.can_launch_batch_jobs) + check += "The default resource should be able to launch batch jobs.\n"; + if( default_resource.Protocol != new_resource.Protocol) + check += "The Protocol property of the default resource can not be modified.\n"; + if(!check.empty()) + throw ResourcesException(check); } // TODO - Add minimal check _resourcesList[new_resource.Name] = new_resource; @@ -364,12 +381,9 @@ void ResourcesManager_cpp::WriteInXmlFile(std::string xml_file) RES_MESSAGE("WriteInXmlFile : start"); MapOfParserResourcesType resourceListToSave(_resourcesList); - // We do not save default local resource because it is automatically created at startup - resourceListToSave.erase(DEFAULT_RESOURCE_NAME); if (resourceListToSave.empty()) { - RES_MESSAGE("WriteInXmlFile: nothing to do, no resource except default \"" << - DEFAULT_RESOURCE_NAME << "\""); + RES_MESSAGE("WriteInXmlFile: nothing to do, no resource to save!"); return; } @@ -426,7 +440,7 @@ const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFiles() return _resourcesList; } - if(statinfo.st_mtime > _lasttime) + if(_lasttime == 0 || statinfo.st_mtime > _lasttime) { to_parse = true; _lasttime = statinfo.st_mtime; @@ -608,9 +622,18 @@ void ResourcesManager_cpp::AddDefaultResourceInCatalog() resource.Protocol = sh; resource.Batch = none; #ifndef WIN32 + struct stat statbuf; if (getenv("HOME") != NULL && getenv("APPLI") != NULL) { - resource.AppliPath = string(getenv("HOME")) + "/" + getenv("APPLI"); + if (stat(getenv("APPLI"), &statbuf) ==0 && S_ISREG(statbuf.st_mode)) + { + // if $APPLI is a regular file, we asume it's a salome Launcher file + resource.AppliPath = string(getenv("APPLI")); + } + else + { + resource.AppliPath = string(getenv("HOME")) + "/" + getenv("APPLI"); + } } string tmpdir = "/tmp"; if (getenv("TMPDIR") != NULL)