Skip to content

Commit

Permalink
Add Registry RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed Jan 23, 2023
1 parent 1503eb5 commit 83d2173
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions platformio/home/rpc/handlers/registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ajsonrpc.core import JSONRPC20DispatchException

from platformio.registry.client import RegistryClient


class RegistryRPC:
@staticmethod
def call_client(method, *args, **kwargs):
try:
client = RegistryClient()
return getattr(client, method)(*args, **kwargs)
except Exception as exc: # pylint: disable=bare-except
raise JSONRPC20DispatchException(
code=4003, message="Registry Call Error", data=str(exc)
) from exc
2 changes: 2 additions & 0 deletions platformio/home/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from platformio.home.rpc.handlers.os import OSRPC
from platformio.home.rpc.handlers.piocore import PIOCoreRPC
from platformio.home.rpc.handlers.project import ProjectRPC
from platformio.home.rpc.handlers.registry import RegistryRPC
from platformio.home.rpc.server import WebSocketJSONRPCServerFactory
from platformio.package.manager.core import get_core_package_dir
from platformio.proc import force_exit
Expand Down Expand Up @@ -72,6 +73,7 @@ def run_server(host, port, no_open, shutdown_timeout, home_url):
ws_rpc_factory.add_object_handler(OSRPC(), namespace="os")
ws_rpc_factory.add_object_handler(PIOCoreRPC(), namespace="core")
ws_rpc_factory.add_object_handler(ProjectRPC(), namespace="project")
ws_rpc_factory.add_object_handler(RegistryRPC(), namespace="registry")

path = urlparse(home_url).path
routes = [
Expand Down

0 comments on commit 83d2173

Please sign in to comment.