mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-31 18:44:27 +02:00
Force to installed dev-platform is available
This commit is contained in:
@@ -12,21 +12,52 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
from platformio.compat import aio_to_thread
|
||||||
from platformio.home.rpc.handlers.base import BaseRPCHandler
|
from platformio.home.rpc.handlers.base import BaseRPCHandler
|
||||||
from platformio.package.manager.platform import PlatformPackageManager
|
from platformio.package.manager.platform import PlatformPackageManager
|
||||||
|
from platformio.package.meta import PackageSpec
|
||||||
from platformio.platform.factory import PlatformFactory
|
from platformio.platform.factory import PlatformFactory
|
||||||
|
|
||||||
|
|
||||||
class PlatformRPC(BaseRPCHandler):
|
class PlatformRPC(BaseRPCHandler):
|
||||||
|
async def fetch_platforms(self, search_query=None, page=0, force_installed=False):
|
||||||
|
if force_installed:
|
||||||
|
return {
|
||||||
|
"items": await aio_to_thread(
|
||||||
|
self._load_installed_platforms, search_query
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
search_result = await self.factory.manager.dispatcher["registry.call_client"](
|
||||||
|
method="list_packages",
|
||||||
|
query=search_query,
|
||||||
|
qualifiers={
|
||||||
|
"types": ["platform"],
|
||||||
|
},
|
||||||
|
page=page,
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"page": search_result["page"],
|
||||||
|
"limit": search_result["limit"],
|
||||||
|
"total": search_result["total"],
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"id": item["id"],
|
||||||
|
"name": item["name"],
|
||||||
|
"description": item["description"],
|
||||||
|
"tier": item["tier"],
|
||||||
|
"ownername": item["owner"]["username"],
|
||||||
|
"version": item["version"]["name"],
|
||||||
|
}
|
||||||
|
for item in search_result["items"]
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def list_installed(options=None):
|
def _load_installed_platforms(search_query=None):
|
||||||
result = []
|
search_query = (search_query or "").strip()
|
||||||
options = options or {}
|
|
||||||
|
|
||||||
def _matchSearchQuery(p):
|
def _matchSearchQuery(p):
|
||||||
searchQuery = options.get("searchQuery")
|
|
||||||
if not searchQuery:
|
|
||||||
return True
|
|
||||||
content_blocks = [p.name, p.title, p.description]
|
content_blocks = [p.name, p.title, p.description]
|
||||||
if p.frameworks:
|
if p.frameworks:
|
||||||
content_blocks.append(" ".join(p.frameworks.keys()))
|
content_blocks.append(" ".join(p.frameworks.keys()))
|
||||||
@@ -34,27 +65,41 @@ class PlatformRPC(BaseRPCHandler):
|
|||||||
board_data = board.get_brief_data()
|
board_data = board.get_brief_data()
|
||||||
for key in ("id", "mcu", "vendor"):
|
for key in ("id", "mcu", "vendor"):
|
||||||
content_blocks.append(board_data.get(key))
|
content_blocks.append(board_data.get(key))
|
||||||
return searchQuery.strip() in " ".join(content_blocks)
|
return search_query in " ".join(content_blocks)
|
||||||
|
|
||||||
|
items = []
|
||||||
pm = PlatformPackageManager()
|
pm = PlatformPackageManager()
|
||||||
for pkg in pm.get_installed():
|
for pkg in pm.get_installed():
|
||||||
p = PlatformFactory.new(pkg)
|
p = PlatformFactory.new(pkg)
|
||||||
if not _matchSearchQuery(p):
|
if search_query and not _matchSearchQuery(p):
|
||||||
continue
|
continue
|
||||||
result.append(
|
items.append(
|
||||||
dict(
|
{
|
||||||
__pkg_path=pkg.path,
|
"__pkg_path": pkg.path,
|
||||||
__pkg_meta=pkg.metadata.as_dict(),
|
"name": p.name,
|
||||||
name=p.name,
|
"title": p.title,
|
||||||
title=p.title,
|
"description": p.description,
|
||||||
description=p.description,
|
"ownername": pkg.metadata.spec.owner if pkg.metadata.spec else None,
|
||||||
|
"version": str(pkg.metadata.version),
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
return items
|
||||||
|
|
||||||
|
async def fetch_boards(self, platform_spec):
|
||||||
|
spec = PackageSpec(platform_spec)
|
||||||
|
if spec.owner:
|
||||||
|
return await self.factory.manager.dispatcher["registry.call_client"](
|
||||||
|
method="get_package",
|
||||||
|
typex="platform",
|
||||||
|
owner=spec.owner,
|
||||||
|
name=spec.name,
|
||||||
|
extra_path="/boards",
|
||||||
)
|
)
|
||||||
return result
|
return await aio_to_thread(self._load_installed_boards, spec)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_boards(spec):
|
def _load_installed_boards(platform_spec):
|
||||||
p = PlatformFactory.new(spec)
|
p = PlatformFactory.new(platform_spec)
|
||||||
return sorted(
|
return sorted(
|
||||||
[b.get_brief_data() for b in p.get_boards().values()],
|
[b.get_brief_data() for b in p.get_boards().values()],
|
||||||
key=lambda item: item["name"],
|
key=lambda item: item["name"],
|
||||||
|
Reference in New Issue
Block a user