forked from platformio/platformio-core
Improve dump of config data
This commit is contained in:
1 parent
3f4aa320c2
commit
7345d3ea19
4 files changed
+89
-17
No files matched your search
@@ -45,11 +45,13 @@ class ProjectRPC(object):
|
||||
|
||||
@staticmethod
|
||||
def config_load(path):
|
||||
return ProjectConfig(path, parse_extra=False).as_tuple()
|
||||
return ProjectConfig(
|
||||
path, parse_extra=False, expand_interpolations=False
|
||||
).as_tuple()
|
||||
|
||||
@staticmethod
|
||||
def config_dump(path, data):
|
||||
config = ProjectConfig(path, parse_extra=False)
|
||||
config = ProjectConfig(path, parse_extra=False, expand_interpolations=False)
|
||||
config.update(data, clear=True)
|
||||
return config.save()
|
||||
|
||||
|
||||
@@ -92,6 +92,8 @@ class ProjectConfigBase(object):
|
||||
if path and os.path.isfile(path):
|
||||
self.read(path, parse_extra)
|
||||
|
||||
self._maintain_renaimed_options()
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self._parser, name)
|
||||
|
||||
@@ -114,8 +116,6 @@ class ProjectConfigBase(object):
|
||||
for item in glob.glob(pattern):
|
||||
self.read(item)
|
||||
|
||||
self._maintain_renaimed_options()
|
||||
|
||||
def _maintain_renaimed_options(self):
|
||||
# legacy `lib_extra_dirs` in [platformio]
|
||||
if self._parser.has_section("platformio") and self._parser.has_option(
|
||||
@@ -195,6 +195,9 @@ class ProjectConfigBase(object):
|
||||
if not section:
|
||||
section = "env:" + env
|
||||
|
||||
if not self.expand_interpolations:
|
||||
return self._parser.options(section)
|
||||
|
||||
for _, option in self.walk_options(section):
|
||||
if option not in result:
|
||||
result.append(option)
|
||||
@@ -260,7 +263,7 @@ class ProjectConfigBase(object):
|
||||
return os.getenv(option)
|
||||
return self.getraw(section, option)
|
||||
|
||||
def get(self, section, option, default=None):
|
||||
def get(self, section, option, default=None): # pylint: disable=too-many-branches
|
||||
value = None
|
||||
try:
|
||||
value = self.getraw(section, option)
|
||||
@@ -296,12 +299,14 @@ class ProjectConfigBase(object):
|
||||
return default if default is not None else option_meta.default
|
||||
|
||||
try:
|
||||
return self._cast_to(value, option_meta.type)
|
||||
return self.cast_to(value, option_meta.type)
|
||||
except click.BadParameter as e:
|
||||
if not self.expand_interpolations:
|
||||
return value
|
||||
raise exception.ProjectOptionValueError(e.format_message(), option, section)
|
||||
|
||||
@staticmethod
|
||||
def _cast_to(value, to_type):
|
||||
def cast_to(value, to_type):
|
||||
items = value
|
||||
if not isinstance(value, (list, tuple)):
|
||||
items = [value]
|
||||
|
||||
Reference in new issue
Block a user