From 36fe82b712aa66de798e4bc6ebd259fe5c9b9e4b Mon Sep 17 00:00:00 2001 From: Francois Henrotte <francois.henrotte@ulg.ac.be> Date: Wed, 12 Nov 2014 11:34:38 +0000 Subject: [PATCH] extend load and save database functionalities in py metamodels --- Fltk/onelabGroup.cpp | 26 +++++++++++++++++++------- contrib/onelab/OnelabParser.cpp | 17 ++--------------- contrib/onelab/python/onelab.py | 31 +++++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp index 8fd179c4ff..23288281a2 100644 --- a/Fltk/onelabGroup.cpp +++ b/Fltk/onelabGroup.cpp @@ -400,14 +400,16 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) #if defined(HAVE_ONELAB_METAMODEL) std::string::size_type first = 0; std::string name = onelab::parameter::getNextToken(message, first); - std::string fileName = onelab::parameter::getNextToken(message, first); - std::vector<std::string> split = SplitOLFileName(fileName); + 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()); - localSolverClient *c = new InterfacedClient(name,"",""); + + 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(fileName, outfile); + c->convert_onefile(fullName, outfile); } else Msg::Error("The file <%s> cannot be opened",ofileName.c_str()); @@ -661,7 +663,7 @@ static void archiveOutputFiles(const std::string &fileName) std::vector<onelab::string> ps; onelab::server::instance()->get(ps,"0Metamodel/9Tag"); if(ps.size()) - stamp.assign(ps[0].getValue()+timeStamp()); + stamp.assign(timeStamp() + ps[0].getValue()); else stamp.assign(timeStamp()); @@ -845,8 +847,17 @@ void onelab_cb(Fl_Widget *w, void *data) onelab::server::instance()->get(ps,"0Metamodel/9Tag"); if(ps.size()){ fileName.assign("onelab" + ps[0].getValue() + ".db"); - ps[0].setValue(""); - onelab::server::instance()->set(ps[0]); + //ps[0].setValue(""); + //onelab::server::instance()->set(ps[0]); + } + + // switch to "run" mode" + std::vector<onelab::number> pn; + onelab::server::instance()->get(pn,"0Metamodel/9Use restored solution"); + if(pn.size()){ + pn[0].setValue(0); + pn[0].setVisible(1); + onelab::server::instance()->set(pn[0]); } std::string s; @@ -875,6 +886,7 @@ void onelab_cb(Fl_Widget *w, void *data) onelab::server::instance()->get(pn,"0Metamodel/9Use restored solution"); if(pn.size()){ pn[0].setValue(1); + pn[0].setVisible(1); onelab::server::instance()->set(pn[0]); } action = "check"; diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp index 24159fd857..cb57202aa0 100644 --- a/contrib/onelab/OnelabParser.cpp +++ b/contrib/onelab/OnelabParser.cpp @@ -4,7 +4,6 @@ #include "OnelabClients.h" - // reserved keywords for the onelab parser namespace olkey{ @@ -354,8 +353,8 @@ std::string localSolverClient::resolveGetVal(std::string line) { else if(!action.compare("expand")) { std::string pattern; pattern.assign(extractExpandPattern(args[0])); - OLMsg::Info("Expand parameter <%s> with pattern <%s>", - paramName.c_str(),pattern.c_str()); + // OLMsg::Info("Expand parameter <%s> with pattern <%s>", + // paramName.c_str(),pattern.c_str()); buff.assign(1,pattern[0]); for(std::vector<double>::iterator it = choices.begin(); it != choices.end(); it++){ @@ -1559,18 +1558,6 @@ void MetaModel::client_sentence(const std::string &name, } } } -/* else if(!action.compare("commandLine")){ - if(isTodo(REGISTER)){ - 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))) diff --git a/contrib/onelab/python/onelab.py b/contrib/onelab/python/onelab.py index 6bed104054..0e7ea24744 100755 --- a/contrib/onelab/python/onelab.py +++ b/contrib/onelab/python/onelab.py @@ -36,8 +36,8 @@ def file_exist(filename): return True except IOError: return False - -def path(ref,inp=''): + +def path(ref, inp=''): # ref is reference directory name # inp is an optional file or directory name dirname = os.path.dirname(ref) @@ -47,12 +47,29 @@ def path(ref,inp=''): else : return '.' if inp[0] == '/' or inp[0] == '\\' or (len(inp) > 2 and inp[1] == '\:'): - return inp # do nothing, inp is an absolute path + return inp # do nothing, inp is an absolute path if dirname: return dirname + os.sep + inp # append inp to the path of the reference file else: return inp +class pth: + def path(self, ref, inp=''): + p = path(ref, inp='') + if not os.path.exists(): + print('The path %s does not exist' %(p)) + self.errors += 1 + return p + + def check_file(self, filename, workdir): + if not file_exist(workdir + os.sep + filename): + print('The file %s does not exist in %s' %(filename, workdir)) + self.errors += 1 + + def __init__(self) : + self.errors = 0 + + class _parameter() : _membersbase = [ ('name', 'string'), ('label', 'string', ''), ('help', 'string', ''), @@ -311,7 +328,7 @@ class client : if not self.socket or not filename : return self._send(self._GMSH_MERGE_FILE, filename) - + def openProject(self, filename) : if not self.socket or not filename : return @@ -500,8 +517,10 @@ class client : def outputFiles(self, list) : if list : - self.setString(self.name+'/9Output files', value=list[0], - choices=list, visible=0) + self.setString('0Metamodel/9Output files', value=list[0], + choices=list, visible=1) +# self.setString(self.name+'/9Output files', value=list[0], +# choices=list, visible=1) # tool to extract the (i, j)th element in an array file from rlcompleter import readline -- GitLab