forked from platformio/platformio-core
Introduce "get_all_boards" API to PlatformManager
This commit is contained in:
@@ -16,7 +16,6 @@ import json
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from platformio.exception import APIRequestError, InternetIsOffline
|
|
||||||
from platformio.managers.platform import PlatformManager
|
from platformio.managers.platform import PlatformManager
|
||||||
|
|
||||||
|
|
||||||
@@ -80,27 +79,12 @@ def print_boards(boards):
|
|||||||
|
|
||||||
|
|
||||||
def _get_boards(installed=False):
|
def _get_boards(installed=False):
|
||||||
boards = PlatformManager().get_installed_boards()
|
pm = PlatformManager()
|
||||||
if not installed:
|
return pm.get_installed_boards() if installed else pm.get_all_boards()
|
||||||
know_boards = ["%s:%s" % (b['platform'], b['id']) for b in boards]
|
|
||||||
try:
|
|
||||||
for board in PlatformManager().get_registered_boards():
|
|
||||||
key = "%s:%s" % (board['platform'], board['id'])
|
|
||||||
if key not in know_boards:
|
|
||||||
boards.append(board)
|
|
||||||
except InternetIsOffline:
|
|
||||||
pass
|
|
||||||
return sorted(boards, key=lambda b: b['name'])
|
|
||||||
|
|
||||||
|
|
||||||
def _print_boards_json(query, installed=False):
|
def _print_boards_json(query, installed=False):
|
||||||
result = []
|
result = []
|
||||||
try:
|
for board in _get_boards(installed):
|
||||||
boards = _get_boards(installed)
|
|
||||||
except APIRequestError:
|
|
||||||
if not installed:
|
|
||||||
boards = _get_boards(True)
|
|
||||||
for board in boards:
|
|
||||||
if query:
|
if query:
|
||||||
search_data = "%s %s" % (board['id'], json.dumps(board).lower())
|
search_data = "%s %s" % (board['id'], json.dumps(board).lower())
|
||||||
if query.lower() not in search_data.lower():
|
if query.lower() not in search_data.lower():
|
||||||
|
@@ -167,6 +167,18 @@ class PlatformManager(BasePkgManager):
|
|||||||
def get_registered_boards():
|
def get_registered_boards():
|
||||||
return util.get_api_result("/boards", cache_valid="30d")
|
return util.get_api_result("/boards", cache_valid="30d")
|
||||||
|
|
||||||
|
def get_all_boards(self):
|
||||||
|
boards = self.get_installed_boards()
|
||||||
|
know_boards = ["%s:%s" % (b['platform'], b['id']) for b in boards]
|
||||||
|
try:
|
||||||
|
for board in self.get_registered_boards():
|
||||||
|
key = "%s:%s" % (board['platform'], board['id'])
|
||||||
|
if key not in know_boards:
|
||||||
|
boards.append(board)
|
||||||
|
except (exception.APIRequestError, exception.InternetIsOffline):
|
||||||
|
pass
|
||||||
|
return sorted(boards, key=lambda b: b['name'])
|
||||||
|
|
||||||
def board_config(self, id_, platform=None):
|
def board_config(self, id_, platform=None):
|
||||||
for manifest in self.get_installed_boards():
|
for manifest in self.get_installed_boards():
|
||||||
if manifest['id'] == id_ and (not platform
|
if manifest['id'] == id_ and (not platform
|
||||||
|
Reference in New Issue
Block a user