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
|
# kill all PIO Home servers, they block `pioplus` binary
|
||||||
shutdown_servers()
|
shutdown_servers()
|
||||||
|
|
||||||
to_develop = dev or not all(
|
to_develop = dev or not all([c.isdigit() for c in __version__ if c != "."])
|
||||||
[c.isdigit() for c in __version__ if c != "."])
|
|
||||||
cmds = ([
|
cmds = ([
|
||||||
"pip", "install", "--upgrade",
|
"pip", "install", "--upgrade",
|
||||||
"https://github.com/platformio/platformio-core/archive/develop.zip"
|
"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_platformio_upgrade()
|
||||||
check_internal_updates(ctx, "platforms")
|
check_internal_updates(ctx, "platforms")
|
||||||
check_internal_updates(ctx, "libraries")
|
check_internal_updates(ctx, "libraries")
|
||||||
except (exception.GetLatestVersionError, exception.APIRequestError):
|
except (exception.InternetIsOffline, exception.GetLatestVersionError,
|
||||||
|
exception.APIRequestError):
|
||||||
click.secho(
|
click.secho(
|
||||||
"Failed to check for PlatformIO upgrades. "
|
"Failed to check for PlatformIO upgrades. "
|
||||||
"Please check your Internet connection.",
|
"Please check your Internet connection.",
|
||||||
@ -240,6 +241,8 @@ def check_platformio_upgrade():
|
|||||||
last_check['platformio_upgrade'] = int(time())
|
last_check['platformio_upgrade'] = int(time())
|
||||||
app.set_state_item("last_check", last_check)
|
app.set_state_item("last_check", last_check)
|
||||||
|
|
||||||
|
util.internet_on(raise_exception=True)
|
||||||
|
|
||||||
# Update PlatformIO's Core packages
|
# Update PlatformIO's Core packages
|
||||||
update_core_packages(silent=True)
|
update_core_packages(silent=True)
|
||||||
|
|
||||||
@ -285,6 +288,8 @@ def check_internal_updates(ctx, what):
|
|||||||
last_check[what + '_update'] = int(time())
|
last_check[what + '_update'] = int(time())
|
||||||
app.set_state_item("last_check", last_check)
|
app.set_state_item("last_check", last_check)
|
||||||
|
|
||||||
|
util.internet_on(raise_exception=True)
|
||||||
|
|
||||||
pm = PlatformManager() if what == "platforms" else LibraryManager()
|
pm = PlatformManager() if what == "platforms" else LibraryManager()
|
||||||
outdated_items = []
|
outdated_items = []
|
||||||
for manifest in pm.get_installed():
|
for manifest in pm.get_installed():
|
||||||
|
@ -18,6 +18,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
|
import socket
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@ -540,6 +541,7 @@ def _get_api_result(
|
|||||||
|
|
||||||
|
|
||||||
def get_api_result(url, params=None, data=None, auth=None, cache_valid=None):
|
def get_api_result(url, params=None, data=None, auth=None, cache_valid=None):
|
||||||
|
internet_on(raise_exception=True)
|
||||||
from platformio.app import ContentCache
|
from platformio.app import ContentCache
|
||||||
total = 0
|
total = 0
|
||||||
max_retries = 5
|
max_retries = 5
|
||||||
@ -559,8 +561,6 @@ def get_api_result(url, params=None, data=None, auth=None, cache_valid=None):
|
|||||||
return result
|
return result
|
||||||
except (requests.exceptions.ConnectionError,
|
except (requests.exceptions.ConnectionError,
|
||||||
requests.exceptions.Timeout) as e:
|
requests.exceptions.Timeout) as e:
|
||||||
if not internet_on():
|
|
||||||
raise exception.InternetIsOffline()
|
|
||||||
from platformio.maintenance import in_silence
|
from platformio.maintenance import in_silence
|
||||||
total += 1
|
total += 1
|
||||||
if not in_silence():
|
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.")
|
"Please try later.")
|
||||||
|
|
||||||
|
|
||||||
def internet_on():
|
@memoized
|
||||||
for url in ("http://dl.bintray.com", "http://dl.platformio.org"):
|
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:
|
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
|
return True
|
||||||
except: # pylint: disable=bare-except
|
except: # pylint: disable=bare-except
|
||||||
pass
|
pass
|
||||||
return False
|
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():
|
def get_pythonexe_path():
|
||||||
return os.environ.get("PYTHONEXEPATH", normpath(sys.executable))
|
return os.environ.get("PYTHONEXEPATH", normpath(sys.executable))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user