def resume_cube(self): """resume_cube() -> self : Resume the last cube produced by the user. :returns: self or None :rtype: Client or None :raises: RuntimeError """ if self.username is None or self.password is None or self.server is None or self.port is None: raise RuntimeError('one or more login parameters are None') query = 'operator=oph_get_config;key=OPH_DATACUBE;' self.last_request = query try: self.last_response, self.last_jobid, newsession, return_value, error = _ophsubmit.submit( self.username, self.password, self.server, self.port, query) if return_value: raise RuntimeError(error) response = self.deserialize_response() if response is not None: for response_i in response['response']: if response_i['objkey'] == 'get_config': self.cube = response_i['objcontent'][0]['rowvalues'][ 0][1] break except Exception as e: print(get_linenumber(), "Something went wrong in resuming last cube:", e) return None return self
def resume_cube(self): """resume_cube() -> self : Resume the last cube produced by the user. :returns: self or None :rtype: Client or None :raises: RuntimeError """ if self.username is None or self.password is None or self.server is None or self.port is None: raise RuntimeError('one or more login parameters are None') query = 'operator=oph_get_config;key=OPH_DATACUBE;' self.last_request = query try: self.last_response, self.last_jobid, newsession, return_value, error = _ophsubmit.submit(self.username, self.password, self.server, self.port, query) if return_value: raise RuntimeError(error) response = self.deserialize_response() if response is not None: for response_i in response['response']: if response_i['objkey'] == 'get_config': self.cube = response_i['objcontent'][0]['rowvalues'][0][1] break except Exception as e: print(get_linenumber(),"Something went wrong in resuming last cube:", e) return None return self
def submit(self, query): """submit(query) -> self : Submit a query like 'operator=myoperator;param1=value1;' or 'myoperator param1=value1;' to the Ophidia server according to all login parameters of the Client and its state. :param query: query like 'operator=myoperator;param1=value1;' or 'myoperator param1=value1;' :type query: str :returns: self or None :rtype: Client or None :raises: RuntimeError """ if query is None: raise RuntimeError('query is not present') if self.username is None or self.password is None or self.server is None or self.port is None: raise RuntimeError('one or more login parameters are None') # Check if the query contains only the oph operator r = query.split() if len(r) != 1: if not query.endswith(';'): query = query.rstrip() query += ';' else: query += ' ' if self.session and 'sessionid' not in query: query += 'sessionid=' + self.session + ';' if self.cwd and 'cwd' not in query: query += 'cwd=' + self.cwd + ';' if self.cube and 'cube' not in query: query += 'cube=' + self.cube + ';' if self.exec_mode and 'exec_mode' not in query: query += 'exec_mode=' + self.exec_mode + ';' if self.ncores and 'ncores' not in query: query += 'ncores=' + str(self.ncores) + ';' self.last_request = query try: self.last_response, self.last_jobid, newsession, return_value, error = _ophsubmit.submit(self.username, self.password, self.server, self.port, query) if return_value: raise RuntimeError(error) if newsession is not None: if len(newsession) == 0: self.session = None else: self.session = newsession self.cwd = '/' response = self.deserialize_response() if response is not None: for response_i in response['response']: if response_i['objclass'] == 'text': if response_i['objcontent'][0]['title'] == 'Output Cube': self.cube = response_i['objcontent'][0]['message'] break for response_i in response['response']: if response_i['objclass'] == 'text': if response_i['objcontent'][0]['title'] == 'Current Working Directory': self.cwd = response_i['objcontent'][0]['message'] break except Exception as e: print(get_linenumber(),"Something went wrong in submitting the request:", e) return None return self
def wsubmit(self, workflow, *params): """wsubmit(workflow,*params) -> self : Submit an entire workflow passing a JSON string or the path of a JSON file and an optional series of parameters that will replace $1, $2 etc. in the workflow. The workflow will be validated against the Ophidia Workflow JSON Schema. :param workflow: JSON string or path of a JSON file containing an Ophidia workflow :type workflow: str :param params: list of positional parameters that will replace $1, $2 etc. in the workflow :type params: str :returns: self or None :rtype: Client or None :raises: RuntimeError """ if workflow is None: raise RuntimeError('workflow is not present') if self.username is None or self.password is None or self.server is None or self.port is None: raise RuntimeError('one or more login parameters are None') request = None import os.path import re if os.path.isfile(workflow): try: file = open(workflow, 'r') buffer = file.read() file.close() for index, param in enumerate(params, start=1): buffer = buffer.replace('${' + str(index) + '}', str(param)) buffer = re.sub('(\$' + str(index) + ')([^0-9]|$)', str(param) + '\g<2>', buffer) request = json.loads(buffer) except Exception as e: print( get_linenumber(), "Something went wrong in reading and/or parsing the file:", e) return None else: try: buffer = workflow for index, param in enumerate(params, start=1): buffer = buffer.replace('${' + str(index) + '}', str(param)) buffer = re.sub('(\$' + str(index) + ')([^0-9]|$)', str(param) + '\g<2>', buffer) request = json.loads(buffer) except Exception as e: print(get_linenumber(), "Something went wrong in parsing the string:", e) return None del os.path del re if self.session and 'sessionid' not in request: request['sessionid'] = self.session if self.cwd and 'cwd' not in request: request['cwd'] = self.cwd if self.cube and 'cube' not in request: request['cube'] = self.cube if self.exec_mode and 'exec_mode' not in request: request['exec_mode'] = self.exec_mode if self.ncores and 'ncores' not in request: request['ncores'] = str(self.ncores) self.last_request = json.dumps(request) try: if not self.wisvalid(self.last_request): print("The workflow is not valid") return None self.last_response, self.last_jobid, newsession, return_value, error = _ophsubmit.submit( self.username, self.password, self.server, self.port, self.last_request) if return_value: raise RuntimeError(error) if newsession is not None: if len(newsession) == 0: self.session = None else: self.session = newsession self.cwd = '/' response = self.deserialize_response() if response is not None: for response_i in response['response']: if response_i['objclass'] == 'text': if response_i['objcontent'][0][ 'title'] == 'Output Cube': self.cube = response_i['objcontent'][0]['message'] break for response_i in response['response']: if response_i['objclass'] == 'text': if response_i['objcontent'][0][ 'title'] == 'Current Working Directory': self.cwd = response_i['objcontent'][0]['message'] break except Exception as e: print(get_linenumber(), "Something went wrong in submitting the request:", e) return None return self
def submit(self, query): """submit(query) -> self : Submit a query like 'operator=myoperator;param1=value1;' or 'myoperator param1=value1;' to the Ophidia server according to all login parameters of the Client and its state. :param query: query like 'operator=myoperator;param1=value1;' or 'myoperator param1=value1;' :type query: str :returns: self or None :rtype: Client or None :raises: RuntimeError """ if query is None: raise RuntimeError('query is not present') if self.username is None or self.password is None or self.server is None or self.port is None: raise RuntimeError('one or more login parameters are None') # Check if the query contains only the oph operator r = query.split() if len(r) != 1: if not query.endswith(';'): query = query.rstrip() query += ';' else: query += ' ' if self.session and 'sessionid' not in query: query += 'sessionid=' + self.session + ';' if self.cwd and 'cwd' not in query: query += 'cwd=' + self.cwd + ';' if self.cube and 'cube' not in query: query += 'cube=' + self.cube + ';' if self.exec_mode and 'exec_mode' not in query: query += 'exec_mode=' + self.exec_mode + ';' if self.ncores and 'ncores' not in query: query += 'ncores=' + str(self.ncores) + ';' self.last_request = query try: self.last_response, self.last_jobid, newsession, return_value, error = _ophsubmit.submit( self.username, self.password, self.server, self.port, query) if return_value: raise RuntimeError(error) if newsession is not None: if len(newsession) == 0: self.session = None else: self.session = newsession self.cwd = '/' response = self.deserialize_response() if response is not None: for response_i in response['response']: if response_i['objclass'] == 'text': if response_i['objcontent'][0][ 'title'] == 'Output Cube': self.cube = response_i['objcontent'][0]['message'] break for response_i in response['response']: if response_i['objclass'] == 'text': if response_i['objcontent'][0][ 'title'] == 'Current Working Directory': self.cwd = response_i['objcontent'][0]['message'] break except Exception as e: print(get_linenumber(), "Something went wrong in submitting the request:", e) return None return self
def wsubmit(self, workflow, *params): """wsubmit(workflow,*params) -> self : Submit an entire workflow passing a JSON string or the path of a JSON file and an optional series of parameters that will replace $1, $2 etc. in the workflow. The workflow will be validated against the Ophidia Workflow JSON Schema. :param workflow: JSON string or path of a JSON file containing an Ophidia workflow :type workflow: str :param params: list of positional parameters that will replace $1, $2 etc. in the workflow :type params: str :returns: self or None :rtype: Client or None :raises: RuntimeError """ if workflow is None: raise RuntimeError('workflow is not present') if self.username is None or self.password is None or self.server is None or self.port is None: raise RuntimeError('one or more login parameters are None') request = None import os.path import re if os.path.isfile(workflow): try: file = open(workflow, 'r') buffer = file.read() file.close() for index, param in enumerate(params, start=1): buffer = buffer.replace('${' + str(index) + '}', str(param)) buffer = re.sub('(\$' + str(index) + ')([^0-9]|$)', str(param) + '\g<2>', buffer) request = json.loads(buffer) except Exception as e: print(get_linenumber(),"Something went wrong in reading and/or parsing the file:", e) return None else: try: buffer = workflow for index, param in enumerate(params, start=1): buffer = buffer.replace('${' + str(index) + '}', str(param)) buffer = re.sub('(\$' + str(index) + ')([^0-9]|$)', str(param) + '\g<2>', buffer) request = json.loads(buffer) except Exception as e: print(get_linenumber(),"Something went wrong in parsing the string:", e) return None del os.path del re if self.session and 'sessionid' not in request: request['sessionid'] = self.session if self.cwd and 'cwd' not in request: request['cwd'] = self.cwd if self.cube and 'cube' not in request: request['cube'] = self.cube if self.exec_mode and 'exec_mode' not in request: request['exec_mode'] = self.exec_mode if self.ncores and 'ncores' not in request: request['ncores'] = str(self.ncores) self.last_request = json.dumps(request) try: if not self.wisvalid(self.last_request): print("The workflow is not valid") return None self.last_response, self.last_jobid, newsession, return_value, error = _ophsubmit.submit(self.username, self.password, self.server, self.port, self.last_request) if return_value: raise RuntimeError(error) if newsession is not None: if len(newsession) == 0: self.session = None else: self.session = newsession self.cwd = '/' response = self.deserialize_response() if response is not None: for response_i in response['response']: if response_i['objclass'] == 'text': if response_i['objcontent'][0]['title'] == 'Output Cube': self.cube = response_i['objcontent'][0]['message'] break for response_i in response['response']: if response_i['objclass'] == 'text': if response_i['objcontent'][0]['title'] == 'Current Working Directory': self.cwd = response_i['objcontent'][0]['message'] break except Exception as e: print(get_linenumber(),"Something went wrong in submitting the request:", e) return None return self