Skip to content

Commit 83d2173

Browse files
committed
Add Registry RPC
1 parent 1503eb5 commit 83d2173

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) 2014-present PlatformIO <[email protected]>
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ajsonrpc.core import JSONRPC20DispatchException
16+
17+
from platformio.registry.client import RegistryClient
18+
19+
20+
class RegistryRPC:
21+
@staticmethod
22+
def call_client(method, *args, **kwargs):
23+
try:
24+
client = RegistryClient()
25+
return getattr(client, method)(*args, **kwargs)
26+
except Exception as exc: # pylint: disable=bare-except
27+
raise JSONRPC20DispatchException(
28+
code=4003, message="Registry Call Error", data=str(exc)
29+
) from exc

platformio/home/run.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from platformio.home.rpc.handlers.os import OSRPC
3434
from platformio.home.rpc.handlers.piocore import PIOCoreRPC
3535
from platformio.home.rpc.handlers.project import ProjectRPC
36+
from platformio.home.rpc.handlers.registry import RegistryRPC
3637
from platformio.home.rpc.server import WebSocketJSONRPCServerFactory
3738
from platformio.package.manager.core import get_core_package_dir
3839
from platformio.proc import force_exit
@@ -72,6 +73,7 @@ def run_server(host, port, no_open, shutdown_timeout, home_url):
7273
ws_rpc_factory.add_object_handler(OSRPC(), namespace="os")
7374
ws_rpc_factory.add_object_handler(PIOCoreRPC(), namespace="core")
7475
ws_rpc_factory.add_object_handler(ProjectRPC(), namespace="project")
76+
ws_rpc_factory.add_object_handler(RegistryRPC(), namespace="registry")
7577

7678
path = urlparse(home_url).path
7779
routes = [

0 commit comments

Comments
 (0)