def get_capabilities(wps_host=None, wps_client=None, version='1.0.0'):
    """WPS GetCapabilities response.

    Parameters
    ----------
    wps_host : string
    wps_client : pywps.tests.WpsClient
    version : string

    Returns
    -------
    out : list of ?

    """

    if wps_host:
        return WebProcessingService(wps_host, version)
    else:
        response = wps_client.get(
            '?service=WPS&request=GetCapabilities&version={0}'.format(version))
        wps_reader = WPSReader()
        element = wps_reader.readFromString(response.get_data())
        wps = WebProcessingService(None, version, skip_caps=True)
        wps._parseCapabilitiesMetadata(element)
        return wps
def test_wps_getcapabilities_usgs():
    # Initialize WPS client
    wps = WebProcessingService('http://cida.usgs.gov/gdp/process/WebProcessingService', skip_caps=True)

    # Execute fake invocation of GetCapabilities operation by parsing cached response from USGS service
    xml = open(resource_file('wps_USGSCapabilities.xml'), 'rb').read()
    wps.getcapabilities(xml=xml)

    # Check WPS description
    assert wps.updateSequence is not None
    assert wps.identification.type == 'WPS'
    assert wps.identification.title == 'Geo Data Portal WPS Implementation'
    assert wps.identification.abstract == 'A Geo Data Portal Service based on the 52north implementation of WPS 1.0.0'

    # Check available operations
    operations = [op.name for op in wps.operations]
    assert operations == [
        'GetCapabilities',
        'DescribeProcess',
        'Execute']

    # Check high level process descriptions
    processes = [(p.identifier, p.title) for p in wps.processes]
    assert processes == [
        ('gov.usgs.cida.gdp.wps.algorithm.filemanagement.ReceiveFiles', 'gov.usgs.cida.gdp.wps.algorithm.filemanagement.ReceiveFiles'),  # noqa
        ('gov.usgs.cida.gdp.wps.algorithm.discovery.CalculateWCSCoverageInfo', 'gov.usgs.cida.gdp.wps.algorithm.discovery.CalculateWCSCoverageInfo'),  # noqa
        ('gov.usgs.cida.gdp.wps.algorithm.communication.EmailWhenFinishedAlgorithm', 'gov.usgs.cida.gdp.wps.algorithm.communication.EmailWhenFinishedAlgorithm'),  # noqa
        ('gov.usgs.cida.gdp.wps.algorithm.communication.GeoserverManagementAlgorithm', 'gov.usgs.cida.gdp.wps.algorithm.communication.GeoserverManagementAlgorithm'),  # noqa
        ('gov.usgs.cida.gdp.wps.algorithm.discovery.GetWcsCoverages', 'gov.usgs.cida.gdp.wps.algorithm.discovery.GetWcsCoverages'),  # noqa
        ('gov.usgs.cida.gdp.wps.algorithm.filemanagement.GetWatersGeom', 'gov.usgs.cida.gdp.wps.algorithm.filemanagement.GetWatersGeom'),  # noqa
        ('gov.usgs.cida.gdp.wps.algorithm.discovery.ListOpendapGrids', 'gov.usgs.cida.gdp.wps.algorithm.discovery.ListOpendapGrids'),  # noqa
        ('gov.usgs.cida.gdp.wps.algorithm.filemanagement.CreateNewShapefileDataStore', 'gov.usgs.cida.gdp.wps.algorithm.filemanagement.CreateNewShapefileDataStore'),  # noqa
        ('gov.usgs.cida.gdp.wps.algorithm.discovery.GetGridTimeRange', 'gov.usgs.cida.gdp.wps.algorithm.discovery.GetGridTimeRange'),  # noqa
        ]
示例#3
0
    def create_from_process(cls,
                            url,
                            identifier,
                            request_template,
                            username=None,
                            password=None,
                            output_hook=None):
        try:
            wps = WebProcessingService(url,
                                       username=username,
                                       password=password,
                                       verbose=False,
                                       skip_caps=False)
            process = wps.describeprocess(identifier)

            if process:
                _f = open(request_template)
                _run = cls.objects.create(identifier=identifier,
                                          title=process.title,
                                          abstract=process.abstract,
                                          version=wps.version,
                                          url=url,
                                          service_instance=wps.url,
                                          username=username,
                                          password=password,
                                          request_template=File(_f),
                                          output_hook=output_hook)
                _run._initialized = True
                _run._wps = wps
                return _run
        except:
            log.exception("Could not create Process!")
            raise

        return wps.id
示例#4
0
def pinned_processes(request):
    from owslib.wps import WebProcessingService
    settings = request.db.settings.find_one() or {}
    processes = []
    if 'pinned_processes' in settings:
        for pinned in settings.get('pinned_processes'):
            try:
                service_name, identifier = pinned.split('.', 1)
                url = request.route_path('processes_execute',
                                         _query=[('wps', service_name),
                                                 ('process', identifier)])
                wps = WebProcessingService(url=request.route_url(
                    'owsproxy', service_name=service_name),
                                           verify=False)
                # TODO: need to fix owslib to handle special identifiers
                process = wps.describeprocess(identifier)
                description = headline(process.abstract)
            except Exception:
                LOGGER.warn("could not add pinned process %s", pinned)
            else:
                processes.append(
                    dict(title=process.identifier,
                         description=description,
                         url=url,
                         service_title=wps.identification.title))
    return processes
示例#5
0
async def fimex_transfer(*,
                         user_id: str,
                         email: EmailStr,
                         uri: str,
                         wps_url: str,
                         reducetime_start: str = None,
                         reducetime_end: str = None,
                         interpolate_proj_string: str = None,
                         interpolate_method: str = None,
                         select_variables: str,
                         interpolate_xaxis_min: str = None,
                         interpolate_xaxis_max: str = None,
                         interpolate_yaxis_min: str = None,
                         interpolate_yaxis_max: str = None,
                         interpolate_xaxis_units: str = None,
                         interpolate_yaxis_units: str = None,
                         reducebox_east: str,
                         reducebox_south: str,
                         reducebox_west: str,
                         reducebox_north: str,
                         interpolate_hor_steps: str = None,
                         inputtype: str,
                         outputtype: str,
                         background_tasks: BackgroundTasks):
    input_files = uri.split(",")
    fimex_list = []
    for input_file in input_files:
        print(input_file)
        fimex_list.append(
            Fimex(wps_url, input_file, reducetime_start, reducetime_end,
                  interpolate_proj_string, interpolate_method,
                  select_variables, interpolate_xaxis_min,
                  interpolate_xaxis_max, interpolate_yaxis_min,
                  interpolate_yaxis_max, interpolate_xaxis_units,
                  interpolate_yaxis_units, reducebox_east, reducebox_south,
                  reducebox_west, reducebox_north, interpolate_hor_steps,
                  inputtype, outputtype))
    # wps=http://localhost:5000/wps?request=GetCapabilities&service=WPS
    # input_file = 'http://OpeDAP-server/thredds/dodsC/NBS/S2B/2018/02/18/S2B_MSIL1C_20180218T110109_N0206_R094_T33WWS_20180218T144023.nc'
    # wps=http://localhost:5000/cgi-bin/pywps.cgi?service=wps&version=1.0.0&request=getcapabilities
    wps = WebProcessingService(wps_url, verbose=False, skip_caps=True)
    config = confuse.Configuration('Basket', __name__)
    transaction = Transaction(str(uuid.uuid4()), user_id, email,
                              status.Status.ORDERED, "nordatanet", fimex_list)
    solr_client = SolrClient(config['solr']['endpoint'].get(), "basket")
    solr_client.update(transaction.toSolrDocument())

    try:
        for fimex in fimex_list:
            execution = wps.execute('transformation',
                                    fimex.input_map(),
                                    output=fimex.output_map())
            background_tasks.add_task(doFinal, execution, email, transaction)
            print(execution.statusLocation)

    except requests.exceptions.ConnectionError as ce:
        raise HTTPException(status_code=502,
                            detail="Failed to establish a connection")

    return transaction.toJson()
示例#6
0
def complex_input_with_reference():
    """
    use ComplexDataInput with a reference to a document
    """

    print("\ncomplex_input_with_reference ...")

    wps = WebProcessingService('http://localhost:8094/wps', verbose=verbose)

    processid = 'wordcount'
    textdoc = ComplexDataInput(
        "http://www.gutenberg.org/files/28885/28885-h/28885-h.htm"
    )  # alice in wonderland
    inputs = [("text", textdoc)]
    # list of tuple (output identifier, asReference attribute)
    outputs = [("output", True)]

    execution = wps.execute(processid, inputs, output=outputs)
    monitorExecution(execution)

    # show status
    print('percent complete', execution.percentCompleted)
    print('status message', execution.statusMessage)

    for output in execution.processOutputs:
        print('identifier=%s, dataType=%s, data=%s, reference=%s' %
              (output.identifier, output.dataType, output.data,
               output.reference))
示例#7
0
    def _executeRequest(self, processid, inputs, verbose):
        """
        This function makes a call to the Web Processing Service with
        the specified user inputs.
        """

        wps = WebProcessingService(WPS_URL)

        # if verbose=True, then will we will monitor the status of the call.
        # if verbose=False, then we will return only the file outputpath.
        if not verbose:
            # redirects the standard output to avoid printing request status
            old_stdout = sys.stdout
            result = StringIO()
            sys.stdout = result

            # executes the request
            execution = wps.execute(processid, inputs, output="OUTPUT")
            monitorExecution(execution, download=True)

            # sets the standard output back to original
            sys.stdout = old_stdout
            result_string = result.getvalue()

            #parses the redirected output to get the filepath of the saved file
            output = result_string.split('\n')
            tmp = output[len(output) - 2].split(' ')
            return tmp[len(tmp) - 1]

        # executes the request
        execution = wps.execute(processid, inputs, output="OUTPUT")
        monitorExecution(execution, download=True)
示例#8
0
def test_wps_describeprocess_bbox():
    # Initialize WPS client
    wps = WebProcessingService('http://localhost:8094/wps', skip_caps=True)
    # Execute fake invocation of DescribeProcess operation by parsing cached response from Emu service
    xml = open(resource_file('wps_bbox_DescribeProcess.xml'), 'rb').read()
    process = wps.describeprocess('bbox', xml=xml)
    # Check process description
    assert process.identifier == 'bbox'
    assert process.title == 'Bounding Box'
    # Check process inputs
    # Example Input:
    #     identifier=bbox, title=Bounding Box, abstract=None, data type=BoundingBoxData
    #     Supported Value: EPSG:4326
    #     Supported Value: EPSG:3035
    #     Default Value: EPSG:4326
    #     minOccurs=1, maxOccurs=1
    for input in process.dataInputs:
        assert input.identifier == 'bbox'
        assert input.dataType == 'BoundingBoxData'
    # Example Output:
    #    identifier=bbox, title=Bounding Box, abstract=None, data type=BoundingBoxData
    #    Supported Value: EPSG:4326
    #    Default Value: EPSG:4326
    #    reference=None, mimeType=None
    # Check process outputs
    for output in process.processOutputs:
        assert output.identifier == 'bbox'
        assert output.dataType == 'BoundingBoxData'
示例#9
0
    def _generateRequest(self,
                         dataSetURI,
                         algorithm,
                         method,
                         varID=None,
                         verbose=False):
        """
        Takes a dataset uri, algorithm, method, and datatype. This function will generate a simple XML document
        to make the request specified. (Only works for ListOpendapGrids and GetGridTimeRange). 
        
        Will return a list containing the info requested for (either data types or time range).
        """

        wps_Service = 'http://cida.usgs.gov/gdp/utility/WebProcessingService'
        POST = WebProcessingService(wps_Service, verbose=False)

        xmlGen = gdpXMLGenerator()
        root = xmlGen.getXMLRequestTree(dataSetURI, algorithm, method, varID,
                                        verbose)

        # change standard output to not display waiting status
        if not verbose:
            old_stdout = sys.stdout
            result = StringIO()
            sys.stdout = result
        request = etree.tostring(root)

        execution = POST.execute(None, [], request=request)
        if method == 'getDataSetTime':
            seekterm = 'time'
        else:
            seekterm = 'name'
        if not verbose:
            sys.stdout = old_stdout
        return self._parseXMLNodesForTagText(execution.response, seekterm)
示例#10
0
    def setUp(self):
        """Run the WPS process and store the result."""
        self.wps = WebProcessingService(self.wps_host)

        # Get the description of the process
        self.p = self.wps.describeprocess(self.identifier)

        ### --------------------- ###
        ### Early fault detection ###
        ### --------------------- ###
        # Get the names of the inputs
        ins = [o.identifier for o in self.p.dataInputs]

        # Get the names of the outputs
        outs = [o.identifier for o in self.p.processOutputs]

        # Check that the params are in the inputs
        for key in self.params.keys():
            self.assertIn(key, ins)

        # Check that the desired output is defined
        self.assertIn(self.output_name, outs)
        ### --------------------- ###


        # Execute the process
        self.output = self.execute_wps()
示例#11
0
def call_wps(args):
    if not args.token:
        user_id = args.user
        if not user_id:
            logging.error("No user id found on the call, aborting!")
            sys.exit(1)
        user_token_file = os.path.join("/etc/d4science/", user_id)
        with open(user_token_file, "r") as f:
            gcube_vre_token = f.read()
    else:
        gcube_vre_token = args.token.encode("utf-8")

    logging.info("User: %s", args.user)
    logging.info("Token: (SHA256) %s", hashlib.sha256(gcube_vre_token).hexdigest())

    gcube_vre_token_header = {"gcube-token": gcube_vre_token}

    dataminer_url = (
        "http://dataminer-prototypes.d4science.org/wps/" "WebProcessingService"
    )
    wps = WebProcessingService(dataminer_url, headers=gcube_vre_token_header)
    process_id = args.process
    process = wps.describeprocess(process_id)

    inputs = build_inputs(process, args.input, args.inputdata, gcube_vre_token)
    outputs = [(o.identifier, True) for o in process.processOutputs]
    # execute the process
    execution = wps.execute(process_id, inputs, outputs)
    monitorExecution(execution, sleepSecs=5, download=True)
    logging.info("Execution status: %s", execution.status)
    exit_code = 0 if execution.status == "ProcessSucceeded" else 1
    logging.info("Exit code: %d", exit_code)
    produce_output(execution, args.output, args.outdir, gcube_vre_token_header)
    return exit_code
示例#12
0
def complex_input_with_content():
    """
    use ComplexDataInput with a direct content
    """

    print("\ncomplex_input_with_content ...")

    wps = WebProcessingService('http://localhost:8094/wps', verbose=verbose)

    processid = 'wordcount'
    textdoc = ComplexDataInput(
        "ALICE was beginning to get very tired ...")  # alice in wonderland
    inputs = [("text", textdoc)]
    # list of tuple (output identifier, asReference attribute)
    outputs = [("output", True)]

    execution = wps.execute(processid, inputs, output=outputs)
    monitorExecution(execution)

    # show status
    print('percent complete', execution.percentCompleted)
    print('status message', execution.statusMessage)

    for output in execution.processOutputs:
        print('identifier=%s, dataType=%s, data=%s, reference=%s' %
              (output.identifier, output.dataType, output.data,
               output.reference))
示例#13
0
文件: pyGDP.py 项目: prog556/pyGDP
 def _executeRequest(self, processid, inputs, verbose):
     """
     This function makes a call to the Web Processing Service with
     the specified user inputs.
     """
     
     wps = WebProcessingService(WPS_URL)
     
     # if verbose=True, then will we will monitor the status of the call.
     # if verbose=False, then we will return only the file outputpath.
     if not verbose:
         # redirects the standard output to avoid printing request status
         old_stdout = sys.stdout
         result = StringIO()
         sys.stdout = result
         
         # executes the request
         execution = wps.execute(processid, inputs, output = "OUTPUT")
         monitorExecution(execution, download=True)    
         
         # sets the standard output back to original
         sys.stdout = old_stdout
         result_string = result.getvalue()
         
         #parses the redirected output to get the filepath of the saved file
         output = result_string.split('\n')
         tmp = output[len(output) - 2].split(' ')
         return tmp[len(tmp)-1]
 
     # executes the request
     execution = wps.execute(processid, inputs, output = "OUTPUT")
     monitorExecution(execution, download=True)   
示例#14
0
    def __init__(self, request):
        self.request = request
        self.execution = None
        self.service_name = None
        self.processid = None
        self.process = None
        if 'job_id' in request.params:
            job = request.db.jobs.find_one(
                {'identifier': request.params['job_id']})
            self.service_name = job.get('service_name')
            self.execution = check_status(url=job.get('status_location'),
                                          response=job.get('response'),
                                          verify=False,
                                          sleep_secs=0)
            self.processid = self.execution.process.identifier
        elif 'wps' in request.params:
            self.service_name = request.params.get('wps')
            self.processid = request.params.get('process')

        if self.service_name:
            # TODO: avoid getcaps
            self.wps = WebProcessingService(url=request.route_url(
                'owsproxy', service_name=self.service_name),
                                            verify=False)
            # TODO: need to fix owslib to handle special identifiers
            self.process = self.wps.describeprocess(self.processid)
        super(ExecuteProcess, self).__init__(request,
                                             name='processes_execute',
                                             title='')
示例#15
0
def _generateRequest(dataSetURI, algorithm, method, varID, verbose):
    """
    Takes a dataset uri, algorithm, method, and datatype. This function will generate a simple XML document
    to make the request specified. (Only works for ListOpendapGrids and GetGridTimeRange). 
    
    Will return a list containing the info requested for (either data types or time range).
    """

    POST = WebProcessingService(WPS_Service, verbose=verbose)

    xmlGen = gdpXMLGenerator()
    root = xmlGen.getXMLRequestTree(dataSetURI, algorithm, method, varID,
                                    verbose)

    request = etree.tostring(root)

    execution = POST.execute(None, [], request=request)

    _execute_request._check_for_execution_errors(execution)

    if method == 'getDataSetTime':
        seekterm = '{xsd/gdptime-1.0.xsd}time'
    elif method == 'getDataType':
        seekterm = '{xsd/gdpdatatypecollection-1.0.xsd}name'
    elif method == 'getDataLongName':
        seekterm = '{xsd/gdpdatatypecollection-1.0.xsd}description'
    elif method == 'getDataUnits':
        seekterm = '{xsd/gdpdatatypecollection-1.0.xsd}unitsstring'

    return _parseXMLNodesForTagText(execution.response, seekterm)
示例#16
0
def uploadShapeFile(filePath):
    """
    Given a file, this function encodes the file and uploads it onto geoserver.
    """

    # encodes the file, opens it, reads it, and closes it
    # returns a filename in form of: filename_copy.zip
    filePath = _encodeZipFolder(filePath)
    if filePath is None:
        return

    filehandle = open(filePath, 'r')
    filedata = filehandle.read()
    filehandle.close()
    os.remove(filePath)  # deletes the encoded file

    # this if for naming the file on geoServer
    filename = filePath.split("/")
    # gets rid of filepath, keeps only filename eg: file.zip
    filename = filename[len(filename) - 1]
    filename = filename.replace("_copy.zip", "")

    xml_gen = gdpXMLGenerator()
    root = xml_gen.getUploadXMLtree(filename, upload_URL, filedata)

    # now we have a complete XML upload request
    upload_request = etree.tostring(root)
    post = WebProcessingService(WPS_Service)
    execution = post.execute(None, [], request=upload_request)
    monitorExecution(execution)
    return "upload:" + filename
示例#17
0
def wps():
    '''Returns a WPS instance'''
    # Initialize WPS client
    wps = WebProcessingService('http://example.org/wps', skip_caps=True)
    xml = open(resource_file('wps_CEDACapabilities.xml'), 'rb').read()
    wps.getcapabilities(xml=xml)
    return wps
示例#18
0
def multiple_outputs():
    print("\nmultiple outputs ...")
    
    # get multiple outputs
    wps = WebProcessingService('http://localhost:8094/wps', verbose=verbose)

    processid = 'dummyprocess'
    inputs = [("input1", '1'), ("input2", '2')]
    # list of tuple (output identifier, asReference attribute)
    outputs = [("output1",True), ("output2",False)]

    execution = wps.execute(processid, inputs, output=outputs)
    monitorExecution(execution)

    # show status
    print('percent complete', execution.percentCompleted)
    print('status message', execution.statusMessage)

    # outputs
    for output in execution.processOutputs:
        print('identifier=%s, dataType=%s, data=%s, reference=%s' % (output.identifier, output.dataType, output.data, output.reference)) 

    # errors
    print(execution.status)
    for error in execution.errors:
            print(error.code, error.locator, error.text)
示例#19
0
def _generateRequest(dataSetURI, algorithm, method, varID, verbose):
    """
    Takes a dataset uri, algorithm, method, and datatype. This function will generate a simple XML document
    to make the request specified. (Only works for ListOpendapGrids and GetGridTimeRange). 
    
    Will return a list containing the info requested for (either data types or time range).
    """
    
    POST = WebProcessingService(WPS_Service, verbose=verbose)
    
    xmlGen = gdpXMLGenerator()
    root = xmlGen.getXMLRequestTree(dataSetURI, algorithm, method, varID, verbose)           
     
    request = etree.tostring(root)
    
    execution = POST.execute(None, [], request=request)
    
    _execute_request._check_for_execution_errors(execution)
    
    if method == 'getDataSetTime':
        seekterm = '{xsd/gdptime-1.0.xsd}time'
    elif method == 'getDataType':
        seekterm = '{xsd/gdpdatatypecollection-1.0.xsd}name'
    elif method == 'getDataLongName':
        seekterm = '{xsd/gdpdatatypecollection-1.0.xsd}description'
    elif method == 'getDataUnits':
        seekterm = '{xsd/gdpdatatypecollection-1.0.xsd}unitsstring'
    
    return _parseXMLNodesForTagText(execution.response, seekterm)
示例#20
0
def test_wps_response6():
    # Build WPS object; service has been down for some time so skip caps here
    wps = WebProcessingService('http://rsg.pml.ac.uk/wps/vector.cgi', skip_caps=True)

    # Execute face WPS invocation
    request = open(resource_file('wps_PMLExecuteRequest6.xml'), 'rb').read()
    response = open(resource_file('wps_PMLExecuteResponse6.xml'), 'rb').read()
    execution = wps.execute(None, [], request=request, response=response)

    # Check execution result
    assert execution.status == 'ProcessSucceeded'
    assert execution.url == 'http://rsg.pml.ac.uk/wps/vector.cgi'
    assert execution.statusLocation == \
        'http://rsg.pml.ac.uk/wps/wpsoutputs/pywps-132084838963.xml'
    assert execution.serviceInstance == \
        'http://rsg.pml.ac.uk/wps/vector.cgi?service=WPS&request=GetCapabilities&version=1.0.0'
    assert execution.version == '1.0.0'
    # check single output
    output = execution.processOutputs[0]
    assert output.identifier == 'output'
    assert output.title == 'Name for output vector map'
    assert output.mimeType == 'text/xml'
    assert output.dataType == 'ComplexData'
    assert output.reference is None

    response = output.data[0]
    should_return = '''<ns3:FeatureCollection xmlns:ns3="http://ogr.maptools.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://www.opengis.net/wps/1.0.0" xsi:schemaLocation="http://ogr.maptools.org/ output_0n7ij9D.xsd">\n\t\t\t\t\t  <gml:boundedBy xmlns:gml="http://www.opengis.net/gml">\n\t\t\t\t\t    <gml:Box>\n\t\t\t\t\t      <gml:coord><gml:X>-960123.1421801626</gml:X><gml:Y>4665723.56559387</gml:Y></gml:coord>\n\t\t\t\t\t      <gml:coord><gml:X>-101288.6510608822</gml:X><gml:Y>5108200.011823481</gml:Y></gml:coord>\n\t\t\t\t\t    </gml:Box>\n\t\t\t\t\t  </gml:boundedBy>                         \n\t\t\t\t\t  <gml:featureMember xmlns:gml="http://www.opengis.net/gml">\n\t\t\t\t\t    <ns3:output fid="F0">\n\t\t\t\t\t      <ns3:geometryProperty><gml:LineString><gml:coordinates>-960123.142180162365548,4665723.565593870356679,0 -960123.142180162365548,4665723.565593870356679,0 -960123.142180162598379,4665723.565593870356679,0 -960123.142180162598379,4665723.565593870356679,0 -711230.141176006174646,4710278.48552671354264,0 -711230.141176006174646,4710278.48552671354264,0 -623656.677859728806652,4848552.374973464757204,0 -623656.677859728806652,4848552.374973464757204,0 -410100.337491964863148,4923834.82589447684586,0 -410100.337491964863148,4923834.82589447684586,0 -101288.651060882242746,5108200.011823480948806,0 -101288.651060882242746,5108200.011823480948806,0 -101288.651060882257298,5108200.011823480948806,0 -101288.651060882257298,5108200.011823480948806,0</gml:coordinates></gml:LineString></ns3:geometryProperty>\n\t\t\t\t\t      <ns3:cat>1</ns3:cat>\n\t\t\t\t\t      <ns3:id>1</ns3:id>\n\t\t\t\t\t      <ns3:fcat>0</ns3:fcat>\n\t\t\t\t\t      <ns3:tcat>0</ns3:tcat>\n\t\t\t\t\t      <ns3:sp>0</ns3:sp>\n\t\t\t\t\t      <ns3:cost>1002619.181</ns3:cost>\n\t\t\t\t\t      <ns3:fdist>0</ns3:fdist>\n\t\t\t\t\t      <ns3:tdist>0</ns3:tdist>\n\t\t\t\t\t    </ns3:output>\n\t\t\t\t\t  </gml:featureMember>\n\t\t\t\t\t</ns3:FeatureCollection>'''  # noqa
    assert compare_xml(should_return, response) is True
def test_wps_describeprocess_ceda():
    # Initialize WPS client
    wps = WebProcessingService('http://ceda-wps2.badc.rl.ac.uk/wps',
                               skip_caps=True)
    # Execute fake invocation of DescribeProcess operation by parsing cached response from CEDA service
    xml = open(resource_file('wps_CEDADescribeProcess.xml'), 'rb').read()
    process = wps.describeprocess('DoubleIt', xml=xml)
    # Check process description
    assert process.identifier == 'DoubleIt'
    assert process.title == 'Doubles the input number and returns value'
    assert process.abstract == 'This is test process used to demonstrate how the WPS and the WPS User Interface work. The process accepts an integer or floating point number and returns some XML containing the input number double.'  # NOQA
    # Check process properties
    assert process.statusSupported is False
    assert process.storeSupported is True
    # Check process inputs
    # Example Input:
    #   identifier=NumberToDouble, title=NumberToDouble, abstract=NumberToDouble, data type=LiteralData
    #   Any value allowed
    #   Default Value: None
    #   minOccurs=1, maxOccurs=-1
    for input in process.dataInputs:
        assert input.identifier == 'NumberToDouble'
        assert input.dataType == 'LiteralData'
    # Example Output:
    #   identifier=OutputXML, title=OutputXML, abstract=OutputXML, data type=ComplexData
    #   Supported Value: mimeType=text/XML, encoding=UTF-8, schema=NONE
    #   Default Value: None
    #   reference=None, mimeType=None
    # Check process outputs
    for output in process.processOutputs:
        assert output.identifier == 'OutputXML'
        assert output.dataType == 'ComplexData'
示例#22
0
def complex_input_with_content():
    """
    use ComplexDataInput with a direct content
    """
    
    print("\ncomplex_input_with_content ...")
     
    wps = WebProcessingService('http://localhost:8094/wps', verbose=verbose)

    processid = 'wordcount'
    textdoc = ComplexDataInput("ALICE was beginning to get very tired ...")   # alice in wonderland
    inputs = [("text", textdoc)]
    # list of tuple (output identifier, asReference attribute, mimeType attribute)
    # when asReference or mimeType is None - the wps service will use its default option
    outputs = [("output",True,'some/mime-type')]

    execution = wps.execute(processid, inputs, output=outputs)
    monitorExecution(execution)

    # show status
    print('percent complete', execution.percentCompleted)
    print('status message', execution.statusMessage)

    for output in execution.processOutputs:
        print('identifier=%s, dataType=%s, data=%s, reference=%s' % (output.identifier, output.dataType, output.data, output.reference)) 
def test_wps_describeprocess_ceda():
    # Initialize WPS client
    wps = WebProcessingService('http://ceda-wps2.badc.rl.ac.uk/wps', skip_caps=True)
    # Execute fake invocation of DescribeProcess operation by parsing cached response from CEDA service
    xml = open(resource_file('wps_CEDADescribeProcess.xml'), 'rb').read()
    process = wps.describeprocess('Doubleit', xml=xml)
    # Check process description
    assert process.identifier == 'DoubleIt'
    assert process.title == 'Doubles the input number and returns value'
    assert process.abstract == 'This is test process used to demonstrate how the WPS and the WPS User Interface work. The process accepts an integer or floating point number and returns some XML containing the input number double.'  # NOQA
    # Check process properties
    assert process.statusSupported is False
    assert process.storeSupported is True
    # Check process inputs
    # Example Input:
    #   identifier=NumberToDouble, title=NumberToDouble, abstract=NumberToDouble, data type=LiteralData
    #   Any value allowed
    #   Default Value: None
    #   minOccurs=1, maxOccurs=-1
    for input in process.dataInputs:
        assert input.identifier == 'NumberToDouble'
        assert input.dataType == 'LiteralData'
    # Example Output:
    #   identifier=OutputXML, title=OutputXML, abstract=OutputXML, data type=ComplexData
    #   Supported Value: mimeType=text/XML, encoding=UTF-8, schema=NONE
    #   Default Value: None
    #   reference=None, mimeType=None
    # Check process outputs
    for output in process.processOutputs:
        assert output.identifier == 'OutputXML'
        assert output.dataType == 'ComplexData'
def test_wps_getcapabilities_52n():
    # Initialize WPS client
    wps = WebProcessingService(
        'http://geoprocessing.demo.52north.org:8080/52n-wps-webapp-3.3.1/WebProcessingService',
        skip_caps=True)

    # Execute fake invocation of GetCapabilities operation by parsing cached response from 52North service
    xml = open(resource_file('wps_52nCapabilities.xml'), 'rb').read()
    wps.getcapabilities(xml=xml)

    # Check WPS description
    assert wps.identification.type == 'WPS'

    # Check available operations
    operations = [op.name for op in wps.operations]
    assert operations == [
        'GetCapabilities',
        'DescribeProcess',
        'Execute']

    # Check high level process descriptions
    processes = [(p.identifier, p.title) for p in wps.processes]
    assert processes == [
        ('org.n52.wps.server.algorithm.test.MultiReferenceInputAlgorithm', 'for testing multiple inputs by reference'),
        ('org.n52.wps.server.algorithm.test.EchoProcess', 'Echo process'),
        ('org.n52.wps.server.algorithm.test.MultiReferenceBinaryInputAlgorithm', 'for testing multiple binary inputs by reference'),  # noqa
        ('org.n52.wps.server.algorithm.test.LongRunningDummyTestClass', 'org.n52.wps.server.algorithm.test.LongRunningDummyTestClass'),  # noqa
        ('org.n52.wps.server.algorithm.JTSConvexHullAlgorithm', 'org.n52.wps.server.algorithm.JTSConvexHullAlgorithm'),
        ('org.n52.wps.server.algorithm.test.MultipleComplexInAndOutputsDummyTestClass', 'org.n52.wps.server.algorithm.test.MultipleComplexInAndOutputsDummyTestClass'),  # noqa
        ('org.n52.wps.server.algorithm.test.DummyTestClass', 'org.n52.wps.server.algorithm.test.DummyTestClass')]
示例#25
0
文件: pyGDP.py 项目: prog556/pyGDP
 def _generateRequest(self, dataSetURI, algorithm, method, varID=None, verbose=False):
     """
     Takes a dataset uri, algorithm, method, and datatype. This function will generate a simple XML document
     to make the request specified. (Only works for ListOpendapGrids and GetGridTimeRange). 
     
     Will return a list containing the info requested for (either data types or time range).
     """
     
     wps_Service = 'http://cida.usgs.gov/gdp/utility/WebProcessingService'
     POST = WebProcessingService(wps_Service, verbose=False)
     
     xmlGen = gdpXMLGenerator()
     root = xmlGen.getXMLRequestTree(dataSetURI, algorithm, method, varID, verbose)           
     
     # change standard output to not display waiting status
     if not verbose:
         old_stdout = sys.stdout
         result = StringIO()
         sys.stdout = result   
     request = etree.tostring(root)
     
     execution = POST.execute(None, [], request=request)
     if method == 'getDataSetTime':
         seekterm = 'time'
     else:
         seekterm = 'name'
     if not verbose:
         sys.stdout = old_stdout
     return self._parseXMLNodesForTagText(execution.response, seekterm)
示例#26
0
文件: pyGDP.py 项目: schwehr/pyGDP
    def _executeRequest(self, processid, inputs, output, verbose):
        """
        This function makes a call to the Web Processing Service with
        the specified user inputs.
        """
        wps = WebProcessingService(WPS_URL)

        old_stdout = sys.stdout
        # create StringIO() for listening to print
        result = StringIO()
        if not verbose: # redirect standard output
            sys.stdout = result
        
        execution = wps.execute(processid, inputs, output)
        monitorExecution(execution, download=False) # monitors for success
    
        # redirect standard output after successful execution
        sys.stdout = result
        monitorExecution(execution, download=True)
                
        result_string = result.getvalue()
        output = result_string.split('\n')
        tmp = output[len(output) - 2].split(' ')  
        sys.stdout = old_stdout
        return tmp[len(tmp)-1]
示例#27
0
def test_wps_response6():
    # Build WPS object; service has been down for some time so skip caps here
    wps = WebProcessingService('http://rsg.pml.ac.uk/wps/vector.cgi', skip_caps=True)

    # Execute face WPS invocation
    request = open(resource_file('wps_PMLExecuteRequest6.xml'), 'rb').read()
    response = open(resource_file('wps_PMLExecuteResponse6.xml'), 'rb').read()
    execution = wps.execute(None, [], request=request, response=response)

    # Check execution result
    assert execution.status == 'ProcessSucceeded'
    assert execution.url == 'http://rsg.pml.ac.uk/wps/vector.cgi'
    assert execution.statusLocation == \
        'http://rsg.pml.ac.uk/wps/wpsoutputs/pywps-132084838963.xml'
    assert execution.serviceInstance == \
        'http://rsg.pml.ac.uk/wps/vector.cgi?service=WPS&request=GetCapabilities&version=1.0.0'
    assert execution.version == '1.0.0'
    # check single output
    output = execution.processOutputs[0]
    assert output.identifier == 'output'
    assert output.title == 'Name for output vector map'
    assert output.mimeType == 'text/xml'
    assert output.dataType == 'ComplexData'
    assert output.reference is None

    response = output.data[0]
    should_return = '''<ns3:FeatureCollection xmlns:ns3="http://ogr.maptools.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://www.opengis.net/wps/1.0.0" xsi:schemaLocation="http://ogr.maptools.org/ output_0n7ij9D.xsd">\n\t\t\t\t\t  <gml:boundedBy xmlns:gml="http://www.opengis.net/gml">\n\t\t\t\t\t    <gml:Box>\n\t\t\t\t\t      <gml:coord><gml:X>-960123.1421801626</gml:X><gml:Y>4665723.56559387</gml:Y></gml:coord>\n\t\t\t\t\t      <gml:coord><gml:X>-101288.6510608822</gml:X><gml:Y>5108200.011823481</gml:Y></gml:coord>\n\t\t\t\t\t    </gml:Box>\n\t\t\t\t\t  </gml:boundedBy>                         \n\t\t\t\t\t  <gml:featureMember xmlns:gml="http://www.opengis.net/gml">\n\t\t\t\t\t    <ns3:output fid="F0">\n\t\t\t\t\t      <ns3:geometryProperty><gml:LineString><gml:coordinates>-960123.142180162365548,4665723.565593870356679,0 -960123.142180162365548,4665723.565593870356679,0 -960123.142180162598379,4665723.565593870356679,0 -960123.142180162598379,4665723.565593870356679,0 -711230.141176006174646,4710278.48552671354264,0 -711230.141176006174646,4710278.48552671354264,0 -623656.677859728806652,4848552.374973464757204,0 -623656.677859728806652,4848552.374973464757204,0 -410100.337491964863148,4923834.82589447684586,0 -410100.337491964863148,4923834.82589447684586,0 -101288.651060882242746,5108200.011823480948806,0 -101288.651060882242746,5108200.011823480948806,0 -101288.651060882257298,5108200.011823480948806,0 -101288.651060882257298,5108200.011823480948806,0</gml:coordinates></gml:LineString></ns3:geometryProperty>\n\t\t\t\t\t      <ns3:cat>1</ns3:cat>\n\t\t\t\t\t      <ns3:id>1</ns3:id>\n\t\t\t\t\t      <ns3:fcat>0</ns3:fcat>\n\t\t\t\t\t      <ns3:tcat>0</ns3:tcat>\n\t\t\t\t\t      <ns3:sp>0</ns3:sp>\n\t\t\t\t\t      <ns3:cost>1002619.181</ns3:cost>\n\t\t\t\t\t      <ns3:fdist>0</ns3:fdist>\n\t\t\t\t\t      <ns3:tdist>0</ns3:tdist>\n\t\t\t\t\t    </ns3:output>\n\t\t\t\t\t  </gml:featureMember>\n\t\t\t\t\t</ns3:FeatureCollection>'''  # noqa
    assert compare_xml(should_return, response) is True
def run_wps(process_id,input,output):
    #choose the first wps engine
    my_engine = WebProcessingService('http://appsdev.hydroshare.org:8282/wps/WebProcessingService', verbose=False, skip_caps=True)
    my_engine.getcapabilities()
    my_process = my_engine.describeprocess(process_id)
    my_inputs = my_process.dataInputs
    input_names = [] #getting list of input
    for input1 in my_inputs:
        input_names.append(input1)
    #executing the process..
    execution = my_engine.execute(process_id, input, output)
    request = execution.request
    #set store executeresponse to false
    request = request.replace('storeExecuteResponse="true"', 'storeExecuteResponse="false"')
    url_wps = 'http://appsdev.hydroshare.org:8282/wps/WebProcessingService'
    wps_request = urllib2.Request(url_wps,request)
    wps_open = urllib2.urlopen(wps_request)
    wps_read = wps_open.read()
    if 'href' in wps_read:
        tag = 'href="'
        location = wps_read.find(tag)
        new= wps_read[location+len(tag):len(wps_read)]
        tag2 = '"/>\n    </wps:Output>\n  </wps:ProcessOutputs>\n</wps:'
        location2 = new.find(tag2)
        final = new[0:location2]
        split = final.split()
        wps_request1 = urllib2.Request(split[0])
        wps_open1 = urllib2.urlopen(wps_request1)
        wps_read1 = wps_open1.read()

    #return [final_output_url, final_data]
    return [wps_read1, split]
示例#29
0
def list_wps_service_engines(app_class=None):
    """
    Get all wps engines offered.

    Args:
      app_class (class, optional): The app class to include in the search for wps engines.

    Returns:
      (tuple): A tuple of WPS engine dictionaries.
    """
    # Init vars
    wps_services_list = []

    # If the app_class is given, check it first for a wps engine
    app_wps_services = None

    if app_class and issubclass(app_class):
        #         Instantiate app class and retrieve wps services list
        app = app_class()
        app_wps_services = app.wps_services()

    if app_wps_services:
        # Search for match
        for app_wps_service in app_wps_services:
            wps = WebProcessingService(app_wps_service.endpoint,
                                       username=app_wps_service.username,
                                       password=app_wps_service.password,
                                       verbose=False,
                                       skip_caps=True)

            activated_wps = activate_wps(wps=wps, endpoint=app_wps_service.endpoint, name=app_wps_service.name)

            if activated_wps:
                wps_services_list.append(activated_wps)

    # If no wps_services are known yet check for port 8090 to 8099
    if not WpsModel.objects.all():
        find_wps_service_engines()

    # If the wps engine cannot be found in the app_class, check settings for site-wide wps engines
    site_wps_services = WpsModel.objects.all()

    for site_wps_service in site_wps_services:

        # Create OWSLib WebProcessingService engine object
        wps = WebProcessingService(site_wps_service.endpoint,
                                   username=site_wps_service.username,
                                   password=site_wps_service.password,
                                   verbose=False,
                                   skip_caps=True)

        # Initialize the object with get capabilities call
        activated_wps = activate_wps(wps=wps,
                                     endpoint=site_wps_service.endpoint,
                                     name=site_wps_service.name)

        if activated_wps:
            wps_services_list.append(activated_wps)

    return wps_services_list
示例#30
0
    def __init__(self,
                 name,
                 url,
                 identifier,
                 inputs=None,
                 linked_inputs=None,
                 monitor=None,
                 progress_range=None,
                 headers=None,
                 **_):
        """
        :param name: task name
        :param url: url of the WPS provider
        :param identifier: identifier of the WPS task
        :param inputs: dict of static inputs for the wps
                       (multiple values can be passed for each key by using an array)
        :param linked_inputs: dict of dynamic inputs of the wps obtained from upstream tasks
                              (multiple values can be passed for each key by using an array)
        :param monitor: status and progress monitor
        :param progress_provider:
        :param progress_range: progress range of this task in the overall workflow
        :param headers: headers to be included in the wps call
        :param _: Accept any others parameters coming from the workflow description
        """
        ProgressMonitorPE.__init__(self, name, monitor)

        # Convert dict of values or array of values to a flat list of key, value tuple
        inputs = list(self.iter_inputs(inputs))
        linked_inputs = list(self.iter_inputs(linked_inputs))

        # Defaults argument (with mutable type)
        if not progress_range:
            progress_range = [0, 100]

        self.set_progress_provider(
            RangeProgress(progress_range[0], progress_range[1]))

        self.wps = WebProcessingService(url=url,
                                        skip_caps=True,
                                        verify=False,
                                        headers=headers)
        self.identifier = identifier
        self.proc_desc = self.wps.describeprocess(identifier)

        self._validate_inputs(inputs, linked_inputs)

        # These are the static inputs
        # (linked inputs will be appended to inputs just before execution by the _set_inputs function)
        self.static_inputs = inputs
        self.dynamic_inputs = []

        # Will be filled as PE are connected to us (by the get_output function)
        self.outputs = []

        for _input in linked_inputs:
            # Here we add PE input that will need to be connected
            if _input[0] not in self.inputconnections:
                self._add_input(_input[0])
            self._add_linked_input(_input[0], _input[1])
示例#31
0
def get_wps_service_engine(name, app_class=None):
    """
    Get a wps engine with the given name.

    Args:
      name (string): Name of the wps engine to retrieve.
      app_class (class, optional): The app class to include in the search for wps engines.

    Returns:
      (owslib.wps.WebProcessingService): A owslib.wps.WebProcessingService object.
    """
    # If the app_class is given, check it first for a wps engine
    app_wps_services = None

    if app_class and issubclass(app_class, TethysAppBase):
        # Instantiate app class and retrieve wps services list
        app = app_class()
        app_wps_services = app.wps_services()

    if app_wps_services:
        # Search for match
        for app_wps_service in app_wps_services:

            # If match is found, initiate engine object
            if app_wps_service.name == name:
                wps = WebProcessingService(app_wps_service.endpoint,
                                           username=app_wps_service.username,
                                           password=app_wps_service.password,
                                           verbose=False,
                                           skip_caps=True)

                return activate_wps(wps=wps,
                                    endpoint=app_wps_service.endpoint,
                                    name=app_wps_service.name)

    # If the wps engine cannot be found in the app_class, check database for site-wide wps engines
    site_wps_services = WpsModel.objects.all()

    if site_wps_services:
        # Search for match
        for site_wps_service in site_wps_services:

            # If match is found initiate engine object
            if site_wps_service.name == name:
                # Create OWSLib WebProcessingService engine object
                wps = WebProcessingService(site_wps_service.endpoint,
                                           username=site_wps_service.username,
                                           password=site_wps_service.password,
                                           verbose=False,
                                           skip_caps=True)

                # Initialize the object with get capabilities call
                return activate_wps(wps=wps,
                                    endpoint=site_wps_service.endpoint,
                                    name=site_wps_service.name)

    raise NameError(
        'Could not find wps service with name "{0}". Please check that a wps service with that name '
        'exists in the admin console or in your app.py.'.format(name))
示例#32
0
文件: pyGDP.py 项目: ocefpaf/pyGDP
 def __init__(self, WFS_URL=None):
     if WFS_URL == None:
         from pygdp.namespaces import WFS_URL
     wfsUrl = WFS_URL
     self.wfsUrl = wfsUrl
     self.wpsUrl = WPS_URL
     self.version = '1.1.0'
     self.wps = WebProcessingService(WPS_URL)
示例#33
0
 def __init__(self, wfs_url=WFS_URL):
     # if WFS_URL is None:
     #     from pygdp.namespaces import WFS_URL
     # wfsUrl = WFS_URL
     self.wfsUrl = wfs_url
     self.wpsUrl = WPS_URL
     self.version = '1.1.0'
     self.wps = WebProcessingService(self.wpsUrl)
示例#34
0
 def __init__(self, name=None, url=None, xml=None, **attrs):
     click.MultiCommand.__init__(self, name, **attrs)
     self.url = os.environ.get('WPS_SERVICE') or url
     self.verify = get_ssl_verify()
     self.xml = xml
     self.wps = WebProcessingService(self.url,
                                     verify=self.verify,
                                     skip_caps=True)
     self.commands = OrderedDict()
示例#35
0
 def _execute(self):
     url_execute = "http://localhost:{}/wps".format(self.port)
     inputs = get_inputs(self.job.wps_request.inputs)
     output = get_output(self.job.wps_request.outputs)
     wps = WPS(url=url_execute, skip_caps=True)
     self.execution = wps.execute(self.job.wps_request.identifier,
                                  inputs=inputs,
                                  output=output,
                                  mode=self.job.process.async_)
示例#36
0
def _executeRequest(processid,
                    inputs,
                    output,
                    verbose=True,
                    outputFilePath=None,
                    sleepSecs=10):
    """
    This function makes a call to the Web Processing Service with
    the specified user inputs.
    """
    wps = WebProcessingService(WPS_URL)

    execution = wps.execute(processid, inputs, output)

    sleepSecs = sleepSecs
    err_count = 1

    while execution.isComplete() == False:
        try:
            monitorExecution(execution, sleepSecs,
                             download=False)  # monitors for success
            err_count = 1
        except Exception:
            log.warning(
                'An error occurred while checking status, checking again. Sleeping %d seconds...'
                % sleepSecs)
            err_count += 1
            if err_count > WPS_attempts:
                raise Exception(
                    'The status document failed to return, status checking has aborted. There has been a network or server issue preventing the status document from being retrieved, the request may still be running. For more information, check the status url %s'
                    % execution.statusLocation)
            sleep(sleepSecs)

    if outputFilePath == None:
        outputFilePath = 'gdp_' + processid.replace(
            '.', '-') + '_' + strftime("%Y-%m-%dT%H-%M-%S-%Z")

    done = False
    err_count = 1
    while done == False:
        try:
            monitorExecution(execution, download=True, filepath=outputFilePath)
            done = True
        except Exception:
            log.warning(
                'An error occurred while trying to download the result file, trying again.'
            )
            err_count += 1
            sleep(sleepSecs)
            if err_count > WPS_attempts:
                raise Exception(
                    "The process completed successfully, but an error occurred while downloading the result. You may be able to download the file using the link at the bottom of the status document: %s"
                    % execution.statusLocation)

    _check_for_execution_errors(execution)

    return outputFilePath
示例#37
0
def _executeRequest(processid,
                    inputs,
                    output,
                    verbose=True,
                    outputFilePath=None,
                    sleepSecs=10):
    """
    This function makes a call to the Web Processing Service with
    the specified user inputs.
    """
    wps = WebProcessingService(WPS_URL)

    execution = wps.execute(processid, inputs, output)

    sleepSecs = sleepSecs
    err_count = 1

    while execution.isComplete() == False:
        try:
            monitorExecution(
                execution, sleepSecs, download=False)  # monitors for success
            err_count = 1
        except Exception:
            log.warning(
                'An error occurred while checking status, checking again. Sleeping %d seconds...'
                % sleepSecs)
            err_count += 1
            if err_count > WPS_attempts:
                raise Exception(
                    'The status document failed to return, status checking has aborted. There has been a network or server issue preventing the status document from being retrieved, the request may still be running. For more information, check the status url %s'
                    % execution.statusLocation)
            sleep(sleepSecs)

    if outputFilePath == None:
        outputFilePath = 'gdp_' + processid.replace(
            '.', '-') + '_' + strftime("%Y-%m-%dT%H-%M-%S-%Z")

    done = False
    err_count = 1
    while done == False:
        try:
            monitorExecution(execution, download=True, filepath=outputFilePath)
            done = True
        except Exception:
            log.warning(
                'An error occurred while trying to download the result file, trying again.'
            )
            err_count += 1
            sleep(sleepSecs)
            if err_count > WPS_attempts:
                raise Exception(
                    "The process completed successfully, but an error occurred while downloading the result. You may be able to download the file using the link at the bottom of the status document: %s"
                    % execution.statusLocation)

    _check_for_execution_errors(execution)

    return outputFilePath
示例#38
0
def test_wps_describeprocess_emu_all():
    # Initialize WPS client
    wps = WebProcessingService('http://localhost:8094/wps', skip_caps=True)
    # Execute fake invocation of DescribeProcess operation by parsing cached response from
    xml = open(resource_file('wps_EmuDescribeProcess_all.xml'), 'rb').read()
    process = wps.describeprocess('nap', xml=xml)
    processes = wps.describeprocess('all', xml=xml)
    assert isinstance(process, Process)
    assert isinstance(processes, list)
示例#39
0
def test_describe():
    """Check that owslib can parse the processes' description."""
    from owslib.wps import WebProcessingService

    wps = WebProcessingService(URL, skip_caps=True)
    client = client_for(Service(processes=processes))
    resp = client.get(service="wps",
                      request="getcapabilities",
                      version="1.0.0")
    wps.describeprocess("all", xml=resp.data)
示例#40
0
def execute_workflow(self, userid, url, workflow):
    registry = app.conf['PYRAMID_REGISTRY']
    db = mongodb(registry)

    # generate and run dispel workflow
    # TODO: fix owslib wps for unicode/yaml parameters
    logger.debug('workflow=%s', workflow)
    # using secure url
    workflow['worker']['url'] = secure_url(db, workflow['worker']['url'], userid)
    inputs=[('workflow', json.dumps(workflow))]
    logger.debug('inputs=%s', inputs)
    outputs=[('output', True), ('logfile', True)]
    
    wps = WebProcessingService(url=secure_url(db, url, userid), skip_caps=True, verify=False)
    worker_wps = WebProcessingService(url=workflow['worker']['url'], skip_caps=False, verify=False)
    execution = wps.execute(identifier='workflow', inputs=inputs, output=outputs)
    
    job = add_job(db, userid,
                  task_id = self.request.id,
                  is_workflow = True,
                  service = worker_wps.identification.title,
                  title = workflow['worker']['identifier'],
                  abstract = '',
                  status_location = execution.statusLocation)

    while execution.isNotComplete():
        try:
            execution.checkStatus(sleepSecs=3)
            job['status'] = execution.getStatus()
            job['status_message'] = execution.statusMessage
            job['is_complete'] = execution.isComplete()
            job['is_succeded'] = execution.isSucceded()
            job['progress'] = execution.percentCompleted
            duration = datetime.now() - job.get('created', datetime.now())
            job['duration'] = str(duration).split('.')[0]
            if execution.isComplete():
                job['finished'] = datetime.now()
                if execution.isSucceded():
                    for output in execution.processOutputs:
                        if 'output' == output.identifier:
                            result = yaml.load(urllib.urlopen(output.reference))
                            job['worker_status_location'] = result['worker']['status_location']
                    job['progress'] = 100
                    log(job)
                else:
                    job['status_message'] = '\n'.join(error.text for error in execution.errors)
                    for error in execution.errors:
                        log_error(job, error)
            else:
                log(job)
        except:
            logger.exception("Could not read status xml document.")
        else:
            db.jobs.update({'identifier': job['identifier']}, job)
    return execution.getStatus()
def test_wps_getcapabilities_ceda():
    # Initialize WPS client
    wps = WebProcessingService('http://ceda-wps2.badc.rl.ac.uk/wps', skip_caps=True)

    # Execute fake invocation of GetCapabilities operation by parsing cached response from USGS service
    xml = open(resource_file('wps_CEDACapabilities.xml'), 'rb').read()
    wps.getcapabilities(xml=xml)

    # Check WPS description
    assert wps.identification.type == 'WPS'
    assert wps.identification.title == 'WPS Pylons Test Server'
    assert wps.identification.abstract is None

    # Check available operations
    operations = [op.name for op in wps.operations]
    assert operations == [
        'GetCapabilities',
        'DescribeProcess',
        'Execute']

    # Check high level process descriptions
    processes = [(p.identifier, p.title) for p in wps.processes]
    assert processes == [
        ('CDMSSubsetVariable', 'Writes a text file and returns an output.'),
        ('NCDumpIt', 'Calls ncdump on the input file path and writes it to an output file.'),
        ('TestDap', 'Writes a text file and returns an output.'),
        ('CDMSDescribeVariableDomain', 'Writes a text file and returns an output.'),
        ('CFCheck', 'Writes a text file and returns an output.'),
        ('DoubleIt', 'Doubles the input number and returns value'),
        ('SimplePlot', 'Creates a simple map plot.'),
        ('CDMSListDatasets', 'Writes a text file and returns an output.'),
        ('CDMSListVariables', 'Writes a text file and returns an output.'),
        ('WCSWrapper', 'Web Coverage Service Wrapper Process'),
        ('GetWeatherStations', 'Writes a text file with one weather station per line'),
        ('ListPPFileHeader', 'Writes a text file that contains a listing of pp-records in a file.'),
        ('TakeAges', 'A test process to last a long time.'),
        ('CMIP5FileFinder', 'Writes a test file of matched CMIP5 files.'),
        ('SubsetPPFile', 'Filters a PP-file to generate a new subset PP-file.'),
        ('ExtractUKStationData', 'ExtractUKStationData'),
        ('CDOWrapper1', 'Writes a text file and returns an output.'),
        ('MMDNCDiff', 'MMDNCDiff'),
        ('PlotRotatedGrid', 'Creates a plot - to show we can plot a rotated grid.'),
        ('MMDAsync', 'Writes a text file and returns an output.'),
        ('MashMyDataMultiplier', 'Writes a text file and returns an output.'),
        ('Delegator', 'Writes a text file and returns an output.'),
        ('ExArchProc1', 'Writes a text file and returns an output.'),
        ('CDOShowInfo', 'Writes a text file and returns an output.'),
        ('PostTest', 'Writes a text file and returns an output.'),
        ('StatusTestProcess', 'An process to test status responses'),
        ('WaitForFileDeletionCached', 'An asynchronous job that waits for a file to be deleted'),
        ('WaitForAllFilesToBeDeleted', 'An asynchronous job that waits for a number of files to be deleted'),
        ('AsyncTest', 'Does an asynchronous test job run'),
        ('SyncTest1', 'Just creates a file.'),
        ('WaitForFileDeletion', 'An asynchronous job that waits for a file to be deleted'),
        ('ProcessTemplate', 'Writes a text file and returns an output.')]
示例#42
0
def get_capabilities(wps_host=None, wps_client=None, version='1.0.0'):
    if wps_host:
        return WebProcessingService(wps_host, version)
    else:
        response = wps_client.get(
            '?service=WPS&request=GetCapabilities&version={0}'.format(version))
        wps_reader = WPSReader()
        element = wps_reader.readFromString(response.get_data())
        wps = WebProcessingService(None, version, skip_caps=True)
        wps._parseCapabilitiesMetadata(element)
        return wps
示例#43
0
def get_capabilities(wps_host=None, wps_client=None, version='1.0.0'):
    if wps_host:
        return WebProcessingService(wps_host, version)
    else:
        response = wps_client.get(
            '?service=WPS&request=GetCapabilities&version={0}'.format(version))
        wps_reader = WPSReader()
        element = wps_reader.readFromString(response.get_data())
        wps = WebProcessingService(None, version, skip_caps=True)
        wps._parseCapabilitiesMetadata(element)
        return wps
def run_wps(process_id,input,output):

    #choose the first wps engine
    #my_engine = WebProcessingService('http://appsdev.hydroshare.org:8282/wps/WebProcessingService', verbose=False, skip_caps=True)
    my_engine = WebProcessingService('http://appsdev.hydroshare.org:8282/wps/WebProcessingService',verbose=False, skip_caps=True)
    my_engine.getcapabilities()
    #wps_engines = list_wps_service_engines()
    #my_engine = wps_engines[0]
    #choose the r.time-series-converter
    my_process = my_engine.describeprocess(process_id)

    my_inputs = my_process.dataInputs
    input_names = [] #getting list of input
    for input1 in my_inputs:
        input_names.append(input1)
    #executing the process..
    execution = my_engine.execute(process_id, input, output)
    request = execution.request
    #set store executeresponse to false
    request = request.replace('storeExecuteResponse="true"', 'storeExecuteResponse="false"')

    url_wps = 'http://appsdev.hydroshare.org:8282/wps/WebProcessingService'

    wps_request = urllib2.Request(url_wps,request)
    wps_open = urllib2.urlopen(wps_request)
    wps_read = wps_open.read()



    if 'href' in wps_read:
        tag = 'href="'
        location = wps_read.find(tag)

        new= wps_read[location+len(tag):len(wps_read)]
        tag2 = '"/>\n    </wps:Output>\n  </wps:ProcessOutputs>\n</wps:'
        location2 = new.find(tag2)
        final = new[0:location2]
        split = final.split()
        wps_request1 = urllib2.Request(split[0])

        wps_open1 = urllib2.urlopen(wps_request1)
        wps_read1 = wps_open1.read()

    #now we must use our own method to send the request1
    #we need to use the request
    #this code is for the normal wps which is not working right now
    # monitorExecution(execution)
    # output_data = execution.processOutputs
    # final_output_url = output_data[0].reference
    # final_data = read_final_data(final_output_url)

    #return [final_output_url, final_data]
    return [wps_read1, split]
示例#45
0
def describe_process(identifier, wps_host=None, wps_client=None,
                     version='1.0.0'):
    if wps_host:
        wps = WebProcessingService(wps_host, version)
        return wps.describeprocess(identifier)
    else:
        response = wps_client.get(
            ('?service=WPS&request=DescribeProcess&version={0}&'
             'identifier={1}').format(version, identifier))
        wps_reader = WPSReader()
        element = wps_reader.readFromString(response.get_data())
        wps = WebProcessingService(None, version, skip_caps=True)
        return wps._parseProcessMetadata(element)
示例#46
0
    def _executeRequest(self, processid, inputs, output, verbose):
        """
        This function makes a call to the Web Processing Service with
        the specified user inputs.
        """
        wps = WebProcessingService(WPS_URL)

        old_stdout = sys.stdout
        # create StringIO() for listening to print
        result = StringIO()
        if not verbose: # redirect standard output
            sys.stdout = result
        
        execution = wps.execute(processid, inputs, output)
        
        sleepSecs=10
        err_count=1
        
        while execution.isComplete()==False:
            try:
                monitorExecution(execution, sleepSecs, download=False) # monitors for success
                err_count=1
            except Exception:
                print 'An error occurred while checking status, checking again.'
                print 'Sleeping %d seconds...' % sleepSecs
                err_count+=1
                if err_count > WPS_attempts:
                    raise Exception('The status document failed to return, status checking has aborted. There has been a network or server issue preventing the status document from being retrieved, the request may still be running. For more information, check the status url %s' % execution.statusLocation)
                sleep(sleepSecs)
    
        # redirect standard output after successful execution
        sys.stdout = result
        done=False
        err_count=1
        while done==False:
            try: 
                monitorExecution(execution, download=True)
                done=True
            except Exception:
                print 'An error occurred while trying to download the result file, trying again.'
                err_count+=1
            if err_count > WPS_attempts:        
                raise Exception("The process completed successfully, but an error occurred while downloading the result. You may be able to download the file using the link at the bottom of the status document: %s" % execution.statusLocation)
            sleep(sleepSecs)
            
        result_string = result.getvalue()
        output = result_string.split('\n')
        tmp = output[len(output) - 2].split(' ')  
        sys.stdout = old_stdout
        return tmp[len(tmp)-1]
示例#47
0
def run_wps(res_ids,gap):

    if (gap ==''):
        gap = "linear"

    # checks if there is two resource IDs
    resources = res_ids.split("_")

    process_id = 'org.n52.wps.server.r.series_gap_filler_3'
    process_input = [('resource_id',str(resources[0])),('fill_function',str(gap))]

    #setting the WPS URL is set in app.py
    url_wps = GapFillerTool.wps_url + '/WebProcessingService'
    my_engine = WebProcessingService(url_wps, verbose=False, skip_caps=True)
    my_process = my_engine.describeprocess(process_id)

    #executing the process..
    # build execution

    execution = WPSExecution(version=my_engine.version, url=my_engine.url, username=my_engine.username,
                             password=my_engine.password, verbose=my_engine.verbose)

    requestElement = execution.buildRequest(process_id, process_input, 'output')

    request = etree.tostring(requestElement)
    #set store executeresponse to false

    request = request.replace('storeExecuteResponse="true"', 'storeExecuteResponse="false"')

    execution = my_engine.execute(process_id, process_input, 'output', request)

    monitorExecution(execution)

    status = execution.status


    # if the status is successful...
    if status == 'ProcessSucceeded':
        outputs = execution.processOutputs
        output0 = outputs[0]
        reference0 = output0.reference

        # retrieve the data from the reference
        output_data = requests.get(reference0)
        resp = HttpResponse(output_data, content_type="application/json")

        return resp

    else:
        return JsonResponse({'status': 'wps request failed'})
示例#48
0
def capabilities_helper():
    '''An example template helper function.'''
    # Just return some example text.
    import urllib2
    import owslib.wps
    from owslib.wps import WebProcessingService, monitorExecution
    response = urllib2.urlopen(str(plugins.toolkit.c.resource['origin_url']))
    tmp=response.read()
    wps=WebProcessingService(str(plugins.toolkit.c.resource['origin_url']))
    #wps.getcapabilities(tmp)
    wps.processes1=wps.processes#[:len(wps.processes)/2]
    wps.provider.contact.keys=dir(wps.provider.contact)
    wps.resource=plugins.toolkit.c.resource
    wps.package=plugins.toolkit.c.package
    return wps
示例#49
0
 def __init__(self, request):
     self.wps_id = request.params.get('wps')
     self.wps = WebProcessingService(url=wps_url(request, self.wps_id), verify=False)
     identifier = request.params.get('process')
     # TODO: need to fix owslib to handle special identifiers
     self.process = self.wps.describeprocess(identifier)
     super(ExecuteProcess, self).__init__(request, name='processes_execute', title='')
示例#50
0
class ExecuteProcess(Processes):
    def __init__(self, request):
        self.wps_id = request.params.get("wps")
        self.wps = WebProcessingService(url=wps_url(request, self.wps_id))
        identifier = request.params.get("process")
        # TODO: need to fix owslib to handle special identifiers
        self.process = self.wps.describeprocess(identifier)
        super(ExecuteProcess, self).__init__(request, name="processes_execute", title="")

    def breadcrumbs(self):
        breadcrumbs = super(ExecuteProcess, self).breadcrumbs()
        route_path = self.request.route_path("processes_list", _query=[("wps", self.wps_id)])
        breadcrumbs.append(dict(route_path=route_path, title=self.wps.identification.title))
        breadcrumbs.append(dict(route_path=self.request.route_path(self.name), title=self.process.title))
        return breadcrumbs

    def appstruct(self):
        return {}

    def generate_form(self, formid="deform"):
        from phoenix.schema.wps import WPSSchema

        schema = WPSSchema(process=self.process, user=self.get_user())
        return Form(schema, buttons=("submit",), formid=formid)

    def process_form(self, form):
        controls = self.request.POST.items()
        try:
            appstruct = form.validate(controls)
            self.execute(appstruct)
        except ValidationFailure, e:
            logger.exception("validation of exectue view failed.")
            self.session.flash("There are errors on this page.", queue="danger")
            return dict(description=getattr(self.process, "abstract", ""), form=e.render())
        return HTTPFound(location=self.request.route_url("monitor"))
示例#51
0
class ComplexInputs(Wizard):
    def __init__(self, request):
        super(ComplexInputs, self).__init__(
            request, name='wizard_complex_inputs',
            title="Choose Input Parameter")
        from owslib.wps import WebProcessingService
        self.wps = WebProcessingService(wps_url(request, self.wizard_state.get('wizard_wps')['identifier']), verify=False)
        self.process = self.wps.describeprocess(self.wizard_state.get('wizard_process')['identifier'])
        self.title = "Choose Input Parameter of {0}".format(self.process.title)

    def breadcrumbs(self):
        breadcrumbs = super(ComplexInputs, self).breadcrumbs()
        breadcrumbs.append(dict(route_path=self.request.route_path(self.name), title=self.title))
        return breadcrumbs

    def schema(self):
        return Schema().bind(process=self.process)

    def success(self, appstruct):
        for input in self.process.dataInputs:
            if input.identifier == appstruct.get('identifier'):
                appstruct['mime_types'] = [value.mimeType for value in input.supportedValues]
        super(ComplexInputs, self).success(appstruct)

    def next_success(self, appstruct):
        self.success(appstruct)
        return self.next('wizard_source')

    @view_config(route_name='wizard_complex_inputs', renderer='../templates/wizard/default.pt')
    def view(self):
        return super(ComplexInputs, self).view()
示例#52
0
文件: base.py 项目: bird-house/birdy
 def __init__(self, name=None, url=None, xml=None, **attrs):
     click.MultiCommand.__init__(self, name, **attrs)
     self.url = os.environ.get('WPS_SERVICE') or url
     self.verify = get_ssl_verify()
     self.xml = xml
     self.wps = WebProcessingService(self.url, verify=self.verify, skip_caps=True)
     self.commands = OrderedDict()
def test_wps_execute_invalid_request():
    # Initialize WPS client
    wps = WebProcessingService('http://cida.usgs.gov/gdp/process/WebProcessingService')

    # Submit fake invocation of Execute operation using cached HTTP request and response
    request = open(resource_file('wps_USGSExecuteInvalidRequest.xml'), 'rb').read()
    response = open(resource_file('wps_USGSExecuteInvalidRequestResponse.xml'), 'rb').read()
    execution = wps.execute(None, [], request=request, response=response)

    assert execution.isComplete() is True

    # Display errors
    ex = execution.errors[0]
    assert ex.code is None
    assert ex.locator is None
    assert ex.text == 'Attribute null not found in feature collection'
示例#54
0
 def __init__(self, request):
     self.wps_id = request.params.get("wps")
     self.wps = WebProcessingService(url=wps_url(request, self.wps_id))
     identifier = request.params.get("process")
     # TODO: need to fix owslib to handle special identifiers
     self.process = self.wps.describeprocess(identifier)
     super(ExecuteProcess, self).__init__(request, name="processes_execute", title="")