forked from platformio/platformio-core
Add BaseRPCHandler
This commit is contained in:
@ -15,9 +15,10 @@
|
||||
from ajsonrpc.core import JSONRPC20DispatchException
|
||||
|
||||
from platformio.account.client import AccountClient
|
||||
from platformio.home.rpc.handlers.base import BaseRPCHandler
|
||||
|
||||
|
||||
class AccountRPC:
|
||||
class AccountRPC(BaseRPCHandler):
|
||||
@staticmethod
|
||||
def call_client(method, *args, **kwargs):
|
||||
try:
|
||||
|
@ -16,11 +16,12 @@ import os
|
||||
from pathlib import Path
|
||||
|
||||
from platformio import __version__, app, fs, util
|
||||
from platformio.home.rpc.handlers.base import BaseRPCHandler
|
||||
from platformio.project.config import ProjectConfig
|
||||
from platformio.project.helpers import is_platformio_project
|
||||
|
||||
|
||||
class AppRPC:
|
||||
class AppRPC(BaseRPCHandler):
|
||||
IGNORE_STORAGE_KEYS = [
|
||||
"cid",
|
||||
"coreVersion",
|
||||
|
17
platformio/home/rpc/handlers/base.py
Normal file
17
platformio/home/rpc/handlers/base.py
Normal file
@ -0,0 +1,17 @@
|
||||
# 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.
|
||||
|
||||
|
||||
class BaseRPCHandler:
|
||||
factory = None
|
@ -18,9 +18,10 @@ from pathlib import Path
|
||||
from ajsonrpc.core import JSONRPC20DispatchException
|
||||
|
||||
from platformio.compat import aio_get_running_loop
|
||||
from platformio.home.rpc.handlers.base import BaseRPCHandler
|
||||
|
||||
|
||||
class IDERPC:
|
||||
class IDERPC(BaseRPCHandler):
|
||||
COMMAND_TIMEOUT = 1.5 # in seconds
|
||||
|
||||
def __init__(self):
|
||||
|
@ -17,10 +17,11 @@ import time
|
||||
|
||||
from platformio.cache import ContentCache
|
||||
from platformio.compat import aio_create_task
|
||||
from platformio.home.rpc.handlers.base import BaseRPCHandler
|
||||
from platformio.home.rpc.handlers.os import OSRPC
|
||||
|
||||
|
||||
class MiscRPC:
|
||||
class MiscRPC(BaseRPCHandler):
|
||||
async def load_latest_tweets(self, data_url):
|
||||
cache_key = ContentCache.key_from_args(data_url, "tweets")
|
||||
cache_valid = "180d"
|
||||
|
@ -24,6 +24,7 @@ from starlette.concurrency import run_in_threadpool
|
||||
from platformio import fs
|
||||
from platformio.cache import ContentCache
|
||||
from platformio.device.list.util import list_logical_devices
|
||||
from platformio.home.rpc.handlers.base import BaseRPCHandler
|
||||
from platformio.http import HTTPSession, ensure_internet_on
|
||||
|
||||
|
||||
@ -35,7 +36,7 @@ class HTTPAsyncSession(HTTPSession):
|
||||
return await run_in_threadpool(func, *args, **kwargs)
|
||||
|
||||
|
||||
class OSRPC:
|
||||
class OSRPC(BaseRPCHandler):
|
||||
@staticmethod
|
||||
async def fetch_content(url, data=None, headers=None, cache_valid=None):
|
||||
if not headers:
|
||||
|
@ -12,11 +12,12 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from platformio.home.rpc.handlers.base import BaseRPCHandler
|
||||
from platformio.package.manager.platform import PlatformPackageManager
|
||||
from platformio.platform.factory import PlatformFactory
|
||||
|
||||
|
||||
class PlatformRPC:
|
||||
class PlatformRPC(BaseRPCHandler):
|
||||
@staticmethod
|
||||
def list_installed(options=None):
|
||||
result = []
|
||||
|
@ -20,6 +20,7 @@ from ajsonrpc.core import JSONRPC20DispatchException
|
||||
|
||||
from platformio import exception, fs
|
||||
from platformio.home.rpc.handlers.app import AppRPC
|
||||
from platformio.home.rpc.handlers.base import BaseRPCHandler
|
||||
from platformio.home.rpc.handlers.piocore import PIOCoreRPC
|
||||
from platformio.package.manager.platform import PlatformPackageManager
|
||||
from platformio.project.config import ProjectConfig
|
||||
@ -29,7 +30,7 @@ from platformio.project.integration.generator import ProjectGenerator
|
||||
from platformio.project.options import get_config_options_schema
|
||||
|
||||
|
||||
class ProjectRPC:
|
||||
class ProjectRPC(BaseRPCHandler):
|
||||
@staticmethod
|
||||
def config_call(init_kwargs, method, *args):
|
||||
assert isinstance(init_kwargs, dict)
|
||||
|
@ -15,10 +15,11 @@
|
||||
from ajsonrpc.core import JSONRPC20DispatchException
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from platformio.home.rpc.handlers.base import BaseRPCHandler
|
||||
from platformio.registry.client import RegistryClient
|
||||
|
||||
|
||||
class RegistryRPC:
|
||||
class RegistryRPC(BaseRPCHandler):
|
||||
@staticmethod
|
||||
async def call_client(method, *args, **kwargs):
|
||||
try:
|
||||
|
@ -37,6 +37,7 @@ class JSONRPCServerFactoryBase:
|
||||
raise NotImplementedError
|
||||
|
||||
def add_object_handler(self, handler, namespace):
|
||||
handler.factory = self
|
||||
self.manager.dispatcher.add_object(handler, prefix="%s." % namespace)
|
||||
|
||||
def on_client_connect(self):
|
||||
|
Reference in New Issue
Block a user