示例#1
0
 def 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)
示例#2
0
def load_project_config(path=None):
    if not path or isdir(path):
        path = join(path or get_project_dir(), "platformio.ini")
    if not isfile(path):
        raise exception.NotPlatformIOProject(
            dirname(path) if path.endswith("platformio.ini") else path)
    cp = ProjectConfig()
    try:
        cp.read(path)
    except ConfigParser.Error as e:
        raise exception.InvalidProjectConf(str(e))
    return cp
示例#3
0
    def read(self, path, parse_extra=True):
        if path in self._parsed:
            return
        self._parsed.append(path)
        try:
            self._parser.read(path)
        except ConfigParser.Error as e:
            raise exception.InvalidProjectConf(path, str(e))

        if not parse_extra:
            return

        # load extra configs
        for pattern in self.get("platformio", "extra_configs", []):
            if pattern.startswith("~"):
                pattern = fs.expanduser(pattern)
            for item in glob.glob(pattern):
                self.read(item)
示例#4
0
    def read(self, path, parse_extra=True):
        if path in self._parsed:
            return
        self._parsed.append(path)
        try:
            self._parser.read(path)
        except ConfigParser.Error as e:
            raise exception.InvalidProjectConf(path, str(e))

        if not parse_extra:
            return

        # load extra configs
        for pattern in self.get("platformio", "extra_configs", []):
            for item in glob.glob(pattern):
                self.read(item)

        self._maintain_renaimed_options()
示例#5
0
    def get(self, section, option, default=None):  # pylint: disable=too-many-branches
        value = None
        try:
            value = self.getraw(section, option)
        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
            pass  # handle value from system environment
        except ConfigParser.Error as e:
            raise exception.InvalidProjectConf(self.path, str(e))

        option_meta = ProjectOptions.get("%s.%s" %
                                         (section.split(":", 1)[0], option))
        if not option_meta:
            return value or default

        if option_meta.multiple:
            value = self.parse_multi_values(value)

        if option_meta.sysenvvar:
            envvar_value = os.getenv(option_meta.sysenvvar)
            if not envvar_value and option_meta.oldnames:
                for oldoption in option_meta.oldnames:
                    envvar_value = os.getenv("PLATFORMIO_" + oldoption.upper())
                    if envvar_value:
                        break
            if envvar_value and option_meta.multiple:
                value = value or []
                value.extend(self.parse_multi_values(envvar_value))
            elif envvar_value and not value:
                value = envvar_value

        # option is not specified by user
        if value is None or (option_meta.multiple and value == []
                             and option_meta.default):
            return default if default is not None else option_meta.default

        try:
            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)