|
16 | 16 | import contextlib
|
17 | 17 | import json
|
18 | 18 | import requests
|
| 19 | +import socket |
19 | 20 | import subprocess
|
20 | 21 | import sys
|
21 | 22 | import shutil
|
|
84 | 85 | # Configure logger
|
85 | 86 | logger = logging.getLogger(__name__)
|
86 | 87 |
|
| 88 | +def is_internet_available(): |
| 89 | + """Check if connected to Internet""" |
| 90 | + try: |
| 91 | + with socket.create_connection(("8.8.8.8", 53), timeout=3): |
| 92 | + return True |
| 93 | + except OSError: |
| 94 | + return False |
87 | 95 |
|
88 | 96 | def safe_file_operation(operation_func):
|
89 | 97 | """Decorator for safe filesystem operations with error handling."""
|
@@ -301,17 +309,18 @@ def _configure_arduino_framework(self, frameworks: List[str]) -> None:
|
301 | 309 | self.packages["framework-arduinoespressif32"]["optional"] = False
|
302 | 310 | self.packages["framework-arduinoespressif32-libs"]["optional"] = False
|
303 | 311 |
|
304 |
| - # Use branch master |
305 |
| - url = ("https://raw.githubusercontent.com/espressif/arduino-esp32/" |
306 |
| - "master/package/package_esp32_index.template.json") |
307 |
| - try: |
308 |
| - response = requests.get(url, timeout=30) |
309 |
| - response.raise_for_status() |
310 |
| - packjdata = response.json() |
311 |
| - dyn_lib_url = packjdata['packages'][0]['tools'][0]['systems'][0]['url'] |
312 |
| - self.packages["framework-arduinoespressif32-libs"]["version"] = dyn_lib_url |
313 |
| - except (requests.RequestException, KeyError, IndexError) as e: |
314 |
| - logger.error(f"Failed to fetch Arduino framework library URL: {e}") |
| 312 | + if is_internet_available(): |
| 313 | + # Use branch master |
| 314 | + url = ("https://raw.githubusercontent.com/espressif/arduino-esp32/" |
| 315 | + "master/package/package_esp32_index.template.json") |
| 316 | + try: |
| 317 | + response = requests.get(url, timeout=30) |
| 318 | + response.raise_for_status() |
| 319 | + packjdata = response.json() |
| 320 | + dyn_lib_url = packjdata['packages'][0]['tools'][0]['systems'][0]['url'] |
| 321 | + self.packages["framework-arduinoespressif32-libs"]["version"] = dyn_lib_url |
| 322 | + except (requests.RequestException, KeyError, IndexError) as e: |
| 323 | + logger.error(f"Failed to fetch Arduino framework library URL: {e}") |
315 | 324 |
|
316 | 325 | def _configure_espidf_framework(
|
317 | 326 | self, frameworks: List[str], variables: Dict, board_config: Dict, mcu: str
|
|
0 commit comments