Fix "KeyError: 'content-length'" in PlatformIO Download Manager // Resolve #591

This commit is contained in:
Ivan Kravets
2016-03-22 22:03:51 +02:00
parent 2d684d36e8
commit d83b1280ed
3 changed files with 12 additions and 6 deletions

View File

@ -26,6 +26,9 @@ PlatformIO 2.0
(`issue #571 <https://github.com/platformio/platformio/issues/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 <https://github.com/platformio/platformio/issues/591>`_)
2.8.5 (2016-03-07)
~~~~~~~~~~~~~~~~~~

View File

@ -309,7 +309,7 @@ Intelligent Code Autocompletion
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PlatformIO IDE uses `clang <http://clang.llvm.org>`_ 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::

View File

@ -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: