Skip to content

Commit

Permalink
Simplify progressbar options
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jul 27, 2017
1 parent 02b9737 commit 62c5a3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions sentinelsat/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class SentinelAPI:
api_url : string, optional
URL of the DataHub
defaults to 'https://scihub.copernicus.eu/apihub'
show_progressbars : bool
Whether progressbars should be shown or not, e.g. during download. Defaults to True.
Attributes
----------
Expand All @@ -45,21 +47,19 @@ class SentinelAPI:
page_size : int
number of results per query page
current value: 100 (maximum allowed on ApiHub)
progressbar_opts : dict
Progressbar options passed to tqdm(), e.g. to set {'disable': True}
"""

logger = logging.getLogger('sentinelsat.SentinelAPI')

def __init__(self, user, password, api_url='https://scihub.copernicus.eu/apihub/'):
def __init__(self, user, password, api_url='https://scihub.copernicus.eu/apihub/', show_progressbars=True):
self.session = requests.Session()
if user and password:
self.session.auth = (user, password)
self.api_url = api_url if api_url.endswith('/') else api_url + '/'
self.page_size = 100
self.user_agent = 'sentinelsat/' + sentinelsat_version
self.session.headers['User-Agent'] = self.user_agent
self.progressbar_opts = {}
self.show_progressbars = show_progressbars
# For unit tests
self._last_query = None
self._last_response = None
Expand Down Expand Up @@ -720,7 +720,7 @@ def _download(self, url, path, session, file_size):

def _tqdm(self, **kwargs):
"""tqdm progressbar wrapper. May be overridden to customize progressbar behavior"""
kwargs.update(self.progressbar_opts)
kwargs.update({'disable': not self.show_progressbars})
return tqdm(**kwargs)


Expand Down
8 changes: 4 additions & 4 deletions tests/test_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ def test_progressbars(capsys):
testfile_md5.update(testfile.read())
real_md5 = testfile_md5.hexdigest()

api.progressbar_opts = dict(desc="Testing")
assert api._md5_compare(true_path, real_md5) is True
api.progressbar_opts = dict(desc="Disabled", disable=True)
out, err = capsys.readouterr()
assert "checksumming" in err
api = SentinelAPI("mock_user", "mock_password", show_progressbars=False)
assert api._md5_compare(FIXTURES_DIR + "/map.geojson", real_md5) is False
out, err = capsys.readouterr()
assert out == ""
assert "Testing" in err
assert "Disabled" not in err
assert "checksumming" not in err


@my_vcr.use_cassette
Expand Down

0 comments on commit 62c5a3f

Please sign in to comment.