parent
2d98a2de68
commit
1bc860fafd
1 changed files with 5 additions and 6 deletions
|
@ -349,8 +349,7 @@ class MavenDownloader:
|
||||||
if not self.verify_md5(filename, url + ".md5"):
|
if not self.verify_md5(filename, url + ".md5"):
|
||||||
response = self._request(url, "Failed to download artifact " + str(artifact), lambda r: r)
|
response = self._request(url, "Failed to download artifact " + str(artifact), lambda r: r)
|
||||||
if response:
|
if response:
|
||||||
f = open(filename, 'w')
|
f = open(filename, 'wb')
|
||||||
# f.write(response.read())
|
|
||||||
self._write_chunks(response, f, report_hook=self.chunk_report)
|
self._write_chunks(response, f, report_hook=self.chunk_report)
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
|
@ -366,19 +365,19 @@ class MavenDownloader:
|
||||||
if bytes_so_far >= total_size:
|
if bytes_so_far >= total_size:
|
||||||
sys.stdout.write('\n')
|
sys.stdout.write('\n')
|
||||||
|
|
||||||
def _write_chunks(self, response, file, chunk_size=8192, report_hook=None):
|
def _write_chunks(self, response, filehandle, chunk_size=8192, report_hook=None):
|
||||||
total_size = response.info().getheader('Content-Length').strip()
|
total_size = response.info().get('Content-Length').strip()
|
||||||
total_size = int(total_size)
|
total_size = int(total_size)
|
||||||
bytes_so_far = 0
|
bytes_so_far = 0
|
||||||
|
|
||||||
while 1:
|
while True:
|
||||||
chunk = response.read(chunk_size)
|
chunk = response.read(chunk_size)
|
||||||
bytes_so_far += len(chunk)
|
bytes_so_far += len(chunk)
|
||||||
|
|
||||||
if not chunk:
|
if not chunk:
|
||||||
break
|
break
|
||||||
|
|
||||||
file.write(chunk)
|
filehandle.write(chunk)
|
||||||
if report_hook:
|
if report_hook:
|
||||||
report_hook(bytes_so_far, chunk_size, total_size)
|
report_hook(bytes_so_far, chunk_size, total_size)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue