From d83b1280ed609f297e171c4d09ea5dda7f290435 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 22 Mar 2016 22:03:51 +0200 Subject: [PATCH] Fix "KeyError: 'content-length'" in PlatformIO Download Manager // Resolve #591 --- HISTORY.rst | 3 +++ docs/ide/atom.rst | 2 +- platformio/downloader.py | 13 ++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 2b74cdd4..d10ccb87 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -26,6 +26,9 @@ PlatformIO 2.0 (`issue #571 `_) * Fixed invalid board parameters (reset method and baudrate) for a few ESP8266 based boards +* Fixed "KeyError: 'content-length'" in PlatformIO Download Manager + (`issue #591 `_) + 2.8.5 (2016-03-07) ~~~~~~~~~~~~~~~~~~ diff --git a/docs/ide/atom.rst b/docs/ide/atom.rst index 164423f5..2069a703 100644 --- a/docs/ide/atom.rst +++ b/docs/ide/atom.rst @@ -309,7 +309,7 @@ Intelligent Code Autocompletion ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PlatformIO IDE uses `clang `_ for the Intelligent Code Autocompletion. -To install it or check if it exists, please follow to step +To install it or check if it is already installed, please follow to step :ref:`ide_atom_installation_clang` from Installation guide. .. warning:: diff --git a/platformio/downloader.py b/platformio/downloader.py index 25e409ae..bbb90e07 100644 --- a/platformio/downloader.py +++ b/platformio/downloader.py @@ -56,18 +56,21 @@ class FileDownloader(object): return self._request.headers['last-modified'] def get_size(self): + if "content-length" not in self._request.headers: + return -1 return int(self._request.headers['content-length']) def start(self): itercontent = self._request.iter_content(chunk_size=self.CHUNK_SIZE) f = open(self._destination, "wb") - chunks = int(ceil(self.get_size() / float(self.CHUNK_SIZE))) - if app.is_disabled_progressbar(): + if app.is_disabled_progressbar() or self.get_size() == -1: click.echo("Downloading...") - for _ in range(0, chunks): - f.write(next(itercontent)) + 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)) @@ -78,7 +81,7 @@ class FileDownloader(object): def verify(self, sha1=None): _dlsize = getsize(self._destination) - if _dlsize != self.get_size(): + if self.get_size() != -1 and _dlsize != self.get_size(): raise FDSizeMismatch(_dlsize, self._fname, self.get_size()) if not sha1: