Add a new RPC method "project.config_call" for Home API

This commit is contained in:
Ivan Kravets
2019-10-12 20:00:12 +03:00
parent 181adb277f
commit 55d905a0d0
2 changed files with 8 additions and 4 deletions

View File

@ -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():

View File

@ -409,11 +409,11 @@ class ProjectConfig(ProjectConfigBase, ProjectConfigDirsMixin):
def __repr__(self):
return "<ProjectConfig %s>" % (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