How to use the lbuild.config.ConfigNode function in lbuild

To help you get started, we’ve selected a few lbuild examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github modm-io / lbuild / lbuild / config.py View on Github external
Load configuration from an XML configuration file.

        Args:
            configfile -- Path to the configuration file.
            parent -- Exisiting configuration which will be updated.

        Returns:
            Configuration as a `ConfigNode` instance.
        """
        filename = realpath(str(configfile))
        if not os.path.exists(filename):
            raise LbuildConfigNotFoundException(filename)

        xmltree = ConfigNode._load_and_verify(configfile)

        config = ConfigNode(parent)
        config.filename = os.path.relpath(filename)
        LOGGER.debug("Parse configuration '%s'", config.filename)
        configpath = os.path.dirname(config.filename)
        # load extend strings
        for node in xmltree.iterfind("extends"):
            cpath = Path(ConfigNode._rel_path(node.text, configpath))
            # We first need to check for the path, because in Windows `:`
            # is allowed to be part of the path (`C:\path`)
            try:
                cpath_exists = cpath.exists()
            except:
                cpath_exists = False
            if cpath_exists:
                ConfigNode.from_file(str(cpath), config)
            elif ":" in node.text:
                config._extends[config.filename].append(node.text)
github modm-io / lbuild / lbuild / config.py View on Github external
def flatten(self):
        config = ConfigNode()
        config.filename = self.root.filename
        self.last._flatten(config)
        config._repositories = list(set(config._repositories))
        config._modules = list(set(config._modules))
        return config
github modm-io / lbuild / lbuild / api.py View on Github external
cwd = os.path.abspath(os.path.dirname(config))
        self.cwd = cwd

        file_config = None
        filesystem_config = ConfigNode.from_path(self.cwd)

        # 0. config is default, but file doesn't exist, config = None
        if config == "project.xml":
            config = os.path.join(self.cwd, config)
            if not os.path.exists(config):
                config = None

        # 1. config is None: use filesystem config
        if config is None:
            if filesystem_config is None:
                file_config = ConfigNode()
            else:
                file_config = filesystem_config
        # 2. config is file: create file config and extend if with filesystem config
        elif os.path.exists(config):
            file_config = ConfigNode.from_file(config)
            if file_config is not None:
                file_config.extend_last(filesystem_config)
        # 3. config is alias: create virtual config and extend it with alias
        else:
            file_config = ConfigNode()
            file_config.filename = "command-line"
            file_config._extends["command-line"].append(config)

        self.config = file_config
        self.config.add_commandline_options(listify(options))
        self.config.add_commandline_collectors(listify(collectors))
github modm-io / lbuild / lbuild / parser.py View on Github external
def __init__(self, config=None):
        BaseNode.__init__(self, "lbuild", BaseNode.Type.PARSER)
        self._config = config if config else ConfigNode()
        self._config_flat = self._config.flatten()
github modm-io / lbuild / lbuild / api.py View on Github external
config -- Path to a configuration file. If specified options,
                repositories etc. will be loaded from there.
            options -- List of options. Must be list of strings in a
                "key=value" format.
            collectors -- List of collector values. Must be list of strings in a
                "key=value" format.
        """
        if cwd is None:
            if config is None:
                cwd = os.getcwd()
            else:
                cwd = os.path.abspath(os.path.dirname(config))
        self.cwd = cwd

        file_config = None
        filesystem_config = ConfigNode.from_path(self.cwd)

        # 0. config is default, but file doesn't exist, config = None
        if config == "project.xml":
            config = os.path.join(self.cwd, config)
            if not os.path.exists(config):
                config = None

        # 1. config is None: use filesystem config
        if config is None:
            if filesystem_config is None:
                file_config = ConfigNode()
            else:
                file_config = filesystem_config
        # 2. config is file: create file config and extend if with filesystem config
        elif os.path.exists(config):
            file_config = ConfigNode.from_file(config)
github modm-io / lbuild / lbuild / parser.py View on Github external
for repofile in repofiles:
                repo = self.parse_repository(repofile)

            # nothing more to extend
            if not self._config_flat._extends:
                break

            for filename, aliases in self._config_flat._extends.items():
                node = self._config.find(filename)
                for alias in aliases:
                    fconfig = self.find_any(alias, types=BaseNode.Type.CONFIG)
                    if not fconfig:
                        raise le.LbuildConfigAliasNotFoundException(self, alias)
                    if len(fconfig) > 1:
                        raise le.LbuildConfigAliasAmbiguousException(self, alias, fconfig)
                    self._config.extend(node, ConfigNode.from_file(fconfig[0]._config))
                node._extends.pop(filename)

        self._update_format()
        LOGGER.info("\n%s", self._config.render())
        return self._config_flat