Beispiel #1
0
    def handle_python(self, _task: OrcaTask):
        log.debug("  exec python file : " + _task.python)

        resolved_file = self._resolve_file_path(_task.python, ".py")
        config = _task.config
        try:
            if resolved_file is None:
                exec(_task.python, _task.locals)
            else:
                with open(resolved_file, 'r') as script:
                    _python = script.read()
                    exec(_python, _task.locals)
                    if 'callable' in config:
                        call_str = self.__get_call_string(config, _python)
                        exec(call_str, _task.locals)

            _task.status = "success"
        except IndexError:
            raise ExecutionError(
                'The function {0} was not defined in the file: {1}'.format(_task.config.get('callable'), _task.python)
            )
        except BaseException as e:
            _task.status = "failed"
            log.debug(str(e))
            raise
        # remove after execution
        keys_to_remove = [k for k in _task.locals if
                          k not in _task.outputs and k not in _task.inputs]

        for key in keys_to_remove:
            del _task.locals[key]
Beispiel #2
0
def handle_python_result(outputs: List, name: str, task_locals: Dict) -> Dict:
    d = {}
    for out in outputs:
        try:
            d[name + '.' + out] = task_locals[out]
        except KeyError as e:
            raise ExecutionError("Task output not found: {0}".format(out), e)
    return d
Beispiel #3
0
def handle_csip_result(response: Dict, outputs: List, name: str) -> Dict:
    d = {}
    for k, v in response.items():
        if k in outputs:
            try:
                d[name + "." + k] = v['value']
            except KeyError as e:
                raise ExecutionError(
                    "Output variable {0} not found, message: {1}," +
                    "\n the response from the task was: {2}".format(k, e, json.dumps(response, indent=2)))
    return d
Beispiel #4
0
 def handle_csip(self, _task: OrcaTask) -> Dict:
     try:
         client = Client()
         for key, value in _task.locals.items():
             if isinstance(value, DottedCollection):
                 client.add_data(key, value.to_python())
             else:
                 client.add_data(key, value)
         client = client.execute(_task.csip)
         return handle_csip_result(client.data, _task.outputs, _task.name)
     except requests.exceptions.HTTPError as e:
         raise ExecutionError(e)