mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Enhance configuration variables
This commit is contained in:
@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
DEFAULT_REQUESTS_TIMEOUT = (10, None) # (connect, read)
|
|
||||||
|
|
||||||
VERSION = (4, 4, "0b3")
|
VERSION = (4, 4, "0b3")
|
||||||
__version__ = ".".join([str(s) for s in VERSION])
|
__version__ = ".".join([str(s) for s in VERSION])
|
||||||
|
|
||||||
@ -46,6 +44,8 @@ __registry_api__ = [
|
|||||||
]
|
]
|
||||||
__pioremote_endpoint__ = "ssl:host=remote.platformio.org:port=4413"
|
__pioremote_endpoint__ = "ssl:host=remote.platformio.org:port=4413"
|
||||||
|
|
||||||
|
__default_requests_timeout__ = (10, None) # (connect, read)
|
||||||
|
|
||||||
__core_packages__ = {
|
__core_packages__ = {
|
||||||
"contrib-piohome": "~3.2.3",
|
"contrib-piohome": "~3.2.3",
|
||||||
"contrib-pysite": "~2.%d%d.0" % (sys.version_info.major, sys.version_info.minor),
|
"contrib-pysite": "~2.%d%d.0" % (sys.version_info.major, sys.version_info.minor),
|
||||||
@ -55,3 +55,11 @@ __core_packages__ = {
|
|||||||
"tool-clangtidy": "~1.100000.0",
|
"tool-clangtidy": "~1.100000.0",
|
||||||
"tool-pvs-studio": "~7.7.0",
|
"tool-pvs-studio": "~7.7.0",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__check_internet_hosts__ = [
|
||||||
|
"140.82.118.3", # Github.com
|
||||||
|
"35.231.145.151", # Gitlab.com
|
||||||
|
"88.198.170.159", # platformio.org
|
||||||
|
"github.com",
|
||||||
|
"platformio.org",
|
||||||
|
]
|
||||||
|
@ -20,7 +20,7 @@ import socket
|
|||||||
import requests.adapters
|
import requests.adapters
|
||||||
from requests.packages.urllib3.util.retry import Retry # pylint:disable=import-error
|
from requests.packages.urllib3.util.retry import Retry # pylint:disable=import-error
|
||||||
|
|
||||||
from platformio import DEFAULT_REQUESTS_TIMEOUT, app, util
|
from platformio import __check_internet_hosts__, __default_requests_timeout__, app, util
|
||||||
from platformio.cache import ContentCache
|
from platformio.cache import ContentCache
|
||||||
from platformio.exception import PlatformioException, UserSideException
|
from platformio.exception import PlatformioException, UserSideException
|
||||||
|
|
||||||
@ -30,15 +30,6 @@ except ImportError:
|
|||||||
from urlparse import urljoin
|
from urlparse import urljoin
|
||||||
|
|
||||||
|
|
||||||
PING_REMOTE_HOSTS = [
|
|
||||||
"140.82.118.3", # Github.com
|
|
||||||
"35.231.145.151", # Gitlab.com
|
|
||||||
"88.198.170.159", # platformio.org
|
|
||||||
"github.com",
|
|
||||||
"platformio.org",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPClientError(PlatformioException):
|
class HTTPClientError(PlatformioException):
|
||||||
def __init__(self, message, response=None):
|
def __init__(self, message, response=None):
|
||||||
super(HTTPClientError, self).__init__()
|
super(HTTPClientError, self).__init__()
|
||||||
@ -125,7 +116,7 @@ class HTTPClient(object):
|
|||||||
|
|
||||||
# set default timeout
|
# set default timeout
|
||||||
if "timeout" not in kwargs:
|
if "timeout" not in kwargs:
|
||||||
kwargs["timeout"] = DEFAULT_REQUESTS_TIMEOUT
|
kwargs["timeout"] = __default_requests_timeout__
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@ -179,7 +170,7 @@ class HTTPClient(object):
|
|||||||
def _internet_on():
|
def _internet_on():
|
||||||
timeout = 2
|
timeout = 2
|
||||||
socket.setdefaulttimeout(timeout)
|
socket.setdefaulttimeout(timeout)
|
||||||
for host in PING_REMOTE_HOSTS:
|
for host in __check_internet_hosts__:
|
||||||
try:
|
try:
|
||||||
for var in ("HTTP_PROXY", "HTTPS_PROXY"):
|
for var in ("HTTP_PROXY", "HTTPS_PROXY"):
|
||||||
if not os.getenv(var) and not os.getenv(var.lower()):
|
if not os.getenv(var) and not os.getenv(var.lower()):
|
||||||
@ -208,7 +199,7 @@ def fetch_remote_content(*args, **kwargs):
|
|||||||
kwargs["headers"]["User-Agent"] = app.get_user_agent()
|
kwargs["headers"]["User-Agent"] = app.get_user_agent()
|
||||||
|
|
||||||
if "timeout" not in kwargs:
|
if "timeout" not in kwargs:
|
||||||
kwargs["timeout"] = DEFAULT_REQUESTS_TIMEOUT
|
kwargs["timeout"] = __default_requests_timeout__
|
||||||
|
|
||||||
r = requests.get(*args, **kwargs)
|
r = requests.get(*args, **kwargs)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
@ -22,7 +22,7 @@ from functools import cmp_to_key
|
|||||||
import click
|
import click
|
||||||
from twisted.internet import defer # pylint: disable=import-error
|
from twisted.internet import defer # pylint: disable=import-error
|
||||||
|
|
||||||
from platformio import DEFAULT_REQUESTS_TIMEOUT, fs, util
|
from platformio import __default_requests_timeout__, fs, util
|
||||||
from platformio.cache import ContentCache
|
from platformio.cache import ContentCache
|
||||||
from platformio.clients.http import ensure_internet_on
|
from platformio.clients.http import ensure_internet_on
|
||||||
from platformio.commands.home import helpers
|
from platformio.commands.home import helpers
|
||||||
@ -54,11 +54,11 @@ class OSRPC(object):
|
|||||||
session = helpers.requests_session()
|
session = helpers.requests_session()
|
||||||
if data:
|
if data:
|
||||||
r = yield session.post(
|
r = yield session.post(
|
||||||
uri, data=data, headers=headers, timeout=DEFAULT_REQUESTS_TIMEOUT
|
uri, data=data, headers=headers, timeout=__default_requests_timeout__
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
r = yield session.get(
|
r = yield session.get(
|
||||||
uri, headers=headers, timeout=DEFAULT_REQUESTS_TIMEOUT
|
uri, headers=headers, timeout=__default_requests_timeout__
|
||||||
)
|
)
|
||||||
|
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
@ -21,7 +21,7 @@ from time import mktime
|
|||||||
import click
|
import click
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from platformio import DEFAULT_REQUESTS_TIMEOUT, app, fs
|
from platformio import __default_requests_timeout__, app, fs
|
||||||
from platformio.package.exception import PackageException
|
from platformio.package.exception import PackageException
|
||||||
|
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class FileDownloader(object):
|
|||||||
url,
|
url,
|
||||||
stream=True,
|
stream=True,
|
||||||
headers={"User-Agent": app.get_user_agent()},
|
headers={"User-Agent": app.get_user_agent()},
|
||||||
timeout=DEFAULT_REQUESTS_TIMEOUT,
|
timeout=__default_requests_timeout__,
|
||||||
)
|
)
|
||||||
if self._request.status_code != 200:
|
if self._request.status_code != 200:
|
||||||
raise PackageException(
|
raise PackageException(
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from platformio import proc
|
from platformio import __check_internet_hosts__, proc
|
||||||
from platformio.clients import http
|
from platformio.clients import http
|
||||||
from platformio.clients.registry import RegistryClient
|
from platformio.clients.registry import RegistryClient
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ def test_platformio_cli():
|
|||||||
|
|
||||||
|
|
||||||
def test_ping_internet_ips():
|
def test_ping_internet_ips():
|
||||||
for host in http.PING_REMOTE_HOSTS:
|
for host in __check_internet_hosts__:
|
||||||
requests.get("http://%s" % host, allow_redirects=False, timeout=2)
|
requests.get("http://%s" % host, allow_redirects=False, timeout=2)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user