mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Handle ConfigParser erros
This commit is contained in:
@ -192,6 +192,11 @@ class InvalidLibConfURL(PlatformioException):
|
||||
MESSAGE = "Invalid library config URL '{0}'"
|
||||
|
||||
|
||||
class InvalidProjectConf(PlatformioException):
|
||||
|
||||
MESSAGE = "Invalid `platformio.ini`, project configuration file: '{0}'"
|
||||
|
||||
|
||||
class BuildScriptNotFound(PlatformioException):
|
||||
|
||||
MESSAGE = "Invalid path '{0}' to build script"
|
||||
|
@ -36,23 +36,27 @@ from platformio import __apiurl__, __version__, exception
|
||||
# pylint: disable=wrong-import-order, too-many-ancestors
|
||||
|
||||
try:
|
||||
from configparser import ConfigParser
|
||||
import configparser as ConfigParser
|
||||
except ImportError:
|
||||
from ConfigParser import ConfigParser
|
||||
import ConfigParser as ConfigParser
|
||||
|
||||
|
||||
class ProjectConfig(ConfigParser):
|
||||
class ProjectConfig(ConfigParser.ConfigParser):
|
||||
|
||||
VARTPL_RE = re.compile(r"\$\{([^\.\}]+)\.([^\}]+)\}")
|
||||
|
||||
def items(self, section, **_): # pylint: disable=arguments-differ
|
||||
items = []
|
||||
for option in ConfigParser.options(self, section):
|
||||
for option in ConfigParser.ConfigParser.options(self, section):
|
||||
items.append((option, self.get(section, option)))
|
||||
return items
|
||||
|
||||
def get(self, section, option, **kwargs):
|
||||
value = ConfigParser.get(self, section, option, **kwargs)
|
||||
try:
|
||||
value = ConfigParser.ConfigParser.get(self, section, option,
|
||||
**kwargs)
|
||||
except ConfigParser.Error as e:
|
||||
raise exception.InvalidProjectConf(str(e))
|
||||
if "${" not in value or "}" not in value:
|
||||
return value
|
||||
return self.VARTPL_RE.sub(self._re_sub_handler, value)
|
||||
@ -331,7 +335,10 @@ def load_project_config(path=None):
|
||||
raise exception.NotPlatformIOProject(
|
||||
dirname(path) if path.endswith("platformio.ini") else path)
|
||||
cp = ProjectConfig()
|
||||
cp.read(path)
|
||||
try:
|
||||
cp.read(path)
|
||||
except ConfigParser.Error as e:
|
||||
raise exception.InvalidProjectConf(str(e))
|
||||
return cp
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user