Catch IOError for VSCode Terminal

This commit is contained in:
Ivan Kravets
2017-12-14 20:05:06 +02:00
parent 15bb626e78
commit a632583f89

View File

@@ -73,19 +73,29 @@ class FileDownloader(object):
def start(self):
itercontent = self._request.iter_content(chunk_size=self.CHUNK_SIZE)
f = open(self._destination, "wb")
if app.is_disabled_progressbar() or self.get_size() == -1:
click.echo("Downloading...")
for chunk in itercontent:
if chunk:
f.write(chunk)
else:
chunks = int(ceil(self.get_size() / float(self.CHUNK_SIZE)))
with click.progressbar(length=chunks, label="Downloading") as pb:
for _ in pb:
f.write(next(itercontent))
f.close()
self._request.close()
try:
if app.is_disabled_progressbar() or self.get_size() == -1:
click.echo("Downloading...")
for chunk in itercontent:
if chunk:
f.write(chunk)
else:
chunks = int(ceil(self.get_size() / float(self.CHUNK_SIZE)))
with click.progressbar(
length=chunks, label="Downloading") as pb:
for _ in pb:
f.write(next(itercontent))
except IOError as e:
click.secho(
"IOError: Please read -> http://docs.platformio.org"
"/en/latest/ide/vscode.html"
"#packagemanager-is-unable-to-install-tool",
fg="red",
err=True)
raise e
finally:
f.close()
self._request.close()
if self.get_lmtime():
self._preserve_filemtime(self.get_lmtime())