API to update BoardConfig manifest

This commit is contained in:
Ivan Kravets
2018-05-25 21:18:08 +03:00
parent e48e15b014
commit 5011c3e21c
2 changed files with 21 additions and 0 deletions

View File

@ -665,6 +665,15 @@ class PlatformBoardConfig(object):
else:
raise KeyError("Invalid board option '%s'" % path)
def update(self, path, value):
newdict = None
for key in path.split(".")[::-1]:
if newdict is None:
newdict = {key: value}
else:
newdict = {key: newdict}
util.merge_dicts(self._manifest, newdict)
def __contains__(self, key):
try:
self.get(key)

View File

@ -754,6 +754,18 @@ def format_filesize(filesize):
return "%d%sB" % ((base * filesize / unit), suffix)
def merge_dicts(d1, d2, path=None):
if path is None:
path = []
for key in d2:
if (key in d1 and isinstance(d1[key], dict)
and isinstance(d2[key], dict)):
merge_dicts(d1[key], d2[key], path + [str(key)])
else:
d1[key] = d2[key]
return d1
def rmtree_(path):
def _onerror(_, name, __):