Skip to content

Commit

Permalink
move owslib.wps print statements to logging (#864)
Browse files Browse the repository at this point in the history
* move owslib.wps print statements to logging

* fix
  • Loading branch information
tomkralidis committed Feb 24, 2023
1 parent d912673 commit e8dd55f
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 84 deletions.
8 changes: 3 additions & 5 deletions examples/wps-birdhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

from owslib.wps import WebProcessingService, ComplexDataInput, monitorExecution

verbose = False

def multiple_outputs():
print("\nmultiple outputs ...")

# get multiple outputs
wps = WebProcessingService('http://localhost:8094/wps', verbose=verbose)
wps = WebProcessingService('http://localhost:8094/wps')

processid = 'dummyprocess'
inputs = [("input1", '1'), ("input2", '2')]
Expand Down Expand Up @@ -41,7 +39,7 @@ def complex_input_with_reference():

print("\ncomplex_input_with_reference ...")

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

processid = 'wordcount'
textdoc = ComplexDataInput("http://www.gutenberg.org/files/28885/28885-h/28885-h.htm") # alice in wonderland
Expand All @@ -67,7 +65,7 @@ def complex_input_with_content():

print("\ncomplex_input_with_content ...")

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

processid = 'wordcount'
textdoc = ComplexDataInput("ALICE was beginning to get very tired ...") # alice in wonderland
Expand Down
3 changes: 1 addition & 2 deletions examples/wps-ceda-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from owslib.wps import WebProcessingService, WPSExecution, WFSFeatureCollection, WFSQuery, GMLMultiPolygonFeatureCollection, monitorExecution, ComplexData, printInputOutput
from owslib.util import dump

verbose = True
wps = WebProcessingService('http://ceda-wps2.badc.rl.ac.uk/wps', verbose=verbose)
wps = WebProcessingService('http://ceda-wps2.badc.rl.ac.uk/wps')

# 1) GetCapabilities
# GET request: http://ceda-wps2.badc.rl.ac.uk/wps?Service=WPS&Request=GetCapabilities&Format=text/xml
Expand Down
14 changes: 5 additions & 9 deletions examples/wps-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def usage():
-u, --url=[URL] the base URL of the WPS - required
-r, --request=[REQUEST] the request type (GetCapabilities, DescribeProcess, Execute) - required
-v, --verbose set flag for verbose output - optional (defaults to False)
Request Specific Parameters
---------------------------
Expand All @@ -34,19 +33,19 @@ def usage():
Examples
--------
python wps-client.py -u http://cida.usgs.gov/climate/gdp/process/WebProcessingService -r GetCapabilities
python wps-client.py --verbose --url=http://cida.usgs.gov/climate/gdp/process/WebProcessingService --request=GetCapabilities
python wps-client.py --url=http://cida.usgs.gov/climate/gdp/process/WebProcessingService --request=GetCapabilities
python wps-client.py -u http://ceda-wps2.badc.rl.ac.uk/wps -r GetCapabilities
python wps-client.py -u http://rsg.pml.ac.uk/wps/generic.cgi -r GetCapabilities
python wps-client.py -u http://rsg.pml.ac.uk/wps/vector.cgi -r GetCapabilities
python wps-client.py -u http://cida.usgs.gov/climate/gdp/process/WebProcessingService -r DescribeProcess -i gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm
python wps-client.py --verbose --url http://cida.usgs.gov/climate/gdp/process/WebProcessingService --request DescribeProcess --identifier gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm
python wps-client.py --url http://cida.usgs.gov/climate/gdp/process/WebProcessingService --request DescribeProcess --identifier gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm
python wps-client.py -u http://ceda-wps2.badc.rl.ac.uk/wps -r DescribeProcess -i DoubleIt
python wps-client.py -u http://rsg.pml.ac.uk/wps/generic.cgi -r DescribeProcess -i reprojectCoords
python wps-client.py -u http://rsg.pml.ac.uk/wps/vector.cgi -r DescribeProcess -i v.mkgrid
python wps-client.py -u http://cida.usgs.gov/climate/gdp/process/WebProcessingService -r Execute -x ../tests/wps_USGSExecuteRequest1.xml
python wps-client.py --verbose --url http://cida.usgs.gov/climate/gdp/process/WebProcessingService --request Execute --xml ../tests/wps_USGSExecuteRequest1.xml
python wps-client.py --url http://cida.usgs.gov/climate/gdp/process/WebProcessingService --request Execute --xml ../tests/wps_USGSExecuteRequest1.xml
python wps-client.py -u http://rsg.pml.ac.uk/wps/generic.cgi -r Execute -x ../tests/wps_PMLExecuteRequest4.xml
python wps-client.py -u http://rsg.pml.ac.uk/wps/generic.cgi -r Execute -x ../tests/wps_PMLExecuteRequest5.xml
python wps-client.py -u http://rsg.pml.ac.uk/wps/vector.cgi -r Execute -x ../tests/wps_PMLExecuteRequest6.xml
Expand All @@ -61,7 +60,7 @@ def usage():
print('ARGV :', sys.argv[1:])

try:
options, remainder = getopt.getopt(sys.argv[1:], 'u:r:x:i:v', ['url=', 'request=', 'xml=', 'identifier=', 'verbose'])
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()
Expand All @@ -73,7 +72,6 @@ def usage():
request = None
identifier = None
xml = None
verbose = False

for opt, arg in options:
if opt in ('-u', '--url'):
Expand All @@ -84,8 +82,6 @@ def usage():
xml = open(arg, 'rb').read()
elif opt in ('-i', '--identifier'):
identifier = arg
elif opt in ('-v', '--verbose'):
verbose = True
else:
assert False, 'Unhandled option'

Expand All @@ -95,7 +91,7 @@ def usage():
sys.exit(3)

# instantiate client
wps = WebProcessingService(url, verbose=verbose, skip_caps=True)
wps = WebProcessingService(url, skip_caps=True)

if request == 'GetCapabilities':
wps.getcapabilities()
Expand Down
3 changes: 1 addition & 2 deletions examples/wps-pml-script-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from owslib.wps import WebProcessingService, monitorExecution

# instantiate WPS client
verbose = False
wps = WebProcessingService('http://rsg.pml.ac.uk/wps/generic.cgi', verbose=verbose, skip_caps=True)
wps = WebProcessingService('http://rsg.pml.ac.uk/wps/generic.cgi', skip_caps=True)

# 1) GetCapabilities
wps.getcapabilities()
Expand Down
3 changes: 1 addition & 2 deletions examples/wps-pml-script-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from owslib.wps import WebProcessingService, monitorExecution

# instantiate WPS client
verbose = False
wps = WebProcessingService('http://rsg.pml.ac.uk/wps/vector.cgi', verbose=verbose, skip_caps=True)
wps = WebProcessingService('http://rsg.pml.ac.uk/wps/vector.cgi', skip_caps=True)

# 1) GetCapabilities
wps.getcapabilities()
Expand Down
4 changes: 1 addition & 3 deletions examples/wps-usgs-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from owslib.util import dump

# instantiate WPS client
# setting verbose=True will print out all HTTP request and responses to standard output
verbose = False
wps = WebProcessingService('http://cida.usgs.gov/climate/gdp/process/WebProcessingService', verbose=verbose, skip_caps=True)
wps = WebProcessingService('http://cida.usgs.gov/climate/gdp/process/WebProcessingService', skip_caps=True)

# 1) GetCapabilities
# Submits an HTTP GET "GetCapabilities" request to the WPS service and parses the HTTP response.
Expand Down
8 changes: 3 additions & 5 deletions owslib/coverage/wcs100.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import os
import errno

import logging
from owslib.util import log, makeString


Expand Down Expand Up @@ -108,10 +107,9 @@ def getCoverage(self, identifier=None, bbox=None, time=None, format=None, crs=No
http://myhost/mywcs?SERVICE=WCS&REQUEST=GetCoverage&IDENTIFIER=TuMYrRQ4&VERSION=1.1.0&BOUNDINGBOX=-180,-90,180,90&TIME=2792-06-01T00:00:00.0&FORMAT=cf-netcdf
"""
if log.isEnabledFor(logging.DEBUG):
msg = 'WCS 1.0.0 DEBUG: Parameters passed to GetCoverage: identifier={}, bbox={}, time={}, format={}, crs={}, width={}, height={}, resx={}, resy={}, resz={}, parameter={}, method={}, other_arguments={}' # noqa
log.debug(msg.format(
identifier, bbox, time, format, crs, width, height, resx, resy, resz, parameter, method, str(kwargs)))
msg = 'WCS 1.0.0 DEBUG: Parameters passed to GetCoverage: identifier={}, bbox={}, time={}, format={}, crs={}, width={}, height={}, resx={}, resy={}, resz={}, parameter={}, method={}, other_arguments={}' # noqa
log.debug(msg.format(
identifier, bbox, time, format, crs, width, height, resx, resy, resz, parameter, method, str(kwargs)))

try:
base_url = next((m.get('url') for m in self.getOperationByName('GetCoverage').methods
Expand Down
11 changes: 2 additions & 9 deletions owslib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Contact email: tomkralidis@gmail.com
# =============================================================================

import logging as log
import os
import sys
from collections import OrderedDict
Expand Down Expand Up @@ -618,7 +619,7 @@ def build_get_url(base_url, params, overwrite=False):
def dump(obj, prefix=''):
'''Utility function to print to standard output a generic object with all its attributes.'''

print(("{} {}.{} : {}".format(prefix, obj.__module__, obj.__class__.__name__, obj.__dict__)))
return "{} {}.{} : {}".format(prefix, obj.__module__, obj.__class__.__name__, obj.__dict__)


def getTypedValue(data_type, value):
Expand Down Expand Up @@ -758,14 +759,6 @@ def bind_url(url):
return '%s%s' % (url, binder)


import logging
# Null logging handler
NullHandler = logging.NullHandler

log = logging.getLogger('owslib')
log.addHandler(NullHandler())


def findall(root, xpath, attribute_name=None, attribute_value=None):
"""Find elements recursively from given root element based on
xpath and possibly given attribute
Expand Down

0 comments on commit e8dd55f

Please sign in to comment.