From 55d905a0d04a705d7e9267b83a29742d1039eeb9 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 12 Oct 2019 20:00:12 +0300 Subject: [PATCH] Add a new RPC method "project.config_call" for Home API --- platformio/home/rpc/handlers/project.py | 4 ++++ platformio/project/config.py | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/platformio/home/rpc/handlers/project.py b/platformio/home/rpc/handlers/project.py index 097f7e45..f7a9b8f8 100644 --- a/platformio/home/rpc/handlers/project.py +++ b/platformio/home/rpc/handlers/project.py @@ -32,6 +32,10 @@ from platformio.project.helpers import is_platformio_project class ProjectRPC(object): + @staticmethod + def config_call(path, method, *args): + return getattr(ProjectConfig(path), method)(*args) + @staticmethod def _get_projects(project_dirs=None): def _get_project_data(): diff --git a/platformio/project/config.py b/platformio/project/config.py index d0abf25c..988b53c2 100644 --- a/platformio/project/config.py +++ b/platformio/project/config.py @@ -409,11 +409,11 @@ class ProjectConfig(ProjectConfigBase, ProjectConfigDirsMixin): def __repr__(self): return "" % (self.path or "in-memory") + def as_dict(self): + return {s: self.items(s, as_dict=True) for s in self.sections()} + def to_json(self): - result = {} - for section in self.sections(): - result[section] = self.items(section, as_dict=True) - return json.dumps(result) + return json.dumps(self.as_dict()) def save(self, path=None): path = path or self.path