mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-31 10:37:13 +02:00
Reinit download session when IOError
This commit is contained in:
@ -31,15 +31,8 @@ class FileDownloader(object):
|
|||||||
CHUNK_SIZE = 1024
|
CHUNK_SIZE = 1024
|
||||||
|
|
||||||
def __init__(self, url, dest_dir=None):
|
def __init__(self, url, dest_dir=None):
|
||||||
self._request = None
|
self.url = url
|
||||||
# make connection
|
self._request = self.init_request()
|
||||||
self._request = requests.get(
|
|
||||||
url,
|
|
||||||
stream=True,
|
|
||||||
headers=util.get_request_defheaders(),
|
|
||||||
verify=version_info >= (2, 7, 9))
|
|
||||||
if self._request.status_code != 200:
|
|
||||||
raise FDUnrecognizedStatusCode(self._request.status_code, url)
|
|
||||||
|
|
||||||
disposition = self._request.headers.get("content-disposition")
|
disposition = self._request.headers.get("content-disposition")
|
||||||
if disposition and "filename=" in disposition:
|
if disposition and "filename=" in disposition:
|
||||||
@ -50,12 +43,21 @@ class FileDownloader(object):
|
|||||||
else:
|
else:
|
||||||
self._fname = [p for p in url.split("/") if p][-1]
|
self._fname = [p for p in url.split("/") if p][-1]
|
||||||
|
|
||||||
self._progressbar = None
|
|
||||||
self._destination = self._fname
|
self._destination = self._fname
|
||||||
if dest_dir:
|
if dest_dir:
|
||||||
self.set_destination(
|
self.set_destination(
|
||||||
join(dest_dir.decode(getfilesystemencoding()), self._fname))
|
join(dest_dir.decode(getfilesystemencoding()), self._fname))
|
||||||
|
|
||||||
|
def init_request(self):
|
||||||
|
r = requests.get(
|
||||||
|
self.url,
|
||||||
|
stream=True,
|
||||||
|
headers=util.get_request_defheaders(),
|
||||||
|
verify=version_info >= (2, 7, 9))
|
||||||
|
if r.status_code != 200:
|
||||||
|
raise FDUnrecognizedStatusCode(r.status_code, self.url)
|
||||||
|
return r
|
||||||
|
|
||||||
def set_destination(self, destination):
|
def set_destination(self, destination):
|
||||||
self._destination = destination
|
self._destination = destination
|
||||||
|
|
||||||
@ -87,6 +89,8 @@ class FileDownloader(object):
|
|||||||
f.write(next(itercontent))
|
f.write(next(itercontent))
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if with_progress:
|
if with_progress:
|
||||||
|
# reinitialize request
|
||||||
|
self._request = self.init_request()
|
||||||
return self.start(with_progress=False)
|
return self.start(with_progress=False)
|
||||||
click.secho(
|
click.secho(
|
||||||
"Error: Please read http://bit.ly/package-manager-ioerror",
|
"Error: Please read http://bit.ly/package-manager-ioerror",
|
||||||
|
Reference in New Issue
Block a user