示例#1
0
    def _build_config_content(self, config):
        self._failed_keys = {}
        defines, config_dir, config_list = self._extract_config(config)

        config_parser = ResConfig.config_parser()
        config_content = ConfigContent(None)
        config_content.setParser(config_parser)

        # Insert defines
        for key, value in defines.items():
            config_content.add_define(key, value)

        # Insert key values
        if not os.path.exists(config_dir):
            raise IOError("The configuration directory: %s does not exist" %
                          config_dir)

        path_elm = config_content.create_path_elm(config_dir)

        def add_key_value(key, value):
            return config_parser.add_key_value(config_content,
                                               key,
                                               StringList([key] + value),
                                               path_elm=path_elm)

        for key, value in config_list:
            if isinstance(value, str):
                value = [value]
            if not isinstance(value, list):
                raise ValueError("Expected value to be str or list, was %r" %
                                 (type(value)))

            ok = add_key_value(key, value)
            if not ok:
                self._failed_keys[key] = value

        config_parser.validate(config_content)
        self._errors = list(config_content.getErrors())

        return config_content
示例#2
0
    def _build_config_content(self, config):
        self._failed_keys = {}
        defines, config_dir, config_list = self._extract_config(config)

        config_parser = ConfigParser()
        ResConfig.init_config_parser(config_parser)
        config_content = ConfigContent(None)
        config_content.setParser(config_parser)

        if config_dir is None:
            raise ValueError("Expected config to specify %s" %
                             ConfigKeys.CONFIG_DIRECTORY)

        # Insert defines
        for key in defines:
            config_content.add_define(key, defines[key])

        # Insert key values
        path_elm = config_content.create_path_elm(config_dir)
        add_key_value = lambda key, value: config_parser.add_key_value(
            config_content, key, StringList([key] + value), path_elm=path_elm)

        for key, value in config_list:
            if isinstance(value, str):
                value = [value]
            if not isinstance(value, list):
                raise ValueError("Expected value to be str or list, was %r" %
                                 (type(value)))

            ok = add_key_value(key, value)
            if not ok:
                self._failed_keys[key] = value

        config_parser.validate(config_content)
        self._errors = list(config_content.getErrors())

        return config_content