Fix "ConnectionError" when PlatformIO SF Storage is off-line

This commit is contained in:
Ivan Kravets
2015-05-28 13:44:10 +03:00
parent 8d9071e7c2
commit 06baa98823
3 changed files with 20 additions and 4 deletions

View File

@ -6,6 +6,7 @@ Release History
* Fixed resolving of C/C++ std libs by Eclipse IDE
(`issue #220 <https://github.com/platformio/platformio/issues/220>`_)
* Fixed "ConnectionError" when PlatformIO SF Storage is off-line
2.0.2 (2015-05-27)
------------------

View File

@ -25,8 +25,11 @@ class FileDownloader(object):
self._destination = self._fname
if dest_dir:
self.set_destination(join(dest_dir, self._fname))
self._progressbar = None
self._progressbar = None
self._request = None
# make connection
self._request = requests.get(url, stream=True,
headers=util.get_request_defheaders())
if self._request.status_code != 200:
@ -93,4 +96,5 @@ class FileDownloader(object):
util.change_filemtime(self._destination, lmtime)
def __del__(self):
self._request.close()
if self._request:
self._request.close()

View File

@ -2,11 +2,12 @@
# See LICENSE for details.
from os import makedirs, remove
from os.path import isdir, join
from os.path import basename, isdir, isfile, join
from shutil import rmtree
from time import time
import click
import requests
from platformio import exception, telemetry, util
from platformio.app import get_state_item, set_state_item
@ -85,7 +86,17 @@ class PackageManager(object):
if not isdir(pkg_dir):
makedirs(pkg_dir)
dlpath = self.download(info['url'], pkg_dir, info['sha1'])
dlpath = None
try:
dlpath = self.download(info['url'], pkg_dir, info['sha1'])
except requests.exceptions.ConnectionError:
if info['url'].startswith("http://sourceforge.net"):
dlpath = self.download(
"http://dl.platformio.org/packages/%s" %
basename(info['url']), pkg_dir, info['sha1'])
assert isfile(dlpath)
if self.unpack(dlpath, pkg_dir):
self._register(name, info['version'])
# remove archive