示例#1
0
文件: Process.py 项目: rbs-pli/pywps
    def execute(self, wps_request, uuid):

        self._set_uuid(uuid)
        async = False
        wps_response = WPSResponse(self, wps_request, self.uuid)

        LOGGER.debug(
            'Check if status storage and updating are supported by this process'
        )
        if wps_request.store_execute == 'true':
            if self.store_supported != 'true':
                raise StorageNotSupported(
                    'Process does not support the storing of the execute response'
                )

            if wps_request.status == 'true':
                if self.status_supported != 'true':
                    raise OperationNotSupported(
                        'Process does not support the updating of status')

                wps_response.status = WPSResponse.STORE_AND_UPDATE_STATUS
                async = True
            else:
                wps_response.status = WPSResponse.STORE_STATUS

        LOGGER.debug(
            'Check if updating of status is not required then no need to spawn a process'
        )

        wps_response = self._execute_process(async, wps_request, wps_response)

        return wps_response
示例#2
0
    def execute(self, wps_request, uuid):
        self._set_uuid(uuid)
        self.async_ = False
        response_cls = get_response("execute")
        wps_response = response_cls(wps_request, process=self, uuid=self.uuid)

        LOGGER.debug(
            'Check if status storage and updating are supported by this process'
        )
        if wps_request.store_execute == 'true':
            if self.store_supported != 'true':
                raise StorageNotSupported(
                    'Process does not support the storing of the execute response'
                )

            if wps_request.status == 'true':
                if self.status_supported != 'true':
                    raise OperationNotSupported(
                        'Process does not support the updating of status')

                wps_response.store_status_file = True
                self.async_ = True
            else:
                wps_response.store_status_file = False

        LOGGER.debug(
            'Check if updating of status is not required then no need to spawn a process'
        )

        wps_response = self._execute_process(self.async_, wps_request,
                                             wps_response)

        return wps_response
示例#3
0
    def execute(self, wps_request):
        import multiprocessing
        self.uuid = str(uuid4())
        async = False
        wps_response = WPSResponse(self, wps_request)

        # check if status storage and updating are supported by this process
        if wps_request.store_execute == 'true':
            if self.store_supported != 'true':
                raise StorageNotSupported(
                    'Process does not support the storing of the execute response'
                )

            file_path = config.get_config_value('server', 'outputPath')
            file_url = '%s:%s%s' % (
                config.get_config_value('wps', 'serveraddress'),
                config.get_config_value('wps', 'serverport'),
                config.get_config_value('server', 'outputUrl'))

            self.status_location = os.path.join(file_path, self.uuid) + '.xml'
            self.status_url = os.path.join(file_url, self.uuid) + '.xml'

            if wps_request.status == 'true':
                if self.status_supported != 'true':
                    raise OperationNotSupported(
                        'Process does not support the updating of status')

                wps_response.status = WPSResponse.STORE_AND_UPDATE_STATUS
                async = True
            else:
                wps_response.status = WPSResponse.STORE_STATUS

        # check if updating of status is not required then no need to spawn a process
        if async:
            process = multiprocessing.Process(target=self._run_process,
                                              args=(wps_request, wps_response))
            process.start()
        else:
            wps_response = self._run_process(wps_request, wps_response)

        return wps_response
示例#4
0
    def _parse_and_execute(self, process, wps_request):
        """Parse and execute request
        """
        # check if datainputs is required and has been passed
        if process.inputs:
            if wps_request.inputs is None:
                raise MissingParameterValue('', 'datainputs')

        # check if all mandatory inputs have been passed
        data_inputs = {}
        for inpt in process.inputs:
            if inpt.identifier not in wps_request.inputs:
                if inpt.min_occurs > 0:
                    raise MissingParameterValue(inpt.identifier, inpt.identifier)
                else:
                    data_inputs[inpt.identifier] = inpt.clone()

            # Replace the dicts with the dict of Literal/Complex inputs
            # set the input to the type defined in the process
            if isinstance(inpt, ComplexInput):
                data_inputs[inpt.identifier] = self.create_complex_inputs(inpt,
                    wps_request.inputs[inpt.identifier])
            elif isinstance(inpt, LiteralInput):
                data_inputs[inpt.identifier] = self.create_literal_inputs(inpt,
                    wps_request.inputs[inpt.identifier])
            elif isinstance(inpt, BoundingBoxInput):
                data_inputs[inpt.identifier] = self.create_bbox_inputs(inpt,
                    wps_request.inputs[inpt.identifier])

        wps_request.inputs = data_inputs
        
        # set as_reference to True for all the outputs specified as reference
        # if the output is not required to be raw
        if not wps_request.raw:
            for wps_outpt in wps_request.outputs:

                is_reference = wps_request.outputs[wps_outpt].get('asReference', 'false')
                if is_reference.lower() == 'true':
                    # check if store is supported
                    if process.store_supported == 'false':
                        raise StorageNotSupported('The storage of data is not supported for this process.')

                    is_reference = True
                else:
                    is_reference = False

                for outpt in process.outputs:
                    if outpt.identifier == wps_outpt:
                        outpt.as_reference = is_reference

        # catch error generated by process code
        try:
            wps_response = process.execute(wps_request)
        except Exception as e:
            raise NoApplicableCode('Service error: %s' % e)

        # get the specified output as raw
        if wps_request.raw:
            for outpt in wps_request.outputs:
                for proc_outpt in process.outputs:
                    if outpt == proc_outpt.identifier:
                        return Response(proc_outpt.data)

            # if the specified identifier was not found raise error
            raise InvalidParameterValue('')

        return wps_response
示例#5
0
文件: Service.py 项目: janpisl/pywps
    def _parse_and_execute(self, process, wps_request, uuid):
        """Parse and execute request
        """

        LOGGER.debug('Checking if all mandatory inputs have been passed')
        data_inputs = {}
        for inpt in process.inputs:
            # Replace the dicts with the dict of Literal/Complex inputs
            # set the input to the type defined in the process.

            request_inputs = None
            if inpt.identifier in wps_request.inputs:
                request_inputs = wps_request.inputs[inpt.identifier]

            if not request_inputs:
                if inpt.data_set:
                    data_inputs[inpt.identifier] = [inpt.clone()]
            else:

                if isinstance(inpt, ComplexInput):
                    data_inputs[inpt.identifier] = self.create_complex_inputs(
                        inpt, request_inputs)
                elif isinstance(inpt, LiteralInput):
                    data_inputs[inpt.identifier] = self.create_literal_inputs(
                        inpt, request_inputs)
                elif isinstance(inpt, BoundingBoxInput):
                    data_inputs[inpt.identifier] = self.create_bbox_inputs(
                        inpt, request_inputs)

        for inpt in process.inputs:

            if inpt.identifier not in data_inputs:
                if inpt.min_occurs > 0:
                    LOGGER.error('Missing parameter value: %s',
                                 inpt.identifier)
                    raise MissingParameterValue(inpt.identifier,
                                                inpt.identifier)

        wps_request.inputs = data_inputs

        # set as_reference to True for all the outputs specified as reference
        # if the output is not required to be raw
        if not wps_request.raw:
            for wps_outpt in wps_request.outputs:

                is_reference = wps_request.outputs[wps_outpt].get(
                    'asReference', 'false')
                if is_reference.lower() == 'true':
                    # check if store is supported
                    if process.store_supported == 'false':
                        raise StorageNotSupported(
                            'The storage of data is not supported for this process.'
                        )

                    is_reference = True
                else:
                    is_reference = False

                for outpt in process.outputs:
                    if outpt.identifier == wps_outpt:
                        outpt.as_reference = is_reference

        # catch error generated by process code
        try:
            wps_response = process.execute(wps_request, uuid)
        except Exception as e:
            e_follow = e
            if not isinstance(e, NoApplicableCode):
                e_follow = NoApplicableCode('Service error: %s' % e)
            if wps_request.raw:
                resp = Response(e_follow.get_body(),
                                mimetype='application/xml')
                resp.call_on_close(process.clean)
                return resp
            else:
                raise e_follow

        # get the specified output as raw
        if wps_request.raw:
            for outpt in wps_request.outputs:
                for proc_outpt in process.outputs:
                    if outpt == proc_outpt.identifier:
                        return Response(proc_outpt.data)

            # if the specified identifier was not found raise error
            raise InvalidParameterValue('')

        return wps_response
示例#6
0
    def _parse_and_execute(self, process, wps_request, uuid):
        """Parse and execute request
        """

        LOGGER.debug('Checking if all mandatory inputs have been passed')
        data_inputs = {}
        for inpt in process.inputs:
            # Replace the dicts with the dict of Literal/Complex inputs
            # set the input to the type defined in the process.

            request_inputs = None
            if inpt.identifier in wps_request.inputs:
                request_inputs = wps_request.inputs[inpt.identifier]

            if not request_inputs:
                if inpt._default is not None:
                    if not inpt.data_set and isinstance(inpt, ComplexInput):
                        inpt._set_default_value()

                    data_inputs[inpt.identifier] = [inpt.clone()]
            else:

                if isinstance(inpt, ComplexInput):
                    data_inputs[inpt.identifier] = self.create_complex_inputs(
                        inpt, request_inputs)
                elif isinstance(inpt, LiteralInput):
                    data_inputs[inpt.identifier] = self.create_literal_inputs(
                        inpt, request_inputs)
                elif isinstance(inpt, BoundingBoxInput):
                    data_inputs[inpt.identifier] = self.create_bbox_inputs(
                        inpt, request_inputs)

        for inpt in process.inputs:

            if inpt.identifier not in data_inputs:
                if inpt.min_occurs > 0:
                    LOGGER.error('Missing parameter value: %s',
                                 inpt.identifier)
                    raise MissingParameterValue(inpt.identifier,
                                                inpt.identifier)

        wps_request.inputs = data_inputs

        # set as_reference to True for all the outputs specified as reference
        # if the output is not required to be raw
        if not wps_request.raw:
            for wps_outpt in wps_request.outputs:

                is_reference = wps_request.outputs[wps_outpt].get(
                    'asReference', 'false')
                mimetype = wps_request.outputs[wps_outpt].get('mimetype', '')
                if is_reference.lower() == 'true':
                    # check if store is supported
                    if process.store_supported == 'false':
                        raise StorageNotSupported(
                            'The storage of data is not supported for this process.'
                        )

                    is_reference = True
                else:
                    is_reference = False

                for outpt in process.outputs:
                    if outpt.identifier == wps_outpt:
                        outpt.as_reference = is_reference
                        if isinstance(outpt, ComplexOutput) and mimetype != '':
                            data_format = [
                                f for f in outpt.supported_formats
                                if f.mime_type == mimetype
                            ]
                            if len(data_format) == 0:
                                raise InvalidParameterValue('MimeType ' +
                                                            mimetype +
                                                            ' not valid')
                            outpt.data_format = data_format[0]

        wps_response = process.execute(wps_request, uuid)
        return wps_response