diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp index 3080208a302e04f4101013eec57cc54cc5467390..b3ed0352b2ef265f35574be4f35a7da22bb4f1bc 100644 --- a/contrib/onelab/OnelabClients.cpp +++ b/contrib/onelab/OnelabClients.cpp @@ -95,7 +95,7 @@ bool localNetworkSolverClient::run() std::string socketName = ":"; #else std::string socketName; - if(getRemote()) + if(isRemote()) socketName = ":"; else socketName = getUserHomedir() + ".gmshsock"; @@ -323,15 +323,6 @@ bool localNetworkSolverClient::kill() // client LOCALSOLVERCLIENT -std::string localSolverClient::toChar(){ - std::ostringstream sstream; - if(getCommandLine().size()){ - sstream << getName() << "." << "commandLine(" - << getCommandLine() << ");\n"; - } - return sstream.str(); -} - const std::string localSolverClient::getString(const std::string what){ std::string name=getName() + "/" + what; std::vector<onelab::string> strings; @@ -416,7 +407,8 @@ bool localSolverClient::checkCommandLine(){ } } else{ - FixExecPath(getCommandLine()); + if(!isRemote()) + FixExecPath(getCommandLine()); if(isNative()){ // native clients checked by initializing setAction("initialize"); @@ -455,11 +447,13 @@ bool localSolverClient::checkCommandLine(){ } } if(success){ - OLMsg::SetOnelabString(getName()+"/CommandLine",getCommandLine(),false); + OLMsg::SetVisible(getName()+"/CommandLine",false); + OLMsg::SetVisible(getName()+"/HostName",false); + OLMsg::SetVisible(getName()+"/RemoteDir",false); OLMsg::Info("Command line ok"); } else{ - //setCommandLine(""); + setCommandLine(""); OLMsg::SetOnelabString(getName() + "/CommandLine", getCommandLine(), true); OLMsg::Error("Invalid command line <%s> for client <%s>", getCommandLine().c_str(), getName().c_str()); @@ -662,10 +656,9 @@ void MetaModel::construct() { OLMsg::Info("Metamodel now CONSTRUCTING"); openOnelabBlock(); - parse_onefile( genericNameFromArgs + onelabExtension + ".save", false); parse_onefile( genericNameFromArgs + onelabExtension); closeOnelabBlock(); - saveCommandLines(genericNameFromArgs); + saveCommandLines(); onelab::server::instance()->setChanged(true, getName()); } @@ -674,7 +667,7 @@ void MetaModel::analyze() { std::string fileName = genericNameFromArgs + onelabExtension; openOnelabBlock(); OLMsg::Info("Parse file <%s> %s", fileName.c_str(), - parse_onefile(fileName)?"ok":"ko"); + parse_onefile(fileName)?"done":"failed"); closeOnelabBlock(); } @@ -683,7 +676,7 @@ void MetaModel::compute() { std::string fileName = genericNameFromArgs + onelabExtension; openOnelabBlock(); OLMsg::Info("Parse file <%s> %s", fileName.c_str(), - parse_onefile(fileName)?"ok":"ko"); + parse_onefile(fileName)?"done":"failed"); closeOnelabBlock(); onelab::server::instance()->setChanged(false); } @@ -691,11 +684,11 @@ void MetaModel::compute() { void MetaModel::registerClient(const std::string &name, const std::string &type, const std::string &cmdl, const std::string &host, const std::string &rdir) { localSolverClient *c; - // Clients are assigned by default the same working dir as the MetaModel - // i.e. the working dir from args - // A working (relative) subdir (useful to organize submodels) + // Clients are assigned by default the same (local) working dir + // as the MetaModel, i.e. the working dir from args + // A working (local relative) subdir (useful to organize submodels) // can be defined with the command: client.workingSubdir(subdir) - if(host.empty()){ //local client + if(host.empty() || !host.compare("localhost")){ //local client if(!type.compare(0,6,"interf")) c= new InterfacedClient(name,cmdl,getWorkingDir()); else if(!type.compare(0,6,"native")) @@ -748,8 +741,8 @@ void InterfacedClient::analyze() { if(split[2].size()){ // if .ol file std::string fileName = getWorkingDir() + split[1] + split[2]; checkIfPresent(fileName); - OLMsg::Info("Parse file <%s> success=%d", fileName.c_str(), - parse_onefile(fileName)); + OLMsg::Info("Parse file <%s> %s", fileName.c_str(), + parse_onefile(fileName)?"done":"failed"); } } convert(); @@ -875,8 +868,8 @@ void EncapsulatedClient::analyze() { if(split[2].size()){ // if .ol file std::string fileName = getWorkingDir() + split[1] + split[2]; checkIfPresent(fileName); - OLMsg::Info("Parse file <%s> success=%d", fileName.c_str(), - parse_onefile(fileName)); + OLMsg::Info("Parse file <%s> %s", fileName.c_str(), + parse_onefile(fileName)?"done":"failed"); } } convert(); @@ -1309,7 +1302,7 @@ std::string removeBlanks(const std::string &in) size_t pos0=in.find_first_not_of(" "); size_t pos=in.find_last_not_of(" "); if( (pos0 != std::string::npos) && (pos != std::string::npos)) - return in.substr(pos0,pos-pos0+1); + return in.substr(pos0, pos-pos0+1); else return ""; } @@ -1324,7 +1317,7 @@ std::vector<std::string> SplitOLFileName(const std::string &in) if(posa != localFileTag.size()) posa = 0; std::vector<std::string> s(3); - s[0] = in.substr(0,posa); + s[0] = in.substr(0, posa); s[1] = in.substr(posa, posb-posa); s[2] = in.substr(posb, in.size()-posb); @@ -1332,17 +1325,40 @@ std::vector<std::string> SplitOLFileName(const std::string &in) return s; } +std::vector<std::string> SplitOLHostName(const std::string &in) +{ + // returns [ hostname, directory] + std::vector<std::string> s(2); + size_t pos = in.find(":"); + if(pos == std::string::npos){ + s[0] = in; + s[1] = ""; + } + else{ + s[0] = in.substr(0,pos); + s[1] = FixPathName(in.substr(pos+1,in.size()-pos-1)); + } + //std::cout << "FHF in=<" << s[0] << "|" << s[1] << std::endl; + return s; +} -bool isPath(const std::string &in) +std::string FixOLPath(const std::string &in) { - size_t pos=in.find_last_not_of(" 0123456789"); - if(pos == std::string::npos) return true; - if(in.compare(pos,1,"/")){ - OLMsg::Error("The argument <%s> is not a valid parameter path (must end with '/')",in.c_str()); - return false; + std::string out = in; + if(out.size()){ + size_t pos = out.find_last_not_of(" 0123456789"); + if((pos != std::string::npos) && (out.compare(pos,1,"/"))) + out.insert(pos,"/"); } - else - return true; + return out; +} + +std::string FixPathName(const std::string &in) +{ + std::string out = in; + if(out.size()) + if(out[out.size()-1] != dirSep) out.push_back(dirSep); + return out; } // std::vector <double> extract_column(const unsigned int col, const array data){ diff --git a/contrib/onelab/OnelabClients.h b/contrib/onelab/OnelabClients.h index da820971dd5e88a8f5f1939b94de55ae2a0323d5..32507689b472b920d097509b1e2a7b2f3719b13a 100644 --- a/contrib/onelab/OnelabClients.h +++ b/contrib/onelab/OnelabClients.h @@ -23,12 +23,12 @@ static std::string localFileTag("_"); enum parseMode {REGISTER, ANALYZE, COMPUTE, EXIT}; #if defined(WIN32) -static std::string dirSep("\\"); +static char dirSep='\\'; static std::string cmdSep(" & "); static std::string removeCmd("del "); static std::string lsCmd("dir "); #else -static std::string dirSep("/"); +static char dirSep='/'; static std::string cmdSep(" ; "); static std::string removeCmd("rm -rf "); static std::string lsCmd("ls "); @@ -48,7 +48,9 @@ std::string sanitizeString(const std::string &in, const std::string &forbidden); std::string removeBlanks(const std::string &in); std::vector<std::string> SplitOLFileName(const std::string &in); -bool isPath(const std::string &in); +std::vector<std::string> SplitOLHostName(const std::string &in); +std::string FixOLPath(const std::string &in); +std::string FixPathName(const std::string &in); std::string FixWindowsQuotes(const std::string &in); std::string QuoteExecPath(const std::string &in); std::string unquote(const std::string &in); @@ -56,10 +58,8 @@ std::string unquote(const std::string &in); // Parser TOOLS int enclosed(const std::string &in, std::vector<std::string> &arguments, size_t &end); int extract(const std::string &in, std::string ¶mName, std::string &action, std::vector<std::string> &arguments); -//bool extractRange(const std::string &in, std::vector<double> &arguments); std::string extractExpandPattern(const std::string& str); - typedef std::vector <std::vector <double> > array; array read_array(std::string fileName, char sep); double find_in_array(int i, int j, const std::vector <std::vector <double> > &data); @@ -120,6 +120,7 @@ class localSolverClient : public onelab::localClient{ private: std::string _commandLine; std::string _workingDir; + bool _remote; int _active; bool _onelabBlock; std::set<std::string, ShortNameLessThan> _parameters; @@ -128,7 +129,7 @@ class localSolverClient : public onelab::localClient{ localSolverClient(const std::string &name, const std::string &cmdl, const std::string &wdir) : onelab::localClient(name), _commandLine(cmdl), _workingDir(wdir), - _active(1), _onelabBlock(false) { + _remote(false), _active(1), _onelabBlock(false) { } virtual ~localSolverClient(){} const std::string &getCommandLine(){ return _commandLine; } @@ -140,12 +141,14 @@ class localSolverClient : public onelab::localClient{ const std::string getString(const std::string what); const bool getList(const std::string type, std::vector<std::string> &choices); + const bool isRemote() { return _remote; } + const void setRemote(bool flag){ _remote = flag; } const bool isActive() { return (bool)_active; } const void setActive(int val) { _active=val; } int getActive() { return _active; } virtual std::string toChar(); - // parser + // parser commands void modify_tags(const std::string lab, const std::string com); const bool isOnelabBlock() { return _onelabBlock; } const void openOnelabBlock() { _onelabBlock=true; } @@ -188,14 +191,12 @@ class localNetworkSolverClient : public localSolverClient{ int _pid; // underlying GmshServer GmshServer *_gmshServer; - // flag indicating if the client is a remote one - bool _remote; // flag indicating whether socket communication should be shown bool _socketMsg; public: localNetworkSolverClient(const std::string &name, const std::string &cmdl, const std::string &wdir) : localSolverClient(name,cmdl,wdir), _socketSwitch("-onelab"), - _pid(-1), _gmshServer(0), _remote(false), _socketMsg(false) {} + _pid(-1), _gmshServer(0), _socketMsg(false) {} virtual ~localNetworkSolverClient(){} virtual bool isNetworkClient(){ return true; } const std::string &getSocketSwitch(){ return _socketSwitch; } @@ -204,8 +205,6 @@ class localNetworkSolverClient : public localSolverClient{ void setPid(int pid){ _pid = pid; } GmshServer *getGmshServer(){ return _gmshServer; } void setGmshServer(GmshServer *server){ _gmshServer = server; } - int getRemote(){ return _remote; } - void setRemote(bool rem){ _remote = rem; } bool isNative() { return true; } virtual std::string buildCommandLine(); @@ -243,7 +242,7 @@ class MetaModel : public localSolverClient { std::vector<localSolverClient *> _clients; // action performed at this metamodel call parseMode _todo; - // remains false as long as the clients do not need recomputation + // remains false as long as the successive clients need no recomputation bool _started; public: MetaModel(const std::string &cmdl, const std::string &wdir, const std::string &cname, const std::string &fname) @@ -269,7 +268,8 @@ class MetaModel : public localSolverClient { const std::string &cmdl, const std::string &host, const std::string &rdir); bool checkCommandLines(); - void saveCommandLines(const std::string fileName); + void saveCommandLines(); + bool findCommandLine(const std::string &client, const std::string &host); localSolverClient *findClientByName(std::string name){ for(unsigned int i=0; i<_clients.size(); i++) if(_clients[i]->getName() == name) return _clients[i]; @@ -326,7 +326,9 @@ class EncapsulatedClient : public localNetworkSolverClient{ class RemoteInterfacedClient : public InterfacedClient, public remoteClient { public: RemoteInterfacedClient(const std::string &name, const std::string &cmdl, const std::string &wdir, const std::string &host, const std::string &rdir) - : InterfacedClient(name,cmdl,wdir), remoteClient(host,rdir) {} + : InterfacedClient(name,cmdl,wdir), remoteClient(host,rdir) { + setRemote(true); + } ~RemoteInterfacedClient(){} bool checkCommandLine(); @@ -351,7 +353,9 @@ public: class RemoteEncapsulatedClient : public EncapsulatedClient, public remoteClient { public: RemoteEncapsulatedClient(const std::string &name, const std::string &cmdl, const std::string &wdir, const std::string &host, const std::string &rdir) - : EncapsulatedClient(name,cmdl,wdir), remoteClient(host,rdir) {} + : EncapsulatedClient(name,cmdl,wdir), remoteClient(host,rdir) { + setRemote(true); + } ~RemoteEncapsulatedClient(){} std::string buildCommandLine(); diff --git a/contrib/onelab/OnelabMessage.cpp b/contrib/onelab/OnelabMessage.cpp index 0818134d8d0c9a96ebc7af8bfdc14e847a2a3625..d55610d5a8e0301d9c83110814b8d886bc7e3109 100644 --- a/contrib/onelab/OnelabMessage.cpp +++ b/contrib/onelab/OnelabMessage.cpp @@ -319,6 +319,18 @@ void OLMsg::SetOnelabString(std::string name, std::string val, bool visible) } } +void OLMsg::SetVisible(std::string name, bool visible) +{ + if(_onelabClient){ + std::vector<onelab::string> strings; + _onelabClient->get(strings, name); + if(strings.size()){ + strings[0].setVisible(visible); + _onelabClient->set(strings[0]); + } + } +} + void OLMsg::SetOnelabAttributeString(std::string name, std::string attrib,std::string val){ if(_onelabClient){ diff --git a/contrib/onelab/OnelabMessage.h b/contrib/onelab/OnelabMessage.h index 079e570f7bfc0f086f2e010db57a0b0d585149eb..17c1f938675377d69f6ded10dba3167157300669 100644 --- a/contrib/onelab/OnelabMessage.h +++ b/contrib/onelab/OnelabMessage.h @@ -114,6 +114,7 @@ class OLMsg { static double GetOnelabNumber(std::string name); static void SetOnelabString(std::string name, std::string val, bool visible=true); static std::string GetOnelabString(std::string name); + static void SetVisible(std::string name, bool visible); static void SetOnelabAttributeString(std::string name, std::string attrib,std::string val); static std::string GetOnelabAttributeString(std::string name,std::string attrib); diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp index acb71fc4c81327d2be2519c3b382ae5f47707bd4..db7f7bc9d3a284959b5ab3544294d6e1faf1ed99 100644 --- a/contrib/onelab/OnelabParser.cpp +++ b/contrib/onelab/OnelabParser.cpp @@ -24,112 +24,106 @@ namespace olkey{ static std::string getRegion(label+"region"); } -int extractLogic(const std::string &in, std::vector<std::string> &arguments){ - // syntax: ( argument[0], argument[1]\in{<,>,<=,>=,==,!=}, arguments[2]) - size_t pos, cursor; - arguments.resize(0); - cursor=0; - if ( (pos=in.find("(",cursor)) == std::string::npos ) - OLMsg::Error("Syntax error: <%s>",in.c_str()); +// Client member functions defined here because they use parser commands - unsigned int count=1; - pos++; // skips '(' - cursor=pos; - do{ - if(in[pos]=='(') count++; - if(in[pos]==')') count--; - if( (in[pos]=='<') || (in[pos]=='=') || (in[pos]=='>') || (in[pos]=='!') ){ - arguments.push_back(removeBlanks(in.substr(cursor,pos-cursor))); - if(count!=1) - OLMsg::Error("Syntax error: <%s>",in.c_str()); - cursor=pos; - if(in[pos+1]=='='){ - arguments.push_back(in.substr(cursor,2)); - pos++; - } - else{ - arguments.push_back(in.substr(cursor,1)); - } - cursor=pos+1; - } - pos++; - } while( count && (pos!=std::string::npos) ); - // count is 0 when the closing brace is found. +bool MetaModel::findCommandLine(const std::string &client, const std::string &host){ + std::string fileName; + size_t pos; - if(count) - OLMsg::Error("Syntax error: mismatched parenthesis in <%s>",in.c_str()); - else - arguments.push_back(removeBlanks(in.substr(cursor,pos-1-cursor))); + //std::cout << "FHF search cmdl: " << client << " , " << host << std::endl; - if((arguments.size()!=1) && (arguments.size()!=3)) - OLMsg::Error("Syntax error: <%s>",in.c_str()); - return arguments.size(); + fileName = getWorkingDir() + genericNameFromArgs + onelabExtension + ".save"; + + std::ifstream infile(fileName.c_str()); + if(infile.is_open()){ + while(infile.good()){ + std::string line; + getline(infile,line); + if( (pos=line.find(olkey::separator)) != std::string::npos){ + std::string name, action; + std::vector<std::string> args; + extract(line.substr(0,pos),name,action,args); + // (name, action, args) = client.commandLine(cmdl{,rhost{,rdir}}) + std::string cmdl="", rhost="localhost", rdir=""; + cmdl = args[0]; + if(args.size() > 1) rhost= args[1]; + if(args.size() > 2) rdir = args[2]; + + if(name == client){ + if( (host.empty() && (rhost != "localhost" )) || + (host.size() && (rhost == host)) ) { + OLMsg::SetOnelabString(name + "/CommandLine", cmdl); + if(rhost.compare("localhost")){ + OLMsg::SetOnelabString(name + "/HostName", rhost); + if(rdir.size()) + OLMsg::SetOnelabString(name + "/RemoteDir", rdir); + } + //std::cout << "FHF found cmdl: " << cmdl << "," << rhost << std::endl; + return true; + } + } + } + } + } + infile.close(); + return false; } -// Client member functions defined here because they use parser commands +std::string localSolverClient::toChar(){ + std::ostringstream sstream; -// std::string localSolverClient::toChar(){ -// std::ostringstream sstream; -// if(getCommandLine().size()){ -// sstream << getName() << "." << "commandLine(" -// << getCommandLine() << ");\n"; -// } -// return sstream.str(); -// } + if(getCommandLine().size()){ + sstream << getName() << ".commandLine(" << getCommandLine(); + std::string host=OLMsg::GetOnelabString(getName() + "/HostName"); + if(host.size() && host.compare("localhost")) { + sstream << "," << host ; + std::string rdir=OLMsg::GetOnelabString(getName() + "/RemoteDir"); + if(rdir.size()) sstream << "," << rdir; + } + sstream << ");" << std::endl; + } + return sstream.str(); +} -void MetaModel::saveCommandLines(const std::string fileName){ +void MetaModel::saveCommandLines(){ std::vector<std::string> arguments, buffer; - std::string loaderPathName=OLMsg::GetOnelabString("LoaderPathName"); - OLMsg::Info("Save command lines for loader <%s>", loaderPathName.c_str()); - std::string fileNameSave = getWorkingDir()+fileName+onelabExtension+".save"; + std::string fileName; + fileName = getWorkingDir() + genericNameFromArgs + onelabExtension + ".save"; - /* - size_t cursor, pos; - std::ifstream infile(fileNameSave.c_str()); - if (infile.is_open()){ - while (infile.good()){ + std::ifstream infile(fileName.c_str()); + if(infile.is_open()){ + while(infile.good()){ std::string line; getline(infile,line); - if ( (pos=line.find(olkey::ifcond)) != std::string::npos) { - cursor = pos+olkey::ifcond.length(); - extractLogic(line.substr(cursor),arguments); - if(arguments.size() >= 2){ - bool keep = arguments[2].compare(loaderPathName); - if(keep) buffer.push_back(line); - do{ - getline (infile,line); - if(keep) buffer.push_back(line); - } while ((pos=line.find(olkey::olendif)) == std::string::npos); - } - else - OLMsg::Error("Incorrect statement <%s> in <%s>", - line.c_str(), fileNameSave.c_str()); + size_t pos; + if( (pos=line.find(olkey::separator)) != std::string::npos){ + std::string name, action; + std::vector<std::string> args; + extract(line.substr(0,pos),name,action,args); + std::string host = OLMsg::GetOnelabString(name + "/HostName"); + std::string rhost=(args.size()>=2)?args[1]:""; + bool keep = rhost.compare(host); + if(keep) buffer.push_back(line); } } } + else + OLMsg::Error("The file <%s> cannot be opened",fileName.c_str()); infile.close(); - */ //save client command lines - std::ofstream outfile(fileNameSave.c_str()); - if (outfile.is_open()){ - // outfile << olkey::ifcond << "(" << olkey::getValue ; - // outfile << "(LoaderPathName) == "; - // outfile << loaderPathName << ")" << std::endl; + std::ofstream outfile(fileName.c_str()); + if(outfile.is_open()){ for(citer it = _clients.begin(); it != _clients.end(); it++){ outfile << (*it)->toChar(); } - //outfile << olkey::olendif << std::endl; - - /* for(std::vector<std::string>::const_iterator it = buffer.begin(); it != buffer.end(); it++){ outfile << (*it) << std::endl; } - */ } else - OLMsg::Error("The file <%s> cannot be opened",fileNameSave.c_str()); + OLMsg::Error("The file <%s> cannot be opened",fileName.c_str()); outfile.close(); } @@ -193,6 +187,48 @@ int extract(const std::string &in, std::string ¶mName, return enclosed(in.substr(cursor),arguments,pos); } +int extractLogic(const std::string &in, std::vector<std::string> &arguments){ + // syntax: ( argument[0], argument[1]\in{<,>,<=,>=,==,!=}, arguments[2]) + size_t pos, cursor; + arguments.resize(0); + cursor=0; + if ( (pos=in.find("(",cursor)) == std::string::npos ) + OLMsg::Error("Syntax error: <%s>",in.c_str()); + + unsigned int count=1; + pos++; // skips '(' + cursor=pos; + do{ + if(in[pos]=='(') count++; + if(in[pos]==')') count--; + if( (in[pos]=='<') || (in[pos]=='=') || (in[pos]=='>') || (in[pos]=='!') ){ + arguments.push_back(removeBlanks(in.substr(cursor,pos-cursor))); + if(count!=1) + OLMsg::Error("Syntax error: <%s>",in.c_str()); + cursor=pos; + if(in[pos+1]=='='){ + arguments.push_back(in.substr(cursor,2)); + pos++; + } + else{ + arguments.push_back(in.substr(cursor,1)); + } + cursor=pos+1; + } + pos++; + } while( count && (pos!=std::string::npos) ); + // count is 0 when the closing brace is found. + + if(count) + OLMsg::Error("Syntax error: mismatched parenthesis in <%s>",in.c_str()); + else + arguments.push_back(removeBlanks(in.substr(cursor,pos-1-cursor))); + + if((arguments.size()!=1) && (arguments.size()!=3)) + OLMsg::Error("Syntax error: <%s>",in.c_str()); + return arguments.size(); +} + std::string extractExpandPattern(const std::string& str){ size_t posa, posb; posa=str.find_first_of("\"\'<"); @@ -480,8 +516,8 @@ void localSolverClient::parse_sentence(std::string line) { if(!action.compare("number")) { double val; // syntax: paramName.number(val,path,help,range(optional)) - if((arguments.size()>1) && isPath(arguments[1])) - name.assign(arguments[1] + name); + if(arguments.size()>1) + name.assign(FixOLPath(arguments[1]) + name); _parameters.insert(name); OLMsg::recordFullName(name); get(numbers, name); @@ -511,8 +547,8 @@ void localSolverClient::parse_sentence(std::string line) { } else if(!action.compare("string")) { // syntax: paramName.string(val,path,help) - if((arguments.size()>1) && isPath(arguments[1])) - name.assign(arguments[1] + name); // append path + if(arguments.size()>1) + name.assign(FixOLPath(arguments[1]) + name); // append path _parameters.insert(name); OLMsg::recordFullName(name); get(strings, name); @@ -540,8 +576,8 @@ void localSolverClient::parse_sentence(std::string line) { OLMsg::Error("No value given for param <%s>",name.c_str()); else val=atof(arguments[0].c_str()); - if((arguments.size()>1) && isPath(arguments[1])) - name.assign(arguments[1] + name); + if(arguments.size()>1) + name.assign(FixOLPath(arguments[1]) + name); _parameters.insert(name); OLMsg::recordFullName(name); get(numbers, name); @@ -897,11 +933,12 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) { get(numbers,longName(arguments[0])); if (numbers.size()) condition = (bool) numbers[0].getValue(); - else - OLMsg::Error("Unknown parameter <%s> in <%s> statement", - arguments[0].c_str(),olkey::ifntrue.c_str()); + else{ + condition=false; + // OLMsg::Warning("Unknown parameter <%s> in <%s> statement", + // arguments[0].c_str(),olkey::ifntrue.c_str()); + } } - std::cout << "cond=" << condition << std::endl; if (!parse_ifstatement(infile,!condition)) OLMsg::Error("Misformed <%s> statement: <%s>", olkey::ifntrue.c_str(),arguments[0].c_str()); @@ -924,8 +961,8 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) { OLMsg::Error("Misformed <%s> statement: (%s)", olkey::include.c_str(),line.c_str()); else - OLMsg::Info("Parse file <%s> success=%d", arguments[0].c_str(), - parse_onefile(getWorkingDir() + arguments[0])); + OLMsg::Info("Parse file <%s> %s", arguments[0].c_str(), + parse_onefile(getWorkingDir() + arguments[0])?"done":"failed"); } else if ( (pos=line.find(olkey::message)) != std::string::npos) { // onelab.message @@ -1223,9 +1260,11 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile, get(numbers,longName(arguments[0])); if (numbers.size()) condition = (bool) numbers[0].getValue(); - else - OLMsg::Error("Unknown parameter <%s> in <%s> statement", - arguments[0].c_str(),olkey::ifntrue.c_str()); + else{ + condition=false; + // OLMsg::Error("Unknown parameter <%s> in <%s> statement", + // arguments[0].c_str(),olkey::ifntrue.c_str()); + } } if (!convert_ifstatement(infile,outfile,!condition)) OLMsg::Error("Misformed <%s> statement: %s", @@ -1354,73 +1393,106 @@ void MetaModel::client_sentence(const std::string &name, if(!action.compare("register")){ if(isTodo(REGISTER)){ - // syntax name.register([interf...|native]{,cmdl{host{,rdir}}}}) ; + std::string type="",cmdl="",host="",rdir=""; + // syntax name.register([interf...|native]{,cmdl}) ; if(!findClientByName(name)){ OLMsg::Info("Define client <%s>", name.c_str()); - std::string type="",cmdl="",host="",rdir=""; if(arguments.size()>=1) type.assign(resolveGetVal(arguments[0])); if(arguments.size()>=2) cmdl.assign(resolveGetVal(arguments[1])); - if(arguments.size()>=3) host.assign(resolveGetVal(arguments[2])); - if(arguments.size()>=4) rdir.assign(resolveGetVal(arguments[3])); - if(arguments.size()>=5) + if(arguments.size()>=3) OLMsg::Warning("Unused arguments for client <%s>", name.c_str()); + // if argument 'cmdl' is empty, + // 1. look on server for one remote host cmdl + // defined by a previous .remote() sentence + // 2. look in the .save file for a local host cmdl + // 3. create an empty parameter restore control to the GUI + + host = OLMsg::GetOnelabString(name + "/HostName"); + rdir = OLMsg::GetOnelabString(name + "/RemoteDir"); + if(cmdl.empty()) + cmdl = OLMsg::GetOnelabString(name + "/CommandLine"); + + if(cmdl.empty()) { + host="localhost"; + if(findCommandLine(name,host)) + cmdl = OLMsg::GetOnelabString(name + "/CommandLine"); + } if(cmdl.empty()) { - // if argument 'cmdl' is empty, look for one on the server - // (read beforehand from the file metamodel.ol.save) - // otherwise register with empty cmdl - // (this situation is dealt with later on) - cmdl=OLMsg::GetOnelabString(name + "/CommandLine"); - if(cmdl.empty()) { + if(OLMsg::hasGmsh){ onelab::string str; str.setName(name + "/CommandLine"); str.setKind("file"); - //str.setVisible(cmdl.empty()); str.setAttribute("Highlight","Ivory"); set(str); + OLMsg::Error("No commandline found for client <%s>", + name.c_str()); + } + else{ // asks the user in console mode + std::cout << "\nONELAB: Enter pathname of the executable file for <" << name << ">" << std::endl; + std::getline (std::cin,cmdl); + OLMsg::SetOnelabString(name + "/CommandLine",cmdl); } } - if(host.empty()) { - host=OLMsg::GetOnelabString(name + "/remoteHost"); - } - if(rdir.empty()) { - rdir=OLMsg::GetOnelabString(name + "/remoteWork"); - } - registerClient(name,type,cmdl,host,rdir); } else OLMsg::Error("Redefinition of client <%s>", name.c_str()); } } - else if(!action.compare("remote")){ + else if(!action.compare("remote") || !action.compare("hostname")){ if(isTodo(REGISTER)){ - if(arguments.size()>0) - OLMsg::SetOnelabString(name + "/remoteHost", arguments[0], false); - else{ - onelab::string str; - str.setName(name + "/remoteHost"); - str.setAttribute("Highlight","Ivory"); - set(str); + std::string host="",rdir=""; + if(arguments.size()>=1) host.assign(resolveGetVal(arguments[0])); + if(arguments.size()>=2) rdir.assign(resolveGetVal(arguments[1])); + if(arguments.size()>=3) + OLMsg::Warning("Unused arguments for client <%s>", name.c_str()); + + if(host.empty()){ + std::string in = OLMsg::GetOnelabString(name + "/HostName"); + if(in.size()){ + std::vector<std::string> split = SplitOLHostName(in); + host = split[0]; + rdir = split[1]; + OLMsg::SetOnelabString(name + "/HostName", host); + if(rdir.size()) + OLMsg::SetOnelabString(name + "/RemoteDir", rdir); + } } - if(arguments.size()>1) - OLMsg::SetOnelabString(name + "/remoteDir", arguments[1], false); - else{ - onelab::string str; - str.setName(name + "/remoteDir"); - str.setAttribute("Highlight","Ivory"); - set(str); + if(!findCommandLine(name,host)){ + if(OLMsg::hasGmsh){ + onelab::string str; + str.setName(name + "/HostName"); + str.setAttribute("Highlight","Ivory"); + set(str); + OLMsg::Error("No hostname found for remote client <%s>",name.c_str()); + } + else{ // asks the user in console mode + std::cout << "\nONELAB: Enter remote host for <" << name << "> (name@host:dir)" << std::endl; + std::string in; + std::getline (std::cin,in); + if(in.size()){ + std::vector<std::string> split = SplitOLHostName(in); + OLMsg::SetOnelabString(name + "/HostName", split[0]); + if(split[1].size()) + OLMsg::SetOnelabString(name + "/RemoteDir", split[1]); + } + } } } } - else if(!action.compare("commandLine")){ +/* else if(!action.compare("commandLine")){ if(isTodo(REGISTER)){ - if(arguments[0].size()) - OLMsg::SetOnelabString(name + "/CommandLine",arguments[0],false); + if(arguments[0].size() >= 1) + OLMsg::SetOnelabString(name + "/CommandLine", arguments[0], false); else OLMsg::Error("No pathname given for client <%s>", name.c_str()); + if(arguments[0].size() >= 2) + OLMsg::SetOnelabString(name + "/HostName", arguments[1], false); + if(arguments[0].size() >= 3) + OLMsg::SetOnelabString(name + "/RemoteDir",arguments[2], false); } - } + }*/ else if(!action.compare("workingSubdir")){ localSolverClient *c; if((c=findClientByName(name)))