diff --git a/Common/onelab.h b/Common/onelab.h index 2333ce219dc09a2834b1e9e28f97a8e8fb1b301f..6bd4942376c6e38513d38c0969c8986e76c3e8ea 100644 --- a/Common/onelab.h +++ b/Common/onelab.h @@ -1337,6 +1337,10 @@ namespace onelab{ { return _parameterSpace.getChanged(client); } + bool isRegistered(const std::string &client) + { + return _clients.count(client); + } unsigned int getNumParameters(){ return _parameterSpace.getNumParameters(); } std::vector<std::string> toChar(const std::string &client="") { diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp index 23288281a2726db376b2e499080592a46792cd78..c26270910e53a7cbea8bee50fde1a6d1f6882667 100644 --- a/Fltk/onelabGroup.cpp +++ b/Fltk/onelabGroup.cpp @@ -377,50 +377,45 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) std::string::size_type first = 0; std::string clientName = onelab::parameter::getNextToken(message, first); std::string command = onelab::parameter::getNextToken(message, first); - gmshLocalNetworkClient* subClient = - new gmshLocalNetworkClient(clientName, command); - onelabGmshServer *server = new onelabGmshServer(subClient); - subClient->setPid(0); - int sock = server->LaunchClient(); - if(sock < 0){ // could not establish the connection: aborting - server->Shutdown(); - delete server; - Msg::Error("Could not connect client '%s'", subClient->getName().c_str()); - } - else{ - Msg::StatusBar(true, "Running '%s'...", subClient->getName().c_str()); - subClient->setGmshServer(server); - subClient->setFather(this); - master->addClient(subClient); + if (!onelab::server::instance()->isRegistered(clientName)){ + gmshLocalNetworkClient* subClient = + new gmshLocalNetworkClient(clientName, command); + onelabGmshServer *server = new onelabGmshServer(subClient); + subClient->setPid(0); + int sock = server->LaunchClient(); + if(sock < 0){ // could not establish the connection: aborting + server->Shutdown(); + delete server; + Msg::Error("Could not connect client '%s'", subClient->getName().c_str()); + } + else{ + Msg::StatusBar(true, "Running '%s'...", subClient->getName().c_str()); + subClient->setGmshServer(server); + subClient->setFather(this); + master->addClient(subClient); + } } + else + Msg::Error("Redefinition of existing client <%s>",clientName.c_str()); } break; case GmshSocket::GMSH_OLPARSE: { #if defined(HAVE_ONELAB_METAMODEL) std::string::size_type first = 0; - std::string name = onelab::parameter::getNextToken(message, first); + std::string clientName = onelab::parameter::getNextToken(message, first); std::string fullName = onelab::parameter::getNextToken(message, first); - std::vector<std::string> split = SplitOLFileName(fullName); - std::string ofileName = split[0] + split[1] ; - std::ofstream outfile(ofileName.c_str()); - - std::vector<std::string> split2 = SplitFileName(split[1]); - localSolverClient *c = new InterfacedClient(name,"",split2[0]); - if (outfile.is_open()) { - Msg::Info("Preprocess file <%s>",ofileName.c_str()); - c->convert_onefile(fullName, outfile); + if (!onelab::server::instance()->isRegistered(clientName)){ + preProcess(clientName, fullName); // contrib/onelab/OnelabParser.cpp + Msg::Info("Preprocess file <%s> done", fullName.c_str()); + + std::string reply = onelab::server::instance()->getChanged(clientName) ? + "true" : "false"; + getGmshServer()->SendMessage + (GmshSocket::GMSH_OLPARSE, reply.size(), &reply[0]); } else - Msg::Error("The file <%s> cannot be opened",ofileName.c_str()); - outfile.close(); - - std::string reply = onelab::server::instance()->getChanged(c->getName()) ? - "true" : "false"; - getGmshServer()->SendMessage - (GmshSocket::GMSH_OLPARSE, reply.size(), &reply[0]); - - delete c; + Msg::Error("Redefinition of existing client <%s>",clientName.c_str()); #endif } break; diff --git a/contrib/onelab/OnelabClients.h b/contrib/onelab/OnelabClients.h index 24056e938b7ec0a5d9526ee1ac03cd8036d4a612..e43e6355c12418e557afc585ee412dadb6c8485d 100644 --- a/contrib/onelab/OnelabClients.h +++ b/contrib/onelab/OnelabClients.h @@ -14,6 +14,7 @@ #include "OS.h" #include "onelab.h" #include "OnelabMessage.h" +#include "StringUtils.h" // Onelab file extension static std::string onelabExtension(".ol"); @@ -72,6 +73,8 @@ class ShortNameLessThan{ } }; +void preProcess(const std::string &client, const std::string &fullName); + /* VIRTUAL and BASE CLASSES diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp index cb57202aa030b933f529109bfccd88f28ce907db..cfd9dba3f8704ea86f09f79fecc0adf1b4aa4212 100644 --- a/contrib/onelab/OnelabParser.cpp +++ b/contrib/onelab/OnelabParser.cpp @@ -1435,10 +1435,39 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile, } } +void preProcess(const std::string &client, const std::string &fullName){ + std::vector<std::string> split = SplitOLFileName(fullName); + std::string ifileName = split[1] + split[2] ; // remove heading "_" if any + std::string ofileName = split[0] + split[1] ; // remove trailing ".ol" + + std::string workDir = SplitFileName(split[1]) [0]; + localSolverClient *c = new InterfacedClient(client, "", workDir); + + std::ifstream infile(ifileName.c_str()); + if( infile.is_open()) { + std::ofstream outfile(ofileName.c_str()); + if(outfile.is_open()) { + OLMsg::Info("Preprocess file <%s> into <%s>",ifileName.c_str(), ofileName.c_str()); + while ( infile.good() ) { + std::string line; + getline (infile,line); + c->convert_oneline(line,infile,outfile); + } + outfile.close(); + } + else + OLMsg::Error("The file <%s> cannot be opened",ofileName.c_str()); + infile.close(); + } + else + OLMsg::Error("The file <%s> cannot be opened",ifileName.c_str()); + delete c; +} + void localSolverClient::convert_onefile(std::string fileName, std::ofstream &outfile) { std::ifstream infile(fileName.c_str()); if (infile.is_open()){ - //OLMsg::Info("Convert file <%s>",fileName.c_str()); + OLMsg::Info("Convert file <%s>",fileName.c_str()); while ( infile.good() ) { std::string line; getline (infile,line); diff --git a/contrib/onelab/python/onelab.py b/contrib/onelab/python/onelab.py index 44facd54dc27c9987e198e79ccaff0fdaf24cf83..d07eec7e686484ac71e4f51fa5e3807ccd6b2676 100755 --- a/contrib/onelab/python/onelab.py +++ b/contrib/onelab/python/onelab.py @@ -38,8 +38,9 @@ def file_exist(filename): return False def path(ref, inp=''): - # ref is reference directory name - # inp is an optional file or directory name + # ref is a reference file name (not a directory) + # inp is an optional file or subdirectory name + # return the path to 'inp' in the same directory as 'ref' dirname = os.path.dirname(ref) if not inp: if dirname: @@ -57,16 +58,19 @@ class pth: def path(self, ref, inp=''): p = path(ref,inp) if not os.path.exists(p): - print('PTH error: The path %s does not exist' %(p)) self.errors += 1 + self.msg += p + ' ' return p + def status(self): + return '%d path errors: %s' %(self.errors, self.msg) + def copy(self, here, there): os.system('cp '+ here + ' ' + there) def __init__(self) : self.errors = 0 - + self.msg = '' class _parameter() : _membersbase = [