diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp index fe88b7c4c706b009a3cdf7134fde36c229a40b58..ad2f9a165664e127677944dee60f4a5d985ac84c 100644 --- a/contrib/onelab/OnelabClients.cpp +++ b/contrib/onelab/OnelabClients.cpp @@ -297,7 +297,7 @@ bool localNetworkSolverClient::receiveMessage(){ bool localNetworkSolverClient::run() { - new_connection: + //new_connection: setPid(0); // Choose socket type (Unix or TCP/IP) @@ -345,8 +345,6 @@ bool localNetworkSolverClient::run() sock = -1; } - std::cout << "sock = " << sock << std::endl; - if(sock < 0){ //could not establish connection: aborting socketConnection->Shutdown(); delete socketConnection; @@ -369,7 +367,6 @@ bool localNetworkSolverClient::run() } else if(!getGmshServer()->NonBlockingWait(0.001, 0., sock)){ haveData = true; - std::cout << "Have data" << std::endl; } else{// an error occurred stop = true; @@ -384,10 +381,10 @@ bool localNetworkSolverClient::run() setGmshServer(0); OLMsg::StatusBar(2, true, "Done running '%s'", _name.c_str()); - if(command.empty()){ - OLMsg::Info("Client disconnected: starting new connection"); - goto new_connection; - } + // if(command.empty()){ + // OLMsg::Info("Client disconnected: starting new connection"); + // goto new_connection; + // } return true; } diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp index 50e47afb81a686b3b50d749f76ff0c4916d579c8..71d7450cfcd26062c533cb03110f95cf60cc21d2 100644 --- a/contrib/onelab/OnelabParser.cpp +++ b/contrib/onelab/OnelabParser.cpp @@ -1398,7 +1398,7 @@ void localSolverClient::convert_onefile(std::string fileName, std::ofstream &out infile.close(); } else - OLMsg::Error("The file %s cannot be opened",fileName.c_str()); + OLMsg::Error("The file <%s> cannot be opened",fileName.c_str()); } void localSolverClient::client_sentence(const std::string &name, diff --git a/contrib/onelab/python/OnelabClient.py b/contrib/onelab/python/OnelabClient.py index 771f165b8cc656020fe72f71e29d0fd1c80fbba2..a09fea29bb3e685e1fb8f1c189adabd604880582 100755 --- a/contrib/onelab/python/OnelabClient.py +++ b/contrib/onelab/python/OnelabClient.py @@ -106,7 +106,7 @@ class client : self._createSocket() self.socket.send(struct.pack('ii%is' %len(m), t, len(m), m)) - def _def_parameter(self, param) : + def _define_parameter(self, param) : if not self.socket : return self._send(self._GMSH_PARAMETER_QUERY, param.tochar()) @@ -116,66 +116,57 @@ class client : elif t == self._GMSH_PARAM_NOT_FOUND : self._send(self._GMSH_PARAMETER, param.tochar()) - def def_string(self, name, value, **param): + def setString(self, name, value, **param): param = _parameter('string', name=name, value=value, **param) - self._def_parameter(param) + self._define_parameter(param) return param.value - def def_number(self, name, value, **param): + def setNumber(self, name, value, **param): if "labels" in param : param["choices"] = param["labels"].keys() p = _parameter('number', name=name, value=value, **param) - self._def_parameter(p) + self._define_parameter(p) return p.value - def _get_parameter(self, param) : + def _get_parameter(self, param, warn_if_not_found=True) : if not self.socket : return self._send(self._GMSH_PARAMETER_QUERY, param.tochar()) (t, msg) = self._receive() if t == self._GMSH_PARAMETER : param.fromchar(msg) - elif t == self._GMSH_PARAM_NOT_FOUND : - print 'Unknown parameter %s' %(name) + elif t == self._GMSH_PARAM_NOT_FOUND and warn_if_not_found : + print 'Unknown parameter %s' %(param.name) - def get_number(self, name): + def getNumber(self, name, warn_if_not_found=True): param = _parameter('number', name=name, value=0) - self._get_parameter(param) + self._get_parameter(param, warn_if_not_found) return param.value - def get_string(self, name): + def getString(self, name, warn_if_not_found=True): param = _parameter('string', name=name, value='void') - self._get_parameter(param) + self._get_parameter(param, warn_if_not_found) return param.value - def sub_client(self, name, command): - print 'Defining the subclient ' + name - msg = [name, command] - if not self.socket : + def showGeometry(self, filename) : + if not self.socket or not filename : return - self._send(self._GMSH_CONNECT, '\0'.join(msg)) - ## (t, msg) = self._receive() - ## print ("python receive : ", t, msg) - ## if t == self._GMSH_CONNECT and msg : - ## print "The client %s is now connected" %(msg) - ## print "python launch : "+ command + " -onelab " + name + " " + msg - ## os.system(command + " -onelab " + name + " " + msg) - - def wait_on_subclient(self, name): - if not self.socket : + if self.getString('Gmsh/MergedGeo', False) == filename : return - (t, msg) = self._receive() - if t == self._GMSH_OPTION_1 : - print 'Client <%s> done, proceeding with the script...' %(name) - - def merge_file(self, filename) : + else : + self.setString('Gmsh/MergedGeo', filename) + if filename[0] != '/' : + filename = os.getcwd() + "/" + filename + self._send(self._GMSH_MERGE_FILE, filename) + + def mergeFile(self, filename) : if not self.socket : return if filename and filename[0] != '/' : filename = os.getcwd() + "/" + filename; - self._send(self._GMSH_PARSE_STRING, 'Merge "'+filename+'";') + self._send(self._GMSH_PARSE_STRING, 'Merge "' + filename + '";') - def convert_olfile(self, filename) : + def preProcess(self, filename) : if not self.socket : return if filename and filename[0] != '/' : @@ -191,22 +182,47 @@ class client : self.socket.connect(addr) #self.socket.setblocking(1) #self.socket.settimeout(5.0) - + + def _wait_on_subclients(self): + if not self.socket : + return + while self.NumSubClients > 0: + (t, msg) = self._receive() + if t == self._GMSH_STOP : + self.NumSubClients -= 1 + + def run(self, name, command): + msg = [name, command] + if not self.socket : + return + self._send(self._GMSH_CONNECT, '\0'.join(msg)) + self.NumSubClients +=1 + self._wait_on_subclients() + def __init__(self): self.socket = None self.name = "" self.addr = "" + self.NumSubClients = 0 for i, v in enumerate(sys.argv) : if v == '-onelab': self.name = sys.argv[i + 1] self.addr = sys.argv[i + 2] self._createSocket() self._send(self._GMSH_START, str(os.getpid())) - self.action = self.get_string('python/Action') + self.action = self.getString('python/Action') if self.action == "initialize": exit(0) def __del__(self) : if self.socket : + self._wait_on_subclients() self._send(self._GMSH_STOP, 'Goodbye!') self.socket.close() - print 'Destructor called for %s' %(self.name) + +## wait_on_clients +## a la fin de sub_client +## envoyer GMSH_STOP seulement si les sous-clients sont termines. +## et modif dans onelabGroup run pour interdire au main +## de fermer les sockets de clients non-termines. + + diff --git a/contrib/onelab/python/sub.py b/contrib/onelab/python/sub.py index c432a9231916ce7e1e2c1a393c3d103baf3cdbf5..b2830368bc0f464d04fefd512a0fc81ac733e54e 100755 --- a/contrib/onelab/python/sub.py +++ b/contrib/onelab/python/sub.py @@ -1,14 +1,11 @@ #!/usr/bin/env python #coding=utf-8 +import OnelabClient as onelab -import OnelabClient +OL = onelab.client() -oc = OnelabClient.client() - -A = oc.get_number('A') -B = oc.def_number('Group/B', 20) +A = OL.getNumber('A') +B = OL.setNumber('Group/B', 20) print 'A= %f B = %f' %(A, B) - -print('Action=%s' %(oc.get_string('python/Action'))) diff --git a/contrib/onelab/python/test.py b/contrib/onelab/python/test.py index 5a17ae96b180ef166a2a9ac1cbff0b3fd95171f0..7bcce603875e2987b4b91e1950185d3ed0e0977e 100755 --- a/contrib/onelab/python/test.py +++ b/contrib/onelab/python/test.py @@ -1,38 +1,34 @@ #!/usr/bin/env python #coding=utf-8 -import OnelabClient +import OnelabClient as onelab -oc = OnelabClient.client() +modelName = 'coin' + +OL = onelab.client() +print('\nStarting METAMODEL - Action = %s' %(OL.getString('python/Action'))) #name and default value are required -A = oc.def_number('A', 10) +A = OL.setNumber('A', 10) #other attributes are optionals #B = oc.def_number('Group/B', 0, min = -10, max = 10, step = 1) +OL.showGeometry(modelName + '.geo') -modelName = 'coin' - -oc.merge_file(modelName + '.geo') - -print('Action=%s' %(oc.get_string('python/Action'))) +OL.run('gmsh', 'gmsh ' + modelName + '.geo -2') -oc.sub_client('gmsh', 'gmsh ' + modelName + '.geo -2') +OL.mergeFile(modelName + '.msh') -oc.merge_file(modelName + '.msh') +OL.run('subclient', 'sub.py') -oc.sub_client('subclient', 'sub.py') -print 'script is waiting until subclient is done' -oc.wait_on_subclient('subclient'); +C = OL.setNumber('Group/C', 2, choices = [0, 1, 2, 3], attributes={'Highlight':'Pink'}) +D = OL.setNumber('Group/D', 2, labels = {0:'zero', 1:'un', 2:'deux', 3:'trois'}, attributes={'Highlight':'Blue'}) -C = oc.def_number('Group/C', 2, choices = [0, 1, 2, 3], attributes={'Highlight':'Pink'}) -D = oc.def_number('Group/D', 2, labels = {0:'zero', 1:'un', 2:'deux', 3:'trois'}, attributes={'Highlight':'Blue'}) -#utf-8 are allowed everywhere (should be prefixed by 'u' in python 2, -#not required in python 3) -#Omega = oc.get_string(u'Ω', u'∫(∂φ/∂α)³dx', help=u'ask someone@universe.org', +#utf-8 are allowed everywhere +#(should be prefixed by 'u' in python 2, not required in python 3) +#Omega = OL.getString(u'Ω', u'∫(∂φ/∂α)³dx', help=u'ask someone@universe.org', #choices = ['oui', 'non', u'peut-être']) -oc.convert_olfile(modelName + '.txt') - +OL.preProcess(modelName + '.txt.ol') -if oc.action != 'compute' : +if OL.action != 'compute' : exit(0)