File: wps-client.py

package info (click to toggle)
owslib 0.35.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,772 kB
  • sloc: xml: 143,288; python: 24,542; makefile: 15
file content (131 lines) | stat: -rwxr-xr-x 5,089 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/python
# -*- coding: ISO-8859-15 -*-
# =============================================================================
#
# Authors : Luca Cinquini
#
# =============================================================================

import sys
import getopt
import os
from owslib.wps import WebProcessingService, monitorExecution

def usage():
    print("""
    
Usage: %s [parameters]

Common Parameters for all request types
-------------------

    -u, --url=[URL] the base URL of the WPS - required
    -r, --request=[REQUEST] the request type (GetCapabilities, DescribeProcess, Execute) - required 

Request Specific Parameters
---------------------------

    DescribeProcess
        -i, --identifier=[ID] process identifier - required
    Execute
        -x, --xml XML file containing pre-made request to be submitted - required

Examples
--------
python3 wps-client.py -u http://cida.usgs.gov/climate/gdp/process/WebProcessingService -r GetCapabilities
python3 wps-client.py --url=http://cida.usgs.gov/climate/gdp/process/WebProcessingService --request=GetCapabilities
python3 wps-client.py -u http://ceda-wps2.badc.rl.ac.uk/wps -r GetCapabilities
python3 wps-client.py -u http://rsg.pml.ac.uk/wps/generic.cgi -r GetCapabilities
python3 wps-client.py -u http://rsg.pml.ac.uk/wps/vector.cgi -r GetCapabilities

python3 wps-client.py -u http://cida.usgs.gov/climate/gdp/process/WebProcessingService -r DescribeProcess -i gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm
python3 wps-client.py --url http://cida.usgs.gov/climate/gdp/process/WebProcessingService --request DescribeProcess --identifier gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm
python3 wps-client.py -u http://ceda-wps2.badc.rl.ac.uk/wps -r DescribeProcess -i DoubleIt
python3 wps-client.py -u http://rsg.pml.ac.uk/wps/generic.cgi -r DescribeProcess -i reprojectCoords
python3 wps-client.py -u http://rsg.pml.ac.uk/wps/vector.cgi -r DescribeProcess -i v.mkgrid

python3 wps-client.py -u http://cida.usgs.gov/climate/gdp/process/WebProcessingService -r Execute -x ../tests/wps_USGSExecuteRequest1.xml
python3 wps-client.py --url http://cida.usgs.gov/climate/gdp/process/WebProcessingService --request Execute --xml ../tests/wps_USGSExecuteRequest1.xml
python3 wps-client.py -u http://rsg.pml.ac.uk/wps/generic.cgi -r Execute -x ../tests/wps_PMLExecuteRequest4.xml 
python3 wps-client.py -u http://rsg.pml.ac.uk/wps/generic.cgi -r Execute -x ../tests/wps_PMLExecuteRequest5.xml 
python3 wps-client.py -u http://rsg.pml.ac.uk/wps/vector.cgi -r Execute -x ../tests/wps_PMLExecuteRequest6.xml 

""" % sys.argv[0])
    
# check args
if len(sys.argv) == 1:
    usage()
    sys.exit(1)
    
print('ARGV      :', sys.argv[1:])
    
try:
    options, remainder = getopt.getopt(sys.argv[1:], 'u:r:x:i:v', ['url=', 'request=', 'xml=', 'identifier='])
except getopt.GetoptError as err:
    print(str(err))
    usage()
    sys.exit(2)
    
print('OPTIONS   :', options)

url = None
request = None
identifier = None
xml = None

for opt, arg in options:
    if opt in ('-u', '--url'):
        url = arg
    elif opt in ('-r', '--request'):
        request = arg
    elif opt in ('-x', '--xml'):
        xml = open(arg, 'rb').read()
    elif opt in ('-i', '--identifier'):
        identifier = arg
    else:
        assert False, 'Unhandled option'
   
# required arguments for all requests     
if request is None or url is None:
    usage()
    sys.exit(3)
        
# instantiate client
wps = WebProcessingService(url, skip_caps=True)

if request == 'GetCapabilities':
    wps.getcapabilities()
    print('WPS Identification type: %s' % wps.identification.type)
    print('WPS Identification title: %s' % wps.identification.title)
    print('WPS Identification abstract: %s' % wps.identification.abstract)
    for operation in wps.operations:
        print('WPS Operation: %s' % operation.name)
    for process in wps.processes:
        print('WPS Process: identifier=%s title=%s' % (process.identifier, process.title))
    
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)