Back to index

salome-kernel  6.5.0
Launcher_Job_Command.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // Author: André RIBES - EDF R&D
00021 //
00022 #include "Launcher_Job_Command.hxx"
00023 
00024 #ifdef WITH_LIBBATCH
00025 #include <Batch/Batch_Constants.hxx>
00026 #endif
00027 
00028 #ifdef WNT
00029 #include <io.h>
00030 #define _chmod chmod
00031 #endif
00032 
00033 Launcher::Job_Command::Job_Command() {_job_type = "command";}
00034 
00035 Launcher::Job_Command::~Job_Command() {}
00036 
00037 void
00038 Launcher::Job_Command::update_job()
00039 {
00040 #ifdef WITH_LIBBATCH
00041   Batch::Parametre params = common_job_params();
00042   params[Batch::EXECUTABLE] = buildCommandScript(params, _launch_date);
00043   params[Batch::EXCLUSIVE] = false;
00044   _batch_job->setParametre(params);
00045 #endif
00046 }
00047 
00048 #ifdef WITH_LIBBATCH
00049 std::string 
00050 Launcher::Job_Command::buildCommandScript(Batch::Parametre params, std::string launch_date)
00051 {
00052   // parameters
00053   std::string work_directory = params[Batch::WORKDIR].str();
00054 
00055   // File name
00056   std::string launch_date_port_file = launch_date;
00057   std::string launch_script = "/tmp/runCommand_" + _job_file_name + "_" + launch_date + ".sh";
00058   std::ofstream launch_script_stream;
00059   launch_script_stream.open(launch_script.c_str(), std::ofstream::out);
00060    
00061   // Script
00062   launch_script_stream << "#! /bin/bash -f" << std::endl;
00063   launch_script_stream << "cd " << work_directory << std::endl;
00064   launch_script_stream << "export PYTHONPATH=" << work_directory << ":$PYTHONPATH" << std::endl;
00065   launch_script_stream << "export PATH=" << work_directory << ":$PATH" << std::endl;
00066   if (_env_file != "")
00067   {
00068     std::string::size_type last = _env_file.find_last_of("/");
00069     launch_script_stream << "source ./" << _env_file.substr(last+1) << std::endl;
00070   }
00071   launch_script_stream << "./" << _job_file_name_complete << " > " << work_directory <<"/logs/command_" << launch_date << ".log 2>&1" << std::endl;
00072 
00073   // Return
00074   launch_script_stream.flush();
00075   launch_script_stream.close();
00076   chmod(launch_script.c_str(), 0x1ED);
00077   chmod(_job_file.c_str(), 0x1ED);
00078   return launch_script;
00079 }
00080 #endif