forked from platformio/platformio-core
Improve off-line mode // Resolve #1126
This commit is contained in:
@ -40,8 +40,7 @@ def cli(dev):
|
||||
# kill all PIO Home servers, they block `pioplus` binary
|
||||
shutdown_servers()
|
||||
|
||||
to_develop = dev or not all(
|
||||
[c.isdigit() for c in __version__ if c != "."])
|
||||
to_develop = dev or not all([c.isdigit() for c in __version__ if c != "."])
|
||||
cmds = ([
|
||||
"pip", "install", "--upgrade",
|
||||
"https://github.com/platformio/platformio-core/archive/develop.zip"
|
||||
|
@ -52,7 +52,8 @@ def on_platformio_end(ctx, result): # pylint: disable=W0613
|
||||
check_platformio_upgrade()
|
||||
check_internal_updates(ctx, "platforms")
|
||||
check_internal_updates(ctx, "libraries")
|
||||
except (exception.GetLatestVersionError, exception.APIRequestError):
|
||||
except (exception.InternetIsOffline, exception.GetLatestVersionError,
|
||||
exception.APIRequestError):
|
||||
click.secho(
|
||||
"Failed to check for PlatformIO upgrades. "
|
||||
"Please check your Internet connection.",
|
||||
@ -240,6 +241,8 @@ def check_platformio_upgrade():
|
||||
last_check['platformio_upgrade'] = int(time())
|
||||
app.set_state_item("last_check", last_check)
|
||||
|
||||
util.internet_on(raise_exception=True)
|
||||
|
||||
# Update PlatformIO's Core packages
|
||||
update_core_packages(silent=True)
|
||||
|
||||
@ -285,6 +288,8 @@ def check_internal_updates(ctx, what):
|
||||
last_check[what + '_update'] = int(time())
|
||||
app.set_state_item("last_check", last_check)
|
||||
|
||||
util.internet_on(raise_exception=True)
|
||||
|
||||
pm = PlatformManager() if what == "platforms" else LibraryManager()
|
||||
outdated_items = []
|
||||
for manifest in pm.get_installed():
|
||||
|
@ -18,6 +18,7 @@ import json
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import socket
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
@ -540,6 +541,7 @@ def _get_api_result(
|
||||
|
||||
|
||||
def get_api_result(url, params=None, data=None, auth=None, cache_valid=None):
|
||||
internet_on(raise_exception=True)
|
||||
from platformio.app import ContentCache
|
||||
total = 0
|
||||
max_retries = 5
|
||||
@ -559,8 +561,6 @@ def get_api_result(url, params=None, data=None, auth=None, cache_valid=None):
|
||||
return result
|
||||
except (requests.exceptions.ConnectionError,
|
||||
requests.exceptions.Timeout) as e:
|
||||
if not internet_on():
|
||||
raise exception.InternetIsOffline()
|
||||
from platformio.maintenance import in_silence
|
||||
total += 1
|
||||
if not in_silence():
|
||||
@ -575,16 +575,34 @@ def get_api_result(url, params=None, data=None, auth=None, cache_valid=None):
|
||||
"Please try later.")
|
||||
|
||||
|
||||
def internet_on():
|
||||
for url in ("http://dl.bintray.com", "http://dl.platformio.org"):
|
||||
@memoized
|
||||
def _internet_on():
|
||||
ips = [
|
||||
"193.222.52.25", # dl.platformio.org
|
||||
"159.122.18.156" # dl.bintray.com
|
||||
]
|
||||
timeout = 2
|
||||
socket.setdefaulttimeout(timeout)
|
||||
for ip in ips:
|
||||
try:
|
||||
requests.get(url, timeout=3)
|
||||
if os.getenv("HTTP_PROXY", os.getenv("HTTPS_PROXY")):
|
||||
requests.get("http://%s" % ip, timeout=timeout)
|
||||
else:
|
||||
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((ip,
|
||||
80))
|
||||
return True
|
||||
except: # pylint: disable=bare-except
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def internet_on(raise_exception=False):
|
||||
result = _internet_on()
|
||||
if raise_exception and not result:
|
||||
raise exception.InternetIsOffline()
|
||||
return result
|
||||
|
||||
|
||||
def get_pythonexe_path():
|
||||
return os.environ.get("PYTHONEXEPATH", normpath(sys.executable))
|
||||
|
||||
|
Reference in New Issue
Block a user