Beispiel #1
0
/**
 * \brief Function to move file
 * \param src: the path of the file to move
 * \param dest: the destination where the file will be moved
 * \param file: the name of the file in dest
 * \return raises an exception on error
 */
int
vishnu::boostMoveFile(const std::string& src, const std::string& dest, const std::string& filename) {

	bfs::path filePath(src);
	bfs::path fileDestPath(dest);
	bfs::path fileNewPath(src);
	if(filename.size()!=0) {
		fileNewPath = bfs::path(filename);
	}

	try {
		//If the destination does not exist, the file is created in the current directory
		if(!bfs::exists(fileDestPath)) {
			bfs::path completePath(bfs::current_path().string() / fileNewPath.filename());
			if(bfs::exists(completePath)){
				bfs::remove(completePath);
			}
			boost::filesystem3::copy(filePath, completePath);
			bfs::remove(filePath);
		}
		else {
			bfs::path completePath(fileDestPath / fileNewPath.filename());
			if(bfs::exists(completePath)){
				bfs::remove(completePath);
			}
			boost::filesystem3::copy(filePath, completePath);
			bfs::remove(filePath);
		}
	} catch (std::exception& e) {
		throw UserException(ERRCODE_INVALID_PARAM, e.what());
	}
	return 0;
}
Beispiel #2
0
/**
 * \brief The submitJob function submits job on a machine through a script pointed by scriptFilePath.
 * \param sessionKey : The session key
 * \param machineId : Is the id of the machine on which the job must be submitted
 * \param scriptFilePath : The path to the file containing the characteristics (job command, and batch scheduler directive required or optional) of the job to submit.
 * \param jobInfo : The  Job object containing the output information (ex: jobId and jobPath) of the job to submit
 * \param options : Is an instance of the class SubmitOptions. Each option is associated to a set operation (e.g: setNbCpu(...)) in the class.  If no set operation is not called on the instance object  options, the job is submitted with the options defined in the scriptFilePath. Otherewise the job is submitted with the optionnal values set by the options object and optionnal values defined in the scriptFilePath, but optionnal values set by SubmitOptions object take precedence over those in scriptFilePath. With in the object options or within the scriptFilePath, the last occurance of an optionnal value takes precedence over earlier occurance.
 * \return int : an error code
 */
int
vishnu::submitJob(const std::string& sessionKey,
		const std::string& machineId,
		const std::string& scriptFilePath,
		Job& jobInfo,
		const SubmitOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

	checkEmptyString(sessionKey, "The session key");
	checkEmptyString(machineId, "The machine id");
	//To check options value nbNodesAndCpuPerNode
	checkJobNbNodesAndNbCpuPerNode(options.getNbNodesAndCpuPerNode());

	SessionProxy sessionProxy(sessionKey);
	boost::filesystem::path completePath(scriptFilePath);
	std::string scriptFileCompletePath = (boost::filesystem::path(boost::filesystem::system_complete(completePath))).string();
	jobInfo.setJobPath(scriptFileCompletePath);

	std::string scriptContent = vishnu::get_file_content(scriptFilePath);

	JobProxy jobProxy(sessionProxy , machineId , jobInfo);

	ListStrings fileParamsVec;
	std::string fileParamsStr = options.getFileParams() ;
	boost::trim(fileParamsStr) ; //TODO BUG when empty list
	boost::split(fileParamsVec, fileParamsStr, boost::is_any_of(" "), boost::token_compress_on) ;

	int ret = jobProxy.submitJob(scriptContent, options);
	jobInfo = jobProxy.getData();

	return ret;
}
Beispiel #3
0
PythonScript* PythonModule::load(const std::string& filename, bool compileDirectly) {

    // do not check isInitialized(), since we call this function from initialize()
    if (!Py_IsInitialized()) {
        LWARNING("load(): not initialized");
        return 0;
    }

    if (isLoaded(filename)) {
        increaseUsage(filename);
        return get(filename);
    }

    PythonScript* script = new PythonScript();
    if (script->load(completePath(filename), compileDirectly)) {
        reg(script, filename);
        return script;
    }
    delete script;

    return 0;
}
bool CoinVisualizationNode::saveModel(const std::string &modelPath, const std::string &filename)
{
	std::string outFile = filename;

	boost::filesystem::path completePath(modelPath);
	boost::filesystem::path fn(outFile);

	if (!boost::filesystem::is_directory(completePath))
	{
		if (!boost::filesystem::create_directories(completePath))
		{
			VR_ERROR << "Could not create model dir  " << completePath.string() << endl;
			return false;
		}
	}

	boost::filesystem::path completeFile = boost::filesystem::operator/(completePath,fn);

    SoOutput* so = new SoOutput();
    if (!so->openFile(completeFile.string().c_str()))
    {
        VR_ERROR << "Could not open file " << completeFile.string() << " for writing." << endl;
    }
	SoGroup *n = new SoGroup;
	n->ref();
	n->addChild(visualization);
	SoGroup* newVisu = CoinVisualizationFactory::convertSoFileChildren(n);
	newVisu->ref();
    SoWriteAction wa(so);
    wa.apply(newVisu);
	so->closeFile();

	newVisu->unref();
	n->unref();

    return true;
}
Beispiel #5
0
/**
 * \brief The submitJob function submits job on a machine through a script pointed by scriptFilePath.
 * \param sessionKey : The session key
 * \param scriptFilePath : The path to the file containing the characteristics (job command, and batch scheduler directive required or optional) of the job to submit.
 * \param jobInfo : The  Job object containing the output information (ex: jobId and jobPath) of the job to submit
 * \param options : Is an instance of the class SubmitOptions. Each option is associated to a set operation (e.g: setNbCpu(...)) in the class.  If no set operation is not called on the instance object  options, the job is submitted with the options defined in the scriptFilePath. Otherewise the job is submitted with the optionnal values set by the options object and optionnal values defined in the scriptFilePath, but optionnal values set by SubmitOptions object take precedence over those in scriptFilePath. With in the object options or within the scriptFilePath, the last occurance of an optionnal value takes precedence over earlier occurance.
 * \return int : an error code
 */
int
vishnu::submitJob(const std::string& sessionKey,
                  const std::string& scriptFilePath,
                  TMS_Data::Job& jobInfo,
                  const TMS_Data::SubmitOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {
  // Dirty cast to modify a const object because the loadcriterion field may not be allocated -> allocating him
  const void *optionPtr = &options;
  TMS_Data::SubmitOptions* optionstmp = (TMS_Data::SubmitOptions*)optionPtr;
  TMS_Data::LoadCriterion_ptr loadCriterion =  new TMS_Data::LoadCriterion();

  checkEmptyString(sessionKey, "The session key");
  checkJobNbNodesAndNbCpuPerNode(optionstmp->getNbNodesAndCpuPerNode());
  // Copy the option object because API -> const and we need to allocate the loadCriterion if not
  if (optionstmp->getCriterion()){
    loadCriterion->setLoadType(optionstmp->getCriterion()->getLoadType());
  }
  optionstmp->setCriterion(loadCriterion);


  boost::filesystem::path completePath(scriptFilePath);
  std::string scriptFileCompletePath = (boost::filesystem::path(boost::filesystem::system_complete(completePath))).string();

  JobProxy jobProxy(sessionKey, optionstmp->getMachine());

  std::vector<std::string> fileParamsVec;
  std::string fileParamsStr = optionstmp->getFileParams() ;
  boost::trim(fileParamsStr) ; //TODO BUG when empty list
  boost::split(fileParamsVec, fileParamsStr, boost::is_any_of(" "), boost::token_compress_on) ;

  std::string scriptContent = vishnu::get_file_content(scriptFilePath);
  int ret = jobProxy.submitJob(scriptFileCompletePath, scriptContent, *optionstmp);
  jobInfo = jobProxy.getData();

  return ret;
}