diff --git a/Common/OS.cpp b/Common/OS.cpp index 853e9f42586dda51ffd9efbe30b82a2a45655d0d..296e787e69ed0dc86dfe39a65929040408e02904 100644 --- a/Common/OS.cpp +++ b/Common/OS.cpp @@ -228,3 +228,21 @@ int SystemCall(const std::string &command, bool blocking) return system(cmd.c_str()); #endif } + +#ifndef MAXPATHLEN +#define MAXPATHLEN 1024 +#endif + +std::string getCurrentWorkdir(){ + char path[MAXPATHLEN]; + if(!getcwd(path, MAXPATHLEN)) return ""; + std::string str = path; + //match the convention of SplitFileName that delivers directory path + //endig with a directory separator +#if defined(WIN32) + str.append("\\"); +#else + str.append("/"); +#endif + return str; +} diff --git a/Common/OS.h b/Common/OS.h index 0bb1cf2c57419dff88fd4aa7a2988cb46bc757b7..dacf126e04fb5c9e92883902b931a2d38c448140 100644 --- a/Common/OS.h +++ b/Common/OS.h @@ -21,5 +21,6 @@ int StatFile(const std::string &fileName); int KillProcess(int pid); int CreateDirectory(const std::string &dirName); int SystemCall(const std::string &command, bool blocking=false); +std::string getCurrentWorkdir(); #endif diff --git a/Fltk/onelabWindow.cpp b/Fltk/onelabWindow.cpp index ea91af7d428a50588aaca43de5133dd2e2f1aab2..93f33ce9082ac7b5b4df511b5fab44216fadaa7a 100644 --- a/Fltk/onelabWindow.cpp +++ b/Fltk/onelabWindow.cpp @@ -1416,8 +1416,9 @@ int metamodel_cb(const std::string &name, const std::string &action) onelab::number n("IsMetamodel", 1.); n.setVisible(false); onelab::server::instance()->set(n); - std::vector<std::string> split = SplitFileName(name); - onelab::string s1("Arguments/WorkingDir", split[0]); + std::vector<std::string> split = SplitFileName(name); + onelab::string s1("Arguments/WorkingDir", + split[0].size()?split[0]:getCurrentWorkdir()); s1.setVisible(false); onelab::server::instance()->set(s1); onelab::string s2("Arguments/FileName", split[1]); diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp index eb201320637e2164148e3f62d908488fa9ca429e..4bfc3241f9cb41f5743c7fa97c9987aac858e676 100644 --- a/contrib/onelab/OnelabClients.cpp +++ b/contrib/onelab/OnelabClients.cpp @@ -410,13 +410,25 @@ bool localSolverClient::checkCommandLine(){ getCommandLine().c_str(), getName().c_str()); if(!isActive()) return true; - if(!getCommandLine().empty()){ + if(getCommandLine().empty()){ + if(OLMsg::hasGmsh) { + OLMsg::Error("No command line for client <%s>", getName().c_str()); + return false; // restores control to gmsh + } + else{ // asks the user in console mode + std::cout << "\nONELAB: Enter pathname of the executable file for <" << getName() << ">" << std::endl; + std::string cmdl; + std::getline (std::cin,cmdl); + setCommandLine(cmdl); + return checkCommandLine(); + } + } + else{ if(isNative()){ setAction("initialize"); - if(!run()){ // initializes native clients + if(!run()){ // initializes native clients, false otherwise OLMsg::Error("Invalid commandline <%s> for client <%s>", FixExecPath(getCommandLine()).c_str(), getName().c_str()); - //setCommandLine(""); return false; } } @@ -425,7 +437,7 @@ bool localSolverClient::checkCommandLine(){ char cbuf [1024]; FILE *fp; commandLine.assign(FixExecPath(getCommandLine())); - cmd.assign("which "+commandLine); + cmd.assign(whichCmd + commandLine); fp = POPEN(cmd.c_str(), "r"); if(fgets(cbuf, 1024, fp) == NULL){ OLMsg::Error("The executable <%s> does not exist", @@ -435,20 +447,6 @@ bool localSolverClient::checkCommandLine(){ } OLMsg::Info("The executable <%s> exists", commandLine.c_str()); PCLOSE(fp); - return true; - } - } - else{ - OLMsg::Error("No commandline for client <%s>", getName().c_str()); - if(OLMsg::hasGmsh) { - return false; // exits metamodel and restores control to gmsh - } - else{ // asks the user in console mode - std::cout << "\nONELAB:Enter the command line (with path) of the executable file of <" << getName() << ">" << std::endl; - std::string cmdl; - std::getline (std::cin,cmdl); - setCommandLine(cmdl); - return cmdl.size(); } } return true; @@ -462,11 +460,7 @@ bool localSolverClient::buildRmCommand(std::string &cmd){ cmd.append("cd " + getWorkingDir() + cmdSep); if(getList("OutputFiles",choices)){ -#if defined(WIN32) - cmd.append("del "); -#else - cmd.append("rm -rf "); -#endif + cmd.append(removeCmd); // defined in OnelabClients.h if(choices.size()){ for(unsigned int i = 0; i < choices.size(); i++) cmd.append(choices[i]+" "); @@ -635,16 +629,6 @@ bool remoteClient::syncOutputFile(const std::string &wdir, const std::string &fi // client METAMODEL - -bool MetaModel::checkCommandLines(){ - bool allDefined=true; - for(citer it = _clients.begin(); it != _clients.end(); it++){ - allDefined = allDefined && (*it)->checkCommandLine(); - } - saveCommandLines(genericNameFromArgs); - return allDefined; -} - void MetaModel::construct() { OLMsg::Info("Metamodel now CONSTRUCTING"); @@ -764,7 +748,7 @@ void InterfacedClient::compute(){ std::vector<std::string> choices; analyze(); - if(OLMsg::GetErrorNum()) return; + if(OLMsg::GetErrorCount()) return; OLMsg::Info("Computes <%s>", getName().c_str()); setAction("compute"); @@ -810,7 +794,7 @@ void NativeClient::compute() { std::vector<std::string> choices; analyze(); - if(OLMsg::GetErrorNum()) return; + if(OLMsg::GetErrorCount()) return; OLMsg::Info("Computes <%s>", getName().c_str()); setAction("compute"); @@ -888,7 +872,7 @@ void EncapsulatedClient::compute(){ std::vector<std::string> choices; analyze(); - if(OLMsg::GetErrorNum()) return; + if(OLMsg::GetErrorCount()) return; OLMsg::Info("Computes <%s>", getName().c_str()); setAction("compute"); @@ -936,7 +920,7 @@ void RemoteInterfacedClient::compute(){ std::vector<std::string> choices; analyze(); - if(OLMsg::GetErrorNum()) return; + if(OLMsg::GetErrorCount()) return; OLMsg::Info("Computes <%s>", getName().c_str()); setAction("compute"); @@ -1001,7 +985,7 @@ void RemoteNativeClient::compute(){ std::vector<std::string> choices; analyze(); - if(OLMsg::GetErrorNum()) return; + if(OLMsg::GetErrorCount()) return; OLMsg::Info("Computes <%s> changed=%d", getName().c_str()); setAction("compute"); @@ -1039,7 +1023,7 @@ void RemoteEncapsulatedClient::compute(){ std::vector<std::string> choices; analyze(); - if(OLMsg::GetErrorNum()) return; + if(OLMsg::GetErrorCount()) return; OLMsg::Info("Computes <%s> changed=%d", getName().c_str()); setAction("compute"); @@ -1174,17 +1158,17 @@ std::string getUserHomedir(){ #include <direct.h> #endif -#ifndef MAXPATHLEN -#define MAXPATHLEN 1024 -#endif - +// #ifndef MAXPATHLEN +// #define MAXPATHLEN 1024 +// #endif -std::string getCurrentWorkdir(){ - char path[MAXPATHLEN]; - if(!getcwd(path, MAXPATHLEN)) return ""; - std::string str = path; - return str; -} +// std::string getCurrentWorkdir(){ +// char path[MAXPATHLEN]; +// if(!getcwd(path, MAXPATHLEN)) return ""; +// std::string str = path; +// str.append(dirSep); +// return str; +// } std::string sanitize(const std::string &in) { diff --git a/contrib/onelab/OnelabClients.h b/contrib/onelab/OnelabClients.h index 435192230bc779824021e5e31ab952415cb64e94..0679361d8a596679b5898b8d755b4a1908efb2cb 100644 --- a/contrib/onelab/OnelabClients.h +++ b/contrib/onelab/OnelabClients.h @@ -23,9 +23,13 @@ enum parseMode {REGISTER, ANALYZE, COMPUTE, EXIT}; #if defined(WIN32) static std::string dirSep("\\"); static std::string cmdSep(" & "); +static std::string removeCmd("del "); +static std::string whichCmd("where "); #else static std::string dirSep("/"); static std::string cmdSep(" ; "); +static std::string removeCmd("rm -rf "); +static std::string whichCmd("which "); #endif // TOOLS diff --git a/contrib/onelab/OnelabMessage.cpp b/contrib/onelab/OnelabMessage.cpp index 6d028085b5021a6e82d4c70a1d8e41334d042d02..0818134d8d0c9a96ebc7af8bfdc14e847a2a3625 100644 --- a/contrib/onelab/OnelabMessage.cpp +++ b/contrib/onelab/OnelabMessage.cpp @@ -50,14 +50,6 @@ static int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) #define vsnprintf _vsnprintf #endif -int OLMsg::GetErrorNum(){ - return _errorCount; -} - -void OLMsg::ResetErrorNum(){ - _errorCount=0; -} - void OLMsg::Init(int argc, char **argv) { time_t now; diff --git a/contrib/onelab/OnelabMessage.h b/contrib/onelab/OnelabMessage.h index ffd187a8b16c6ab3b493b06b75ca4c1f0aca3559..9ce6245fd65db059b486ea3e18f0cde0c2f7ed92 100644 --- a/contrib/onelab/OnelabMessage.h +++ b/contrib/onelab/OnelabMessage.h @@ -73,8 +73,6 @@ class OLMsg { /* static int GetVerbosity(){ return _verbosity; } */ /* static std::string GetLaunchDate(){ return _launchDate; } */ /* static std::string GetCommandLineArgs(){ return _commandLine; } */ - static int GetErrorNum(); - static void ResetErrorNum(); static void Fatal(const char *fmt, ...); static void Error(const char *fmt, ...); static void Warning(const char *fmt, ...); @@ -89,8 +87,11 @@ class OLMsg { static void ResetProgressMeter(){ if(!_commRank) _progressMeterCurrent = 0; } static double &Timer(std::string str){ return _timers[str]; } static void PrintTimers(); + static void ResetErrorCounter(){ _warningCount = 0; _errorCount = 0; } static void PrintErrorCounter(const char *title); + static int GetErrorCount(){ return _errorCount; } + static double GetValue(const char *text, double defaultval); static std::string GetString(const char *text, std::string defaultval); static int GetAnswer(const char *question, int defaultval, const char *zero, diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp index 0618a0a7a012ef92f795f003431b0dffc8a027b7..b7c1f8fb20303b1c1c253539506506a49027b909 100644 --- a/contrib/onelab/OnelabParser.cpp +++ b/contrib/onelab/OnelabParser.cpp @@ -71,6 +71,7 @@ void MetaModel::saveCommandLines(const std::string fileName){ std::vector<std::string> arguments, buffer; size_t cursor, pos; 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::ifstream infile(fileNameSave.c_str()); @@ -87,7 +88,7 @@ void MetaModel::saveCommandLines(const std::string fileName){ do{ getline (infile,line); if(keep) buffer.push_back(line); - } while ((pos=line.find(olkey::olendif)) != std::string::npos); + } while ((pos=line.find(olkey::olendif)) == std::string::npos); } else OLMsg::Error("Incorrect statement <%s> in <%s>", @@ -1441,7 +1442,7 @@ void MetaModel::client_sentence(const std::string &name, set(strings[0]); } localSolverClient *c; - if(!OLMsg::GetErrorNum()) + if(!OLMsg::GetErrorCount()) if((c=findClientByName(name))) if(c->checkCommandLine()) c->analyze(); @@ -1458,7 +1459,7 @@ void MetaModel::client_sentence(const std::string &name, bool changed = onelab::server::instance()->getChanged(c->getName()); bool started = isStarted(changed); - std::cout << c->getName() << " active=" << c->getActive() << " changed=" << changed << " started=" << started << " errors=" << OLMsg::GetErrorNum() << std::endl; + std::cout << c->getName() << " active=" << c->getActive() << " changed=" << changed << " started=" << started << " errors=" << OLMsg::GetErrorCount() << std::endl; if(started) c->compute(); } } @@ -1541,7 +1542,7 @@ void MetaModel::client_sentence(const std::string &name, } localSolverClient *c; if((c=findClientByName(name))) { - if(isTodo(REGISTER) && !OLMsg::GetErrorNum()) + if(isTodo(REGISTER) && !OLMsg::GetErrorCount()) if(onelab::server::instance()->getChanged(c->getName())){ c->compute(); c->GmshMerge(choices); diff --git a/contrib/onelab/loader.cpp b/contrib/onelab/loader.cpp index 6ced543660898c91a466e49571e07c4366229809..c5fea65c0b62b00ad89a27baae2979fd7dee0f6d 100644 --- a/contrib/onelab/loader.cpp +++ b/contrib/onelab/loader.cpp @@ -272,6 +272,8 @@ int main(int argc, char *argv[]){ caseName=argv[i]; modelName.assign(SplitFileName(caseName)[1]); workingDir.assign(SplitFileName(caseName)[0]); + if(workingDir.empty()) + workingDir.assign(getCurrentWorkdir()); i++; } } diff --git a/contrib/onelab/metamodel.cpp b/contrib/onelab/metamodel.cpp index da73a4f2b4794a349ffe5acf8598430c49140545..7777b50eb0ecd874f726315ad2cd16f43e0ddb26 100644 --- a/contrib/onelab/metamodel.cpp +++ b/contrib/onelab/metamodel.cpp @@ -21,7 +21,7 @@ int metamodel(const std::string &action){ OLMsg::Info("Start metamodel"); OLMsg::hasGmsh = OLMsg::GetOnelabNumber("IsMetamodel"); - OLMsg::ResetErrorNum(); + OLMsg::ResetErrorCounter(); parseMode todo; // if(action == "initialize") @@ -50,7 +50,7 @@ int metamodel(const std::string &action){ freopen(mystderr.c_str(),"w",stderr); } - if(OLMsg::GetErrorNum()) myModel->setTodo(EXIT); + if(OLMsg::GetErrorCount()) myModel->setTodo(EXIT); if( myModel->isTodo(ANALYZE)){ myModel->analyze(); @@ -64,7 +64,7 @@ int metamodel(const std::string &action){ OLMsg::Error("Main: Unknown Action <%d>", todo); delete myModel; - if((errors=OLMsg::GetErrorNum())){ + if((errors=OLMsg::GetErrorCount())){ OLMsg::Error("Leave metamodel - %d errors",errors); OLMsg::Info("=============================================="); return 0; diff --git a/contrib/onelab/myOS.cpp b/contrib/onelab/myOS.cpp index 7bbbcdb3a32977269699332962249cb7e7c56a55..ea4b44fa716e58992d3c8366dd8c8fa9b77b1a79 100644 --- a/contrib/onelab/myOS.cpp +++ b/contrib/onelab/myOS.cpp @@ -214,3 +214,21 @@ int SystemCall(const std::string &command, bool blocking) return system(cmd.c_str()); #endif } + +#ifndef MAXPATHLEN +#define MAXPATHLEN 1024 +#endif + +std::string getCurrentWorkdir(){ + char path[MAXPATHLEN]; + if(!getcwd(path, MAXPATHLEN)) return ""; + std::string str = path; + //match the convention of SplitFileName that delivers directory path + //endig with a directory separator +#if defined(WIN32) + str.append("\\"); +#else + str.append("/"); +#endif + return str; +} diff --git a/contrib/onelab/myOS.h b/contrib/onelab/myOS.h index 6a17031a58deee69d69386fda8017645b29bfb43..54665fe40d860519334218160f6a64f10d0d115b 100644 --- a/contrib/onelab/myOS.h +++ b/contrib/onelab/myOS.h @@ -20,5 +20,6 @@ int UnlinkFile(const std::string &fileName); int StatFile(const std::string &fileName); int KillProcess(int pid); int SystemCall(const std::string &command, bool blocking=false); +std::string getCurrentWorkdir(); #endif