Skip to content

Commit

Permalink
Added option to hide progress bars (show_progress).
Browse files Browse the repository at this point in the history
  • Loading branch information
smithara committed Aug 29, 2018
1 parent 3b62112 commit 31831dd
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions viresclient/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def _chunkify_request(start_time, end_time, sampling_step):
return request_intervals

def _get(self, request=None, asynchronous=None, response_handler=None,
message=None):
message=None, show_progress=True):
"""Make a request and handle response according to response_handler
Args:
Expand All @@ -352,12 +352,18 @@ def _get(self, request=None, asynchronous=None, response_handler=None,
"""
try:
if asynchronous:
with ProgressBarProcessing(message) as progressbar:
# progressbar.write(message)
if show_progress:
with ProgressBarProcessing(message) as progressbar:
# progressbar.write(message)
self._wps_service.retrieve_async(
request,
handler=response_handler,
status_handler=progressbar.update
)
else:
self._wps_service.retrieve_async(
request,
handler=response_handler,
status_handler=progressbar.update
handler=response_handler
)
else:
self._wps_service.retrieve(
Expand All @@ -370,7 +376,7 @@ def _get(self, request=None, asynchronous=None, response_handler=None,
)

def get_between(self, start_time=None, end_time=None,
filetype="cdf", asynchronous=True):
filetype="cdf", asynchronous=True, show_progress=True):
"""Make the server request and download the data.
Args:
Expand All @@ -379,6 +385,7 @@ def get_between(self, start_time=None, end_time=None,
filetype (str): one of ('csv', 'cdf')
asynchronous (bool): True for asynchronous processing,
False for synchronous
show_progress (bool): Set to False to remove progress bars
Returns:
ReturnedData object
Expand Down Expand Up @@ -454,28 +461,15 @@ def get_between(self, start_time=None, end_time=None,
retdata = retdatagroup.contents[i]
# Make the request, as either asynchronous or synchronous
# The response handler streams the data to the ReturnedData object
response_handler = self._response_handler(retdata.file)
response_handler = self._response_handler(
retdata.file,
show_progress=show_progress
)
self._get(request=self._request,
asynchronous=asynchronous,
response_handler=response_handler,
message=message
message=message,
show_progress=show_progress
)
# try:
# if asynchronous:
# with ProgressBarProcessing() as progressbar:
# self._wps_service.retrieve_async(
# self._request,
# handler=response_handler,
# status_handler=progressbar.update
# )
# else:
# self._wps_service.retrieve(
# self._request,
# handler=response_handler
# )
# except WPSError:
# raise RuntimeError(
# "Server error - may be outside of product availability?"
# )

return retdatagroup

0 comments on commit 31831dd

Please sign in to comment.