From: Ovidiu Mircescu Date: Fri, 2 Mar 2018 15:59:21 +0000 (+0100) Subject: Windows compatibility. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f2b4b2e1b8983a9fa514e2355ebaff4618cd4eea;p=modules%2Fyacs.git Windows compatibility. --- diff --git a/src/Launcher/Launcher_Job.cxx b/src/Launcher/Launcher_Job.cxx index 07241c30e..0541c5cd0 100644 --- a/src/Launcher/Launcher_Job.cxx +++ b/src/Launcher/Launcher_Job.cxx @@ -29,6 +29,11 @@ #endif #include +#ifdef WIN32 + static const char SEPARATOR = '\\'; +#else + static const char SEPARATOR = '/'; +#endif Launcher::Job::Job() { @@ -181,7 +186,11 @@ Launcher::Job::setResourceDefinition(const ParserResourcesType & resource_defini std::string user_name = ""; if (resource_definition.UserName == "") { +#ifndef WIN32 user_name = getenv("USER"); +#else + user_name = getenv("USERNAME"); +#endif if (user_name == "") user_name = getenv("LOGNAME"); if (user_name == "") @@ -214,7 +223,7 @@ Launcher::Job::setJobFile(const std::string & job_file) } _job_file = job_file; - std::string::size_type p1 = _job_file.find_last_of("/"); + std::string::size_type p1 = _job_file.find_last_of(SEPARATOR); std::string::size_type p2 = _job_file.find_last_of("."); _job_file_name_complete = _job_file.substr(p1+1); _job_file_name = _job_file.substr(p1+1,p2-p1-1); @@ -629,7 +638,11 @@ Launcher::Job::common_job_params() } else { +#ifndef WIN32 _work_directory = std::string("/$HOME/Batch/workdir_"); +#else + _work_directory = std::string("%USERPROFILE%\\Batch\\workdir_"); +#endif _work_directory += date; } } @@ -648,8 +661,11 @@ Launcher::Job::common_job_params() // If result_directory is not defined, we use HOME environnement if (_result_directory == "") +#ifndef WIN32 _result_directory = getenv("HOME"); - +#else + _result_directory = getenv("USERPROFILE"); +#endif // _in_files std::list in_files(_in_files); in_files.push_back(_job_file); @@ -663,7 +679,12 @@ Launcher::Job::common_job_params() // local file -> If file is not an absolute path, we apply _local_directory std::string local_file; +#ifndef WIN32 if (file.substr(0, 1) == std::string("/")) +#else + // On Windows, absolute paths may begin with something like "C:" + if (file.substr(1, 1) == std::string(":")) +#endif local_file = file; else if (file.substr(0, 1) == std::string("-")) // using rsync options local_file = file; @@ -673,7 +694,7 @@ Launcher::Job::common_job_params() // /a/b/./c/f -> _working_directory/c/f local_file = _local_directory + "/./" + file; #else - local_file = file; + local_file = _local_directory + SEPARATOR + file; #endif // remote file -> get only file name from in_files diff --git a/src/Launcher/Launcher_Job_Command.cxx b/src/Launcher/Launcher_Job_Command.cxx index ed4542bd1..c725dc24f 100644 --- a/src/Launcher/Launcher_Job_Command.cxx +++ b/src/Launcher/Launcher_Job_Command.cxx @@ -63,11 +63,19 @@ Launcher::Job_Command::buildCommandScript(Batch::Parametre params, std::string l std::string launch_date_port_file = launch_date; std::ostringstream str_pid; str_pid << ::getpid(); - std::string launch_script = Kernel_Utils::GetTmpDir() + "runCommand_" + _job_file_name + "_" + launch_date + "-" + str_pid.str() + ".sh"; + std::string launch_script = Kernel_Utils::GetTmpDir() + "runCommand_" + + _job_file_name + "_" + launch_date + "-" + + str_pid.str(); +#ifndef WIN32 + launch_script += ".sh"; +#else + launch_script += ".bat"; +#endif std::ofstream launch_script_stream; launch_script_stream.open(launch_script.c_str(), std::ofstream::out); // Script +#ifndef WIN32 launch_script_stream << "#!/bin/sh -f" << std::endl; launch_script_stream << "cd " << work_directory << std::endl; launch_script_stream << "export PYTHONPATH=" << work_directory << ":$PYTHONPATH" << std::endl; @@ -77,6 +85,17 @@ Launcher::Job_Command::buildCommandScript(Batch::Parametre params, std::string l std::string::size_type last = _env_file.find_last_of("/"); launch_script_stream << ". ./" << _env_file.substr(last+1) << std::endl; } +#else + launch_script_stream << "echo OFF" << std::endl; + launch_script_stream << "cd " << work_directory << std::endl; + launch_script_stream << "set PYTHONPATH=" << work_directory << ";%PYTHONPATH%" << std::endl; + launch_script_stream << "set PATH=" << work_directory << ";%PATH%" << std::endl; + if (_env_file != "") + { + std::string::size_type last = _env_file.find_last_of("\\"); + launch_script_stream << "call " << _env_file.substr(last+1) << std::endl; + } +#endif launch_script_stream << runCommandString() << std::endl; // Return @@ -90,7 +109,11 @@ Launcher::Job_Command::buildCommandScript(Batch::Parametre params, std::string l std::string Launcher::Job_Command::runCommandString() { std::ostringstream result; +#ifndef WIN32 result << "./" << _job_file_name_complete; +#else + result << "call " << _job_file_name_complete; +#endif return result.str(); } #endif diff --git a/src/Launcher/Test/test_launcher.py b/src/Launcher/Test/test_launcher.py index d6bc828e1..5087d6699 100755 --- a/src/Launcher/Test/test_launcher.py +++ b/src/Launcher/Test/test_launcher.py @@ -63,7 +63,7 @@ class TestCompo(unittest.TestCase): def create_JobParameters(self): job_params = salome.JobParameters() - job_params.wckey="P11U50:CARBONES" #needed by edf clusters + job_params.wckey="P11U5:CARBONES" #needed by edf clusters job_params.resource_required = salome.ResourceParameters() job_params.resource_required.nb_proc = 1 return job_params diff --git a/src/ResourcesManager/ResourcesManager.cxx b/src/ResourcesManager/ResourcesManager.cxx index 968d2ced2..6ce6d140e 100644 --- a/src/ResourcesManager/ResourcesManager.cxx +++ b/src/ResourcesManager/ResourcesManager.cxx @@ -607,6 +607,7 @@ void ResourcesManager_cpp::AddDefaultResourceInCatalog() resource.DataForSort._Name = DEFAULT_RESOURCE_NAME; resource.Protocol = sh; resource.Batch = none; +#ifndef WIN32 if (getenv("HOME") != NULL && getenv("APPLI") != NULL) { resource.AppliPath = string(getenv("HOME")) + "/" + getenv("APPLI"); @@ -617,6 +618,18 @@ void ResourcesManager_cpp::AddDefaultResourceInCatalog() resource.working_directory = tmpdir + "/salome_localres_workdir"; if (getenv("USER") != NULL) resource.working_directory += string("_") + getenv("USER"); +#else + if (getenv("USERPROFILE") != NULL && getenv("APPLI") != NULL) + { + resource.AppliPath = string(getenv("USERPROFILE")) + "\\" + getenv("APPLI"); + } + string tmpdir = "C:\\tmp"; + if (getenv("TEMP") != NULL) + tmpdir = getenv("TEMP"); + resource.working_directory = tmpdir + "\\salome_localres_workdir"; + if (getenv("USERNAME") != NULL) + resource.working_directory += string("_") + getenv("USERNAME"); +#endif resource.can_launch_batch_jobs = true; resource.can_run_containers = true; _resourcesList[resource.Name] = resource;