コード例 #1
0
ファイル: res_config.py プロジェクト: mycarta/libres
    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)

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

        # Insert key values
        if not os.path.exists( config_dir ):
            raise IOError("The configuration direcetory: %s does not exist" % config_dir)
        
        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
コード例 #2
0
ファイル: res_config.py プロジェクト: elenahechen/libres
    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