当前位置: 首页>>代码示例>>Python>>正文


Python ConfigParser.sections方法代码示例

本文整理汇总了Python中iniparse.ConfigParser.sections方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.sections方法的具体用法?Python ConfigParser.sections怎么用?Python ConfigParser.sections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在iniparse.ConfigParser的用法示例。


在下文中一共展示了ConfigParser.sections方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_ini_file

# 需要导入模块: from iniparse import ConfigParser [as 别名]
# 或者: from iniparse.ConfigParser import sections [as 别名]
    def read_ini_file(self,filename):
        cp = ConfigParser()
        cp.read(filename)

        if not self.backup_base_dir:
            self.backup_base_dir = cp.get('global','backup_base_dir')
        if not os.path.isdir(self.backup_base_dir):
            self.logger.info('Creating backup directory %s' % self.backup_base_dir)
            os.makedirs(self.backup_base_dir)

        self.logger.debug("backup directory : " + self.backup_base_dir)
        self.dbstat = BackupStat(os.path.join(self.backup_base_dir,'log','tisbackup.sqlite'))

        for section in cp.sections():
            if (section != 'global'):
                self.logger.debug("reading backup config " + section)
                backup_item = None
                type = cp.get(section,'type')

                backup_item = backup_drivers[type](backup_name=section,
                                                   backup_dir=os.path.join(self.backup_base_dir,section),dbstat=self.dbstat,dry_run=self.dry_run)
                backup_item.read_config(cp)
                backup_item.verbose = self.verbose

                self.backup_list.append(backup_item)
开发者ID:tranquilit,项目名称:TISbackup,代码行数:27,代码来源:tisbackup.py

示例2: _LoadLevelDef

# 需要导入模块: from iniparse import ConfigParser [as 别名]
# 或者: from iniparse.ConfigParser import sections [as 别名]
def _LoadLevelDef(filename):
    """Load level definitions from Config/Level/<filename>.ini.
    
    Call LoadLevel(<name>) to actually load all the Actors described in
    the file. 
    
    If called a second time, it will reload the file, so the definitions
    will be updated, but the existing world won't be affected. 
    """
    path_try = os.path.join("Config", "Level", filename + ".ini")
    if not (os.path.exists(path_try)):
        raise IOError, "Couldn't find " + path_try
    
    if not hasattr(angel, "_levels"):
        angel._levels = {}
    angel._levels[filename] = {}
    config = ConfigParser()
    config.read(path_try)
    for section in config.sections():
        actor = {}
        for item in config.items(section):
            actor[item[0]] = item[1]
        angel._levels[filename][section] = actor
开发者ID:chrishaukap,项目名称:GameDev,代码行数:25,代码来源:conf_load.py

示例3: _LoadActorDefs

# 需要导入模块: from iniparse import ConfigParser [as 别名]
# 或者: from iniparse.ConfigParser import sections [as 别名]
def _LoadActorDefs(filename):
    """Load actor definitions from Config/ActorDef/<filename>.ini.
    
    Instantiate an Actor from a definition with Actor.Create(<name>)
    
    If called a second time, it will reload the file, so the definitions
    will be updated, but any existing Actors that were created from them
    remain the same. 
    """
    path_try = os.path.join("Config", "ActorDef", filename + ".ini")
    if not (os.path.exists(path_try)):
        raise IOError, "Couldn't find " + path_try
    if not hasattr(Actor, "_defs"):
        Actor._defs = {}
    config = ConfigParser()
    config.read(path_try)
    for section in config.sections():
        definition = {}
        for item in config.items(section):
            definition[item[0]] = item[1]
        if 'class' not in definition:
            definition["class"] = "Actor"
        Actor._defs[section] = definition
开发者ID:chrishaukap,项目名称:GameDev,代码行数:25,代码来源:conf_load.py

示例4: RepoFile

# 需要导入模块: from iniparse import ConfigParser [as 别名]
# 或者: from iniparse.ConfigParser import sections [as 别名]

#.........这里部分代码省略.........

    # -- contents manipulation ------------------------------------------------------------

    def add_repo(self, repo):
        """
        Adds a new repo to this object, however the file is not saved.

        This is not saved as an object reference, so future changes to the passed in
        repo will not be captured in this RepoFile instance. If changes are made to
        the original Repo object, it must be passed into the RepoFile instance through
        update_repo in order for the changes to be captured.

        @param repo: repo to add; may not be None
        @type  repo: L{Repo}
        """
        self.parser.add_section(repo.id)
        self._repo_to_parser(repo)

    def remove_repo_by_name(self, repo_name):
        """
        Removes the repo with the given name. If the repo does not exist, this
        method does nothing.

        @param repo: identifies the repo to remove
        @type  repo: string
        """
        return self.parser.remove_section(repo_name)

    def update_repo(self, repo):
        """
        Updates the underlying store with the latest contents of a repo. The repo
        passed to this method must have been created prior to this call.

        The repo is not saved as an object reference. Instead, the values are captured
        to the underlying store at the point in time this is called.

        @param repo: repo instance containing updated values to store; cannot be None
        @type  repo: L{Repo}
        """
        self._repo_to_parser(repo)

    def get_repo(self, repo_id):
        """
        Loads a repo by repo ID. If the repo does not exist, returns None.

        @param repo_id: id of the repo to retrieve
        @type  repo_id: string

        @return: repo instance if one exists; None otherwise
        @rtype:  L{Repo}
        """
        if self.parser.has_section(repo_id):
            repo = self._parser_to_repo(repo_id)
            return repo
        else:
            return None

    def all_repos(self):
        """
        Returns a list of all repos in the store.

        @return: list of repo instances; empty list if there are none
        @rtype:  list of L{Repo}
        """
        repos = []
        for repo_name in self.parser.sections():
            repo = self._parser_to_repo(repo_name)
            repos.append(repo)

        return repos

    def _repo_to_parser(self, repo):
        """
        Adds the contents of the repo to the underlying store. This call assumes
        the parser section has already been created.

        @param repo: repo instance to update in the parser; cannot be None
        @type  repo: L{Repo}
        """
        for k, v in repo.items():
            if v:
                self.parser.set(repo.id, k, v)
            else:
                self.parser.remove_option(repo.id, k)

    def _parser_to_repo(self, repo_name):
        """
        Utility for converting the config parser section into a repo object.

        @param repo_name: name of the repo being retrieved from the store
        @type  repo_name: string

        @return: repo instance populated from the section data
        @rtype:  L{Repo}
        """
        repo = Repo(repo_name)
        for key, value in self.parser.items(repo_name):
            repo[key] = value

        return repo
开发者ID:pgustafs,项目名称:pulp_rpm,代码行数:104,代码来源:repo_file.py


注:本文中的iniparse.ConfigParser.sections方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。