Skip to content

Commit

Permalink
server: script file location reported to the user can be wrong ECFLOW…
Browse files Browse the repository at this point in the history
…-1374

Former-commit-id: 5db71623e2ec87ee016a9970474a22323af5e307
  • Loading branch information
sandorkertesz committed Nov 6, 2018
1 parent e759a6e commit 4439e60
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Viewer/ecflowUI/src/FileInfoLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ void FileInfoLabel::update(VReply* reply,QString extraText)
s+=Viewer::formatBoldText(" at ",col) + formatDate(f->fetchDate());
}

if(!reply->fileReadMethod().empty())
{
s+=Viewer::formatBoldText(" Lookup method: ",col) + QString::fromStdString(reply->fileReadMethod());
}

}
else if(reply->fileReadMode() == VReply::ServerReadMode)
{
Expand Down
88 changes: 88 additions & 0 deletions Viewer/ecflowUI/src/InfoProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
#include "VNode.hpp"
#include "VReply.hpp"
#include "ServerHandler.hpp"
#include "Submittable.hpp"

#include <QDateTime>

#include <fstream>

#include <boost/algorithm/string/predicate.hpp>

InfoProvider::InfoProvider(InfoPresenter* owner,VTask::Type taskType) :
Expand Down Expand Up @@ -263,6 +266,91 @@ ScriptProvider::ScriptProvider(InfoPresenter* owner) :
or this may be a '<i>dummy</i>' task";
}

void ScriptProvider::visit(VInfoNode* info)
{
reply_->reset();

if(!info->node() || !info->node()->node())
{
owner_->infoFailed(reply_);
}

//Check if we have a server
if(!info->server())
{
owner_->infoFailed(reply_);
}

VNode *n=info->node();

std::string fileName;

// We try to read the file directly from the disk
// Try client first.
// *THIS will minimize calls to the server. when .ecf is not in ECF_SCRIPT but still accessible from the client
try
{
if(Submittable* sb=info->node()->node()->isSubmittable())
{
EcfFile ecf_file = sb->locatedEcfFile(); // will throw std::runtime_error for errors
std::string fileContents, fileName, fileMethod;
ecf_file.script(fileContents);

//Check extra info in the first line
std::string pattern("# ecf_script_origin :");
if(fileContents.size() > pattern.size() &&
fileContents.substr(0,pattern.size()) == pattern)
{
//strip off the first line
std::string::size_type pos=fileContents.find('\n');
if(pos != std::string::npos && fileContents.size() > pos)
{
QString s=QString::fromStdString(fileContents.substr(0,pos));
QStringList sLst=s.split(":");
if(sLst.count() == 3)
{
fileMethod=sLst[1].simplified().toStdString();
fileName=sLst[2].simplified().toStdString();
}

fileContents=fileContents.substr(pos+1);
}
}

reply_->text(fileContents);
reply_->fileReadMode(VReply::LocalReadMode);
reply_->fileName(fileName);
reply_->fileReadMethod(fileMethod);
owner_->infoReady(reply_);
return;
}
}

catch (std::exception& e)
{
// Try the server
}

//We try to get the file contents from the server
//(this will go through the threaded communication)

if(!fileVarName_.empty())
{
//Get the fileName
fileName=n->genVariable(fileVarName_);
}

//Define a task for getting the info from the server.
task_=VTask::create(taskType_,n,this);
task_->reply()->fileName(fileName);
task_->reply()->fileReadMode(VReply::ServerReadMode);

//Run the task in the server. When it finish taskFinished() is called. The text returned
//in the reply will be prepended to the string we generated above.
info->server()->run(task_);
}


HistoryProvider::HistoryProvider(InfoPresenter* owner) :
InfoProvider(owner,VTask::HistoryTask)
{
Expand Down
2 changes: 2 additions & 0 deletions Viewer/ecflowUI/src/InfoProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class ScriptProvider : public InfoProvider
{
public:
explicit ScriptProvider(InfoPresenter* owner);
protected:
void visit(VInfoNode* info);
};

class HistoryProvider : public InfoProvider
Expand Down

0 comments on commit 4439e60

Please sign in to comment.