示例#1
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))
示例#2
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)
示例#3
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))
示例#4
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
示例#5
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)
示例#6
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)   
示例#7
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]
示例#8
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
示例#9
0
def run_wps(timeseries_url):

    #choose the first wps engine
    wps_engines = list_wps_service_engines()
    my_engine = wps_engines[0]

    #choose the r.time-series-converter
    process_id = 'org.n52.wps.server.r.time-series-converter'
    my_process = my_engine.describeprocess(process_id)
    my_inputs = my_process.dataInputs

    input_names = []
    for input in my_inputs:
        input_names.append(input)


    input_url = timeseries_url
    inputs = [ ("url", input_url), ("interval", "daily"), ("stat", "median")]

    #executing the process..
    output = "output"
    execution = my_engine.execute(process_id, inputs, output)

    #checking the status...
    #monitorExecution will run until the process is completed...
    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]
示例#10
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)) 
示例#11
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
示例#12
0
def test_execute_restflow():
    global NODES

    my_wps = wps.get_wps(base.SERVICE)
    
    execution = wps.execute_restflow(my_wps, NODES)
    monitorExecution(execution, sleepSecs=1)
    result = execution.processOutputs[0].reference
    ok_('wpsoutputs' in result, result)
示例#13
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
示例#14
0
文件: conftest.py 项目: roocs/rook
 def execute(self, identifier, inputs):
     outputs = [("output", True, None)]
     execution = self.wps.execute(identifier, inputs, output=outputs)
     monitorExecution(execution)
     print(execution.errors)
     assert execution.isSucceded() is True
     assert len(execution.processOutputs) > 0
     ml_url = execution.processOutputs[0].reference
     xml = requests.get(ml_url).text
     urls = parse_metalink(xml)
     return urls
示例#15
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]
示例#16
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'})
def run_wps(res_ids):
    print"launch wps"
    print res_ids
    # checks if there is two resource IDs
    resources = res_ids.split("_")
    if len(resources) < 2:
        return JsonResponse({'status': 'wps request failed. 2 resources are required, found ' + str(len(resources))})

    process_id = 'org.n52.wps.server.r.linear_regression'
    process_input = [('x_resource_id',str(resources[0])),('y_resource_id',str(resources[1]))]

    #setting the WPS URL is set in app.py
    url_wps = CorrelationPlot.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"')
    print request

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

    monitorExecution(execution)
    status = execution.status
    print 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'})
示例#18
0
def flyGssha(link,resultsFile):
    '''
    This function submits the link to the zipped GSSHA file and gets the result
    '''
    wps = WebProcessingService('http://ci-water.byu.edu:9999/wps/WebProcessingService', verbose=False, skip_caps=True)

    processid = 'rungssha'
    inputs = [('url', link)]
    output = "outputfile"
    execution = wps.execute(processid, inputs, output)
    monitorExecution(execution)

    print "Pre-execution"

    result = execution.getOutput(resultsFile)

    print "GSSHA has taken off!"
示例#19
0
def run_sc(request):

    message = ""

    try:
        if request.POST:
            outlet_x = request.POST.get("outlet_x", None)
            outlet_y = request.POST.get("outlet_y", None)
            dam_height = request.POST.get("dam_height", None)
            watershed_geojson = request.POST.get("watershed_geojson", None)

            # Run reservoircalculation service
            #wps = WebProcessingService('https://tethys-staging.byu.edu/tethys_wps/?', verbose=False)
            wps = WebProcessingService('http://127.0.0.1:8000/tethys_wps/?', verbose=False)

            processid = 'reservoircalculationprocess'

            inputs=[("point_x",outlet_x),
                    ("point_y",outlet_y),
                    ("water_level", dam_height),
                    ("max_boundary", watershed_geojson)]

            execution = wps.execute(processid, inputs, output="lake_volume")
            monitorExecution(execution)
            # extract watershed geojson
            lake_GEOJSON =  execution.processOutputs[1].data[0]
            lake_volume = execution.processOutputs[0].data[0]
            status = execution.status

            # Check results
            if lake_GEOJSON is not None:
                message += str(status)
            else:
                message += str(status)
        else:
            raise Exception("Please call this service in a POST request.")

    except Exception as ex:
        message = ex.message

    return JsonResponse({"lake_GEOJSON":lake_GEOJSON,
                        "lake_volume":lake_volume,
                        "message":message})
示例#20
0
def flyGssha(link, resultsFile):
    '''
    This function submits the link to the zipped GSSHA file and gets the result
    '''
    wps = WebProcessingService(
        'http://ci-water.byu.edu:9999/wps/WebProcessingService',
        verbose=False,
        skip_caps=True)

    processid = 'rungssha'
    inputs = [('url', link)]
    output = "outputfile"
    execution = wps.execute(processid, inputs, output)
    monitorExecution(execution)

    print "Pre-execution"

    result = execution.getOutput(resultsFile)

    print "GSSHA has taken off!"
示例#21
0
def esgf_logon(self, userid, url, openid, password):
    registry = app.conf['PYRAMID_REGISTRY']
    inputs = []
    inputs.append( ('openid', openid.encode('ascii', 'ignore')) )
    inputs.append( ('password', password.encode('ascii', 'ignore')) )
    outputs = [('output',True),('expires',False)]

    wps = WebProcessingService(url=url, skip_caps=True)
    execution = wps.execute(identifier="esgf_logon", inputs=inputs, output=outputs)
    monitorExecution(execution)
    
    if execution.isSucceded():
        credentials = execution.processOutputs[0].reference
        cert_expires = execution.processOutputs[1].data[0]
        db = mongodb(registry)
        user = db.users.find_one({'identifier':userid})
        user['credentials'] = credentials
        user['cert_expires'] = cert_expires
        db.users.update({'identifier':userid}, user)
    return execution.status
示例#22
0
def run_wd(request):

    message = ""

    try:
        if request.GET:
            xlon = request.GET.get("xlon", None)
            ylat = request.GET.get("ylat", None)

            # Run watersheddelineationprocess service
            #wps = WebProcessingService('https://tethys-staging.byu.edu/tethys_wps/?', verbose=False)
            wps = WebProcessingService('http://127.0.0.1:8000/tethys_wps/?', verbose=False)

            processid = 'watersheddelineationprocess'

            inputs=[("outlet_x",xlon),
                    ("outlet_y",ylat)]

            execution = wps.execute(processid, inputs, output="message")
            monitorExecution(execution)
            # extract watershed geojson
            watershed_GEOJSON =  execution.processOutputs[1].data[0]
            snappoint_GEOJSON = execution.processOutputs[2].data[0]
            status = execution.status

            # Check results
            if watershed_GEOJSON is not None:
                message += str(status)
            else:
                message += str(status)
        else:
            raise Exception("Please call this service in a GET request.")

    except Exception as ex:
        message = ex.message
        print ex
        print ex.message

    return JsonResponse({"watershed_GEOJSON":watershed_GEOJSON,
                        "snappoint_GEOJSON":snappoint_GEOJSON,
                        "message":message})
示例#23
0
文件: pyGDP.py 项目: prog556/pyGDP
 def uploadShapeFile(self, 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 = self._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", "")
     
     
     # check to make sure a file with the same name does not exist
     fileCheckString = "upload:" + filename
     shapefiles = self.getShapefiles()
     if fileCheckString in shapefiles:
         print 'File exists already.'
         return
     
     xmlGen = gdpXMLGenerator()
     root = xmlGen.getUploadXMLtree(filename, upload_URL, filedata)
     
     # now we have a complete XML upload request
     uploadRequest = etree.tostring(root)
     POST = WebProcessingService(WPS_Service)
     execution = POST.execute(None, [], request=uploadRequest)
     monitorExecution(execution)
     return "upload:"+filename
示例#24
0
    def uploadShapeFile(self, 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 = self._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", "")

        # check to make sure a file with the same name does not exist
        fileCheckString = "upload:" + filename
        shapefiles = self.getShapefiles()
        if fileCheckString in shapefiles:
            print 'File exists already.'
            return

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

        # now we have a complete XML upload request
        uploadRequest = etree.tostring(root)
        POST = WebProcessingService(WPS_Service)
        execution = POST.execute(None, [], request=uploadRequest)
        monitorExecution(execution)
        return "upload:" + filename
示例#25
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)) 
示例#26
0
    ("TIME_START", "2010-01-01T00:00:00.000Z"),
    ("TIME_END", "2011-01-01T00:00:00.000Z"),
    ("REQUIRE_FULL_COVERAGE", "false"), ("DELIMITER", "COMMA"),
    ("STATISTICS", "MEAN"), ("GROUP_BY", "STATISTIC"),
    ("SUMMARIZE_TIMESTEP", "false"), ("SUMMARIZE_FEATURE_ATTRIBUTE", "false"),
    ("FEATURE_COLLECTION", featureCollection)
]
output = "OUTPUT"
execution = wps.execute(processid, inputs, output="OUTPUT")
# alternatively, submit a pre-made request specified in an XML file
#request = open('../tests/wps_USGSExecuteRequest1.xml','r').read()
#execution = wps.execute(None, [], request=request)

# The monitorExecution() function can be conveniently used to wait for the process termination
# It will eventually write the process output to the specified file, or to the file specified by the server.
monitorExecution(execution)
'''    
# 3b) Execute
# Submits an HTTP POST "Execute" process request to the WPS service, keeps checking the status of the request,
# and retrieves the output once the request terminates successfully (displaying any errors if found).
# This request uses a FEATURE_COLLECTION input defined as a GML (lat, lon) polygon.

polygon = [(-102.8184, 39.5273), (-102.8184, 37.418), (-101.2363, 37.418), (-101.2363, 39.5273), (-102.8184, 39.5273)]
featureCollection = GMLMultiPolygonFeatureCollection( [polygon] )
processid = 'gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm'
inputs =  [ ("FEATURE_ATTRIBUTE_NAME","the_geom"),
            ("DATASET_URI", "dods://igsarm-cida-thredds1.er.usgs.gov:8080/thredds/dodsC/dcp/conus_grid.w_meta.ncml"),
            ("DATASET_ID", "ccsm3_a1b_tmax"),
            ("TIME_START","1960-01-01T00:00:00.000Z"),
            ("TIME_END","1960-12-31T00:00:00.000Z"),
            ("REQUIRE_FULL_COVERAGE","true"),
示例#27
0
elif request == "DescribeProcess":
    if identifier is None:
        print('\nERROR: missing mandatory "-i (or --identifier)" argument')
        usage()
        sys.exit(4)
    process = wps.describeprocess(identifier)
    print("WPS Process: identifier=%s" % process.identifier)
    print("WPS Process: title=%s" % process.title)
    print("WPS Process: abstract=%s" % process.abstract)
    for input in process.dataInputs:
        print(
            "Process input: identifier=%s, data type=%s, minOccurs=%d, maxOccurs=%d"
            % (input.identifier, input.dataType, input.minOccurs, input.maxOccurs)
        )
    for output in process.processOutputs:
        print("Process output: identifier=%s, data type=%s" % (output.identifier, output.dataType))

elif request == "Execute":
    if xml is None:
        print('\nERROR: missing mandatory "-x (or --xml)" argument')
        usage()
        sys.exit(5)
    execution = wps.execute(None, [], request=xml)
    monitorExecution(execution)

else:
    print("\nERROR: Unknown request type")
    usage()
    sys.exit(6)
示例#28
0
    """
    wps = WebProcessingService(WPS_URL, verbose=verbose)

    if async:
        # Return the execution object. This can be monitored via user-supplied code
        return wps.execute(processid, inputs, output)
    else:
        # Blocks waiting for the execution to complete and then returns the file path to the results
        execution = wps.execute(processid, inputs, output)

        # sleepSecs = sleepSecs
        err_count = 1

        while not execution.isComplete():
            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 {} seconds...'.format(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 {}'.format(execution.statusLocation))
                # sleep(sleepSecs)    # monitorExecution calls checkStatus which handles the sleeping

        # Check for any problems with the execution result
        _check_for_execution_errors(execution)
示例#29
0
	def execute(self):
		Outputs={}
		sys.stdout = open(config.getConfigValue("server","logFile"),'w') 
		try:
			wps = WebProcessingService('http://localhost/cgi-bin/pywps.cgi', verbose=True, skip_caps=True)
			identifier = 'dummyprocess' 
			description = wps.describeprocess(identifier)
			wps_outputs=[]
			for item in description.processOutputs:
				if item.dataType == 'ComplexOutput':
					wps_outputs.append((item.identifier, True))
				else: wps_outputs.append((item.identifier, False))
			inputs = [('i1',str(self.Input1.getValue())),('i2',str(self.Input2.getValue())),('i3',str(self.Input3.getValue()))]
			execution = wps.execute(identifier, inputs, output=wps_outputs)
			monitorExecution(execution)
			execution.checkStatus(sleepSecs=1)
			Outputs['dummyprocess_1']={}
			if "ComplexData" in description.processOutputs:
				i=0
				for output in execution.processOutputs:
					if description.processOutputs[i].dataType == 'ComplexData':
						Outputs['dummyprocess_1'][output.identifier]=output.reference 
					else: Outputs['dummyprocess_1'][output.identifier]=output.data[0] 
					i=i+1
			else:
				for output in execution.processOutputs:
					Outputs['dummyprocess_1'][output.identifier]=output.data[0] 
			x= Outputs['dummyprocess_1' ]['output1']
		except:
			wps = WebProcessingService('http://localhost/cgi-bin/pywps.cgi', verbose=True, skip_caps=True)
			identifier = 'dummyprocess' 
			description = wps.describeprocess(identifier)
			wps_outputs=[]
			for item in description.processOutputs:
				if item.dataType == 'ComplexOutput':
					wps_outputs.append((item.identifier, True))
				else: wps_outputs.append((item.identifier, False))
			inputs = [('i1',str(self.Input1.getValue())),('i2',str(self.Input2.getValue())),('i3',str(self.Input3.getValue()))]
			execution = wps.execute(identifier, inputs, output=wps_outputs)
			monitorExecution(execution)
			execution.checkStatus(sleepSecs=1)
			Outputs['dummyprocess_1']={}
			if "ComplexData" in description.processOutputs:
				i=0
				for output in execution.processOutputs:
					if description.processOutputs[i].dataType == 'ComplexData':
						Outputs['dummyprocess_1'][output.identifier]=output.reference 
					else: Outputs['dummyprocess_1'][output.identifier]=output.data[0] 
					i=i+1
			else:
				for output in execution.processOutputs:
					Outputs['dummyprocess_1'][output.identifier]=output.data[0] 
			x= Outputs['dummyprocess_1' ]['output1']
		try:
			wps = WebProcessingService('http://localhost/cgi-bin/pywps.cgi', verbose=True, skip_caps=True)
			identifier = 'dummyprocess' 
			description = wps.describeprocess(identifier)
			wps_outputs=[]
			for item in description.processOutputs:
				if item.dataType == 'ComplexOutput':
					wps_outputs.append((item.identifier, True))
				else: wps_outputs.append((item.identifier, False))
			inputs = [('i1',Outputs['dummyprocess_1']['output1']),('i2',x),('i3',Outputs['dummyprocess_1']['output2'])]
			execution = wps.execute(identifier, inputs)
			Outputs['dummyprocess_2']={}
			if "ComplexData" in description.processOutputs:
				i=0
				for output in execution.processOutputs:
					if description.processOutputs[i].dataType == 'ComplexData':
						Outputs['dummyprocess_2'][output.identifier]=output.reference 
					else: Outputs['dummyprocess_2'][output.identifier]=output.data[0] 
					i=i+1
			else:
				for output in execution.processOutputs:
					Outputs['dummyprocess_2'][output.identifier]=output.data[0] 
		except:
			wps = WebProcessingService('http://localhost/cgi-bin/pywps.cgi', verbose=True, skip_caps=True)
			identifier = 'dummyprocess' 
			description = wps.describeprocess(identifier)
			wps_outputs=[]
			for item in description.processOutputs:
				if item.dataType == 'ComplexOutput':
					wps_outputs.append((item.identifier, True))
				else: wps_outputs.append((item.identifier, False))
			inputs = [('i1',Outputs['dummyprocess_1']['output1']),('i2',x),('i3',Outputs['dummyprocess_1']['output2'])]
			execution = wps.execute(identifier, inputs)
			Outputs['dummyprocess_2']={}
			if "ComplexData" in description.processOutputs:
				i=0
				for output in execution.processOutputs:
					if description.processOutputs[i].dataType == 'ComplexData':
						Outputs['dummyprocess_2'][output.identifier]=output.reference 
					else: Outputs['dummyprocess_2'][output.identifier]=output.data[0] 
					i=i+1
			else:
				for output in execution.processOutputs:
					Outputs['dummyprocess_2'][output.identifier]=output.data[0] 
		self.dummyprocess_1_output1.setValue(Outputs['dummyprocess_1']['output1'])
		self.dummyprocess_2_output2.setValue(Outputs['dummyprocess_2']['output2'])
		self.x.setValue(x)
		sys.stdout.close()
		sys.stdout = sys.__stdout__
		return
示例#30
0
wps = WebProcessingService(
    'https://riesgos.52north.org/wps/WebProcessingService',
    verbose=False,
    skip_caps=True)

processid = 'org.n52.wps.python.algorithm.QuakeMLProcess'
inputs = [("lonmin", "288"), ("lonmax", "292"), ("latmin", "-70"),
          ("latmax", "-10"), ("mmin", "6.6"), ("mmax", "8.5"), ("zmin", "5"),
          ("zmax", "140"), ("p", "0.1"), ("etype", "deaggregation"),
          ("tlon", "-71.5730623712764"), ("tlat", "-33.1299174879672")]
output = "selected-rows"
execution = wps.execute(processid, inputs, output)

from owslib.wps import monitorExecution
monitorExecution(execution)

print(execution.processOutputs[0].reference)

from owslib.wps import ComplexDataInput
quakeMLInput = ComplexDataInput(value=execution.processOutputs[0].reference)

quakeMLInput.schema = "http://quakeml.org/xmlns/quakeml/1.2/QuakeML-1.2.xsd"
quakeMLInput.mimeType = "text/xml"

processid2 = 'org.n52.wps.python.algorithm.ShakemapProcess'
inputs2 = [("quakeml-input", quakeMLInput)]
output2 = "shakemap-output"
execution2 = wps.execute(processid2, inputs2, output2)

monitorExecution(execution2)
示例#31
0
def execute(context, data_dict):
    """Run Execute request from a WPS ressource.
    :param id: the WPS resource
    :type id: string
    :returns: the execute outputs
    :rtype: dict or None
    """
    #toolkit.check_access("ckanext_deadoralive_get", context, data_dict)
    # TODO: Validation.
    #resource_id = data_dict["resource_id"]
    res = toolkit.get_action("resource_show")(context=context,
                                            data_dict=data_dict)
    log.info(res)
    import urllib2
    import owslib.wps
    from owslib.etree import etree
    from owslib.ows import DEFAULT_OWS_NAMESPACE
    from owslib.util import (testXMLValue, build_get_url, dump, getTypedValue,
        getNamespace, nspath, openURL, nspath_eval)
    from owslib.namespaces import Namespaces
    
    n = Namespaces()
    
    def get_namespaces():
        ns = n.get_namespaces(["ogc","wfs","wps","gml","xsi","xlink"])
        ns[None] = n.get_namespace("wps")
        ns["ows"] = DEFAULT_OWS_NAMESPACE
        return ns

    namespaces = get_namespaces()

    class CKANStaticFeatureCollection(owslib.wps.WFSFeatureCollection):
        def __init__(self,url):
            self.url = url
        def getXml(self):
            root = etree.Element(nspath_eval('wps:Reference', namespaces), attrib = { nspath_eval("xlink:href",namespaces) : self.url, "mimeType" : "text/xml"} )
            return root

    class CKANStaticValues(owslib.wps.WFSFeatureCollection):
        def __init__(self,url):
            self.url = url
        def getXml(self):
            root = etree.Element(nspath_eval('wps:Reference', namespaces), attrib = { nspath_eval("xlink:href",namespaces) : self.url, "mimeType" : "text/xml"} )
            return root
        
    response = urllib2.urlopen(res['url'])
    tmp=response.read()
    wps=owslib.wps.WebProcessingService(str(res['url']))
    #wps.getcapabilities(tmp)
    for i in wps.operations:
        if i.name=="Execute":
            wps1=owslib.wps.WebProcessingService(i.methods["Post"]["url"],verbose=True)
            break
    inputs=[]
    j=0
    for i in data_dict.keys():
        if i[:3]=="ir_":
            res=toolkit.get_action("resource_show")(context=context,
                                                    data_dict={"id": data_dict[i]})
            inputs+=[(i.replace("ir_",""), CKANStaticFeatureCollection(res['url']))]
        if i[:2]=="i_":
            inputs+=[(i.replace("i_",""), str(data_dict[i]))]
        j+=1
    try:
        final_res=wps1.execute(data_dict["p"],inputs,output=[(data_dict["out"],True)])
        if data_dict.has_key("async") and data_dict["async"]=="true":
            final_res={"reference": final_res.statusLocation,"status": final_res.statusMessage}
        else:
            from owslib.wps import monitorExecution
            monitorExecution(final_res)
            final_res={"reference": final_res.processOutputs[0].reference,"status": final_res.statusMessage,"keys":res.keys()}
    except Exception,e:
        final_res={"error": str(e),"response":"None"}
        return final_res