From dcfaadac21fb066b95142a2a0f63fb77db553b86 Mon Sep 17 00:00:00 2001 From: Ovidiu Mircescu Date: Fri, 15 Dec 2017 16:52:59 +0100 Subject: [PATCH] Add preprocess command. --- src/engine/BL_Job.cxx | 14 ++++ src/engine/BL_Job.hxx | 4 ++ src/engine/BL_SALOMEServices.cxx | 2 + src/genericgui/BL_CreateJobWizard.cxx | 97 +++++++++++++++++++++++---- src/genericgui/BL_CreateJobWizard.hxx | 7 ++ src/genericgui/BL_JobsManager_QT.cxx | 1 + 6 files changed, 112 insertions(+), 13 deletions(-) diff --git a/src/engine/BL_Job.cxx b/src/engine/BL_Job.cxx index a380c86..11ed0a1 100644 --- a/src/engine/BL_Job.cxx +++ b/src/engine/BL_Job.cxx @@ -26,6 +26,7 @@ BL::Job::Job() _type = COMMAND; _job_file = ""; _env_file = ""; + _pre_command = ""; _batch_params.batch_directory = ""; _batch_params.maximum_duration = ""; _batch_params.mem_limit = 0; @@ -54,6 +55,7 @@ BL::Job::Job(const std::string & name) _type = COMMAND; _job_file = ""; _env_file = ""; + _pre_command = ""; _batch_params.batch_directory = ""; _batch_params.maximum_duration = ""; _batch_params.mem_limit = 0; @@ -167,6 +169,18 @@ BL::Job::getEnvFile() return _env_file; } +void +BL::Job::setPreCommand(const std::string & pre_command) +{ + _pre_command = pre_command; +} + +std::string & +BL::Job::getPreCommand() +{ + return _pre_command; +} + void BL::Job::setBatchParameters(const BL::Job::BatchParam & param) { diff --git a/src/engine/BL_Job.hxx b/src/engine/BL_Job.hxx index f2dc145..532b31d 100644 --- a/src/engine/BL_Job.hxx +++ b/src/engine/BL_Job.hxx @@ -53,6 +53,9 @@ namespace BL{ void setEnvFile(const std::string & env_file); std::string & getEnvFile(); + void setPreCommand(const std::string & pre_command); + std::string & getPreCommand(); + void setDumpYACSState(const int & dump_yacs_state); int getDumpYACSState(); @@ -124,6 +127,7 @@ namespace BL{ BL::Job::JobType _type; std::string _job_file; std::string _env_file; + std::string _pre_command; BL::Job::BatchParam _batch_params; BL::Job::FilesParam _files_params; diff --git a/src/engine/BL_SALOMEServices.cxx b/src/engine/BL_SALOMEServices.cxx index bc7e640..1a1e0d6 100644 --- a/src/engine/BL_SALOMEServices.cxx +++ b/src/engine/BL_SALOMEServices.cxx @@ -299,6 +299,7 @@ BL::SALOMEServices::create_job(BL::Job * job) job_parameters->job_name = CORBA::string_dup(job->getName().c_str()); job_parameters->job_file = CORBA::string_dup(job->getJobFile().c_str()); job_parameters->env_file = CORBA::string_dup(job->getEnvFile().c_str()); + job_parameters->pre_command = CORBA::string_dup(job->getPreCommand().c_str()); BL::Job::FilesParam files = job->getFilesParameters(); std::list::iterator it; int i = 0; @@ -630,6 +631,7 @@ BL::SALOMEServices::get_new_job(int job_number) job_return->setType(job_parameters->job_type.in()); job_return->setJobFile(job_parameters->job_file.in()); job_return->setEnvFile(job_parameters->env_file.in()); + job_return->setPreCommand(job_parameters->pre_command.in()); job_return->setBatchQueue(job_parameters->queue.in()); job_return->setWCKey(job_parameters->wckey.in()); job_return->setExtraParams(job_parameters->extra_params.in()); diff --git a/src/genericgui/BL_CreateJobWizard.cxx b/src/genericgui/BL_CreateJobWizard.cxx index eba7034..f14ade8 100644 --- a/src/genericgui/BL_CreateJobWizard.cxx +++ b/src/genericgui/BL_CreateJobWizard.cxx @@ -56,6 +56,7 @@ BL::CreateJobWizard::CreateJobWizard(BL::JobsManager_QT * jobs_manager, BL::SALO command = ""; python_salome_file = ""; env_file = ""; + pre_command = ""; batch_directory = ""; // For COORM @@ -133,6 +134,7 @@ BL::CreateJobWizard::clone(const std::string & name) setField("yacs_file", QString(job->getJobFile().c_str())); setField("job_type_yacs", true); setField("env_yacs_file", QString(job->getEnvFile().c_str())); + setField("pre_yacs_file", QString(job->getPreCommand().c_str())); if (job->getDumpYACSState() != -1) { QString value; @@ -149,29 +151,31 @@ BL::CreateJobWizard::clone(const std::string & name) setField("command", QString(job->getJobFile().c_str())); setField("job_type_command", true); setField("env_command_file", QString(job->getEnvFile().c_str())); + setField("pre_command_file", QString(job->getPreCommand().c_str())); } else if (job->getType() == BL::Job::PYTHON_SALOME) { setField("PythonSalome", QString(job->getJobFile().c_str())); setField("job_type_python_salome", true); setField("env_PythonSalome_file", QString(job->getEnvFile().c_str())); + setField("pre_PythonSalome_file", QString(job->getPreCommand().c_str())); } - // For COORM + // For COORM BL::Job::BatchParam batch_params = job->getBatchParameters(); - BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(job->getResource().c_str()); - std::string batch = resource_descr.batch.c_str(); - if (batch == "coorm") - { - setField("coorm_batch_directory", QString(batch_params.batch_directory.c_str())); - setField("launcher_file", QString(batch_params.launcher_file.c_str())); - setField("launcher_args", QString(batch_params.launcher_args.c_str())); - } - else - { - setField("batch_directory", QString(batch_params.batch_directory.c_str())); - } + BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(job->getResource().c_str()); + std::string batch = resource_descr.batch.c_str(); + if (batch == "coorm") + { + setField("coorm_batch_directory", QString(batch_params.batch_directory.c_str())); + setField("launcher_file", QString(batch_params.launcher_file.c_str())); + setField("launcher_args", QString(batch_params.launcher_args.c_str())); + } + else + { + setField("batch_directory", QString(batch_params.batch_directory.c_str())); + } QString proc_value; proc_value.setNum(batch_params.nb_proc); @@ -287,6 +291,15 @@ BL::CreateJobWizard::end(int result) f_env_file = field("env_PythonSalome_file").toString(); env_file = f_env_file.trimmed().toUtf8().constData(); + QString f_pre_command_file; + if (job_type == YACS) + f_pre_command_file = field("pre_yacs_file").toString(); + else if (job_type == COMMAND) + f_pre_command_file = field("pre_command_file").toString(); + else if (job_type == PYTHON_SALOME) + f_pre_command_file = field("pre_PythonSalome_file").toString(); + pre_command = f_pre_command_file.trimmed().toUtf8().constData(); + // Batch Panel QString f_batch_directory = field("batch_directory").toString(); batch_directory = f_batch_directory.trimmed().toUtf8().constData(); @@ -555,11 +568,19 @@ BL::YACSSchemaPage::YACSSchemaPage(QWidget * parent) _line_env_file = new QLineEdit(this); registerField("env_yacs_file", _line_env_file); _line_env_file->setReadOnly(true); + QPushButton * command_pre_command_button = new QPushButton(tr("Choose a pre processing script")); + connect(command_pre_command_button, SIGNAL(clicked()), + this, SLOT(choose_pre_command_file())); + _line_pre_command = new QLineEdit(this); + registerField("pre_yacs_file", _line_pre_command); + _line_pre_command->setReadOnly(true); QGridLayout * files_layout = new QGridLayout; files_layout->addWidget(yacs_file_button, 0, 0); files_layout->addWidget(_yacs_file_text, 0, 1); files_layout->addWidget(command_env_file_button, 1, 0); files_layout->addWidget(_line_env_file, 1, 1); + files_layout->addWidget(command_pre_command_button, 2, 0); + files_layout->addWidget(_line_pre_command, 2, 1); files_param_box->setLayout(files_layout); QGroupBox * spec_param_box = new QGroupBox("YACS specific parameters"); @@ -628,6 +649,16 @@ BL::YACSSchemaPage::choose_env_file() _line_env_file->setReadOnly(true); } +void +BL::YACSSchemaPage::choose_pre_command_file() +{ + QString pre_command_file = QFileDialog::getOpenFileName(this, + tr("Open script file"), "", + tr("All Files (*)")); + _line_pre_command->setReadOnly(false); + _line_pre_command->setText(pre_command_file); + _line_pre_command->setReadOnly(true); +} int BL::YACSSchemaPage::nextId() const @@ -655,11 +686,20 @@ BL::CommandMainPage::CommandMainPage(QWidget * parent) registerField("env_command_file", _line_env_file); _line_env_file->setReadOnly(true); + QPushButton * command_pre_command_button = new QPushButton(tr("Choose a pre processing script")); + connect(command_pre_command_button, SIGNAL(clicked()), + this, SLOT(choose_pre_command_file())); + _line_pre_command = new QLineEdit(this); + registerField("pre_command_file", _line_pre_command); + _line_pre_command->setReadOnly(true); + QGridLayout *layout = new QGridLayout; layout->addWidget(command_file_button, 0, 0); layout->addWidget(_line_command, 0, 1); layout->addWidget(command_env_file_button, 1, 0); layout->addWidget(_line_env_file, 1, 1); + layout->addWidget(command_pre_command_button, 2, 0); + layout->addWidget(_line_pre_command, 2, 1); QVBoxLayout * main_layout = new QVBoxLayout; main_layout->addWidget(label); @@ -692,6 +732,17 @@ BL::CommandMainPage::choose_env_file() _line_env_file->setReadOnly(true); } +void +BL::CommandMainPage::choose_pre_command_file() +{ + QString pre_command_file = QFileDialog::getOpenFileName(this, + tr("Open script file"), "", + tr("All Files (*)")); + _line_pre_command->setReadOnly(false); + _line_pre_command->setText(pre_command_file); + _line_pre_command->setReadOnly(true); +} + bool BL::CommandMainPage::validatePage() { @@ -1304,11 +1355,20 @@ BL::PythonSalomeMainPage::PythonSalomeMainPage(QWidget * parent) registerField("env_PythonSalome_file", _line_env_file); _line_env_file->setReadOnly(true); + QPushButton * command_pre_command_button = new QPushButton(tr("Choose a pre processing script")); + connect(command_pre_command_button, SIGNAL(clicked()), + this, SLOT(choose_pre_command_file())); + _line_pre_command = new QLineEdit(this); + registerField("pre_PythonSalome_file", _line_pre_command); + _line_pre_command->setReadOnly(true); + QGridLayout *layout = new QGridLayout; layout->addWidget(PythonSalome_file_button, 0, 0); layout->addWidget(_line_PythonSalome, 0, 1); layout->addWidget(PythonSalome_env_file_button, 1, 0); layout->addWidget(_line_env_file, 1, 1); + layout->addWidget(command_pre_command_button, 2, 0); + layout->addWidget(_line_pre_command, 2, 1); QVBoxLayout * main_layout = new QVBoxLayout; main_layout->addWidget(label); @@ -1341,6 +1401,17 @@ BL::PythonSalomeMainPage::choose_env_file() _line_env_file->setReadOnly(true); } +void +BL::PythonSalomeMainPage::choose_pre_command_file() +{ + QString pre_command_file = QFileDialog::getOpenFileName(this, + tr("Open script file"), "", + tr("All Files (*)")); + _line_pre_command->setReadOnly(false); + _line_pre_command->setText(pre_command_file); + _line_pre_command->setReadOnly(true); +} + bool BL::PythonSalomeMainPage::validatePage() { diff --git a/src/genericgui/BL_CreateJobWizard.hxx b/src/genericgui/BL_CreateJobWizard.hxx index d2d0613..84f8960 100644 --- a/src/genericgui/BL_CreateJobWizard.hxx +++ b/src/genericgui/BL_CreateJobWizard.hxx @@ -79,6 +79,7 @@ namespace BL { std::string python_salome_file; std::string env_file; + std::string pre_command; std::string batch_directory; @@ -281,10 +282,12 @@ namespace BL { public slots: void choose_file(); void choose_env_file(); + void choose_pre_command_file(); private: QLineEdit * _yacs_file_text; QLineEdit * _line_env_file; + QLineEdit * _line_pre_command; }; class CommandMainPage: public QWizardPage @@ -302,10 +305,12 @@ namespace BL { public slots: void choose_command_file(); void choose_env_file(); + void choose_pre_command_file(); private: QLineEdit * _line_command; QLineEdit * _line_env_file; + QLineEdit * _line_pre_command; }; class PythonSalomeMainPage: public QWizardPage @@ -323,10 +328,12 @@ namespace BL { public slots: void choose_PythonSalome_file(); void choose_env_file(); + void choose_pre_command_file(); private: QLineEdit * _line_PythonSalome; QLineEdit * _line_env_file; + QLineEdit * _line_pre_command; }; class AdvancedParametersPage: public QWizardPage diff --git a/src/genericgui/BL_JobsManager_QT.cxx b/src/genericgui/BL_JobsManager_QT.cxx index e56bde1..91ac18e 100644 --- a/src/genericgui/BL_JobsManager_QT.cxx +++ b/src/genericgui/BL_JobsManager_QT.cxx @@ -309,6 +309,7 @@ BL::JobsManager_QT::create_job_with_wizard(BL::CreateJobWizard & wizard) // For all jobs new_job->setEnvFile(wizard.env_file); + new_job->setPreCommand(wizard.pre_command); BL::Job::BatchParam param; // For COORM -- 2.39.2