Allow to call Downloader API in silent mode

This commit is contained in:
Ivan Kravets
2020-01-11 15:23:36 +02:00
parent 0f296e7e37
commit 7e41841a74

View File

@ -74,13 +74,14 @@ class FileDownloader(object):
return -1 return -1
return int(self._request.headers["content-length"]) return int(self._request.headers["content-length"])
def start(self, with_progress=True): def start(self, with_progress=True, silent=False):
label = "Downloading" label = "Downloading"
itercontent = self._request.iter_content(chunk_size=self.CHUNK_SIZE) itercontent = self._request.iter_content(chunk_size=self.CHUNK_SIZE)
f = open(self._destination, "wb") f = open(self._destination, "wb")
try: try:
if not with_progress or self.get_size() == -1: if not with_progress or self.get_size() == -1:
click.echo("%s..." % label) if not silent:
click.echo("%s..." % label)
for chunk in itercontent: for chunk in itercontent:
if chunk: if chunk:
f.write(chunk) f.write(chunk)