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


Python Configuration.set_defaults方法代码示例

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


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

示例1: cli_command

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set_defaults [as 别名]
    def cli_command(self, project, args):
        """Manipulate the trac environment for a project
        
        Supported arguments:
        - create: creates an environment
        - sync: Synchronizes the configuration with Cydra's requirements
        - addrepo <type> <name> [tracname]: adds the repository to trac, identified by tracname
        - updatedefaults <file>: Adds trac's default options to config"""

        if len(args) < 1 or args[0] not in ['create', 'addrepo', 'sync', 'updatedefaults']:
            print self.cli_command.__doc__
            return

        if args[0] == 'create':
            if self.has_env(project):
                print "Project already has a Trac environment!"
                return

            if self.create(project):
                print "Environment created"
            else:
                print "Creation failed!"

        elif args[0] == 'sync':
            self.sync(project)

            print project.name, "synced"

        elif args[0] == 'addrepo':
            if len(args) < 3:
                print self.cli_command.__doc__
                return

            repository = project.get_repository(args[1], args[2])

            if not repository:
                print "Unknown repository"
                return

            ret = False
            if len(args) == 4:
                ret = self.register_repository(repository, args[3])
            else:
                ret = self.register_repository(repository)

            if ret:
                print "Successfully added repository"
            else:
                print "Adding repository failed!"

        elif args[0] == 'updatedefaults':
            if len(args) < 2:
                print self.cli_command.__doc__
                return

            config = Configuration(args[1])
            # load defaults
            config.set_defaults()
            config.save()
开发者ID:akuendig,项目名称:cydra,代码行数:61,代码来源:__init__.py

示例2: sync

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set_defaults [as 别名]
    def sync(self, project):
        """Sync the trac environment with cydra
        
        This sets the options returned by ``get_default_options`` and adds Trac's own defaults if necessary"""
        if not self.has_env(project):
            logger.warning('Project %s has no Trac Environment to sync', project.name)
            return

        tracini = os.path.join(self.get_env_path(project), 'conf', 'trac.ini')
        options = self.get_default_options(project)

        # if inherit is enabled, the default values are supposed to be in
        # the inherited file. Thus, we can truncate the config file to get a bare minimum
        if 'inherit_config' in self.component_config:
            options.append(('inherit', 'file', self.component_config['inherit_config']))
            with open(tracini, 'w') as f:
                f.truncate()

        # re-create the configuration file
        config = Configuration(tracini)
        for section, name, value in options:
            config.set(section, name, value)
        config.save()

        # load defaults
        if not any((section, option) == ('inherit', 'file') for section, option, value in options):
            config.set_defaults()
            config.save()

        # check if repositories in cydra match repositories in trac
        env = Environment(self.get_env_path(project))
        rm = RepositoryManager(env)
        trac_repos = rm.get_real_repositories()
        trac_repo_names = [r.reponame for r in trac_repos]

        for repotype, repos in project.data.get('plugins', {}).get('trac', {}).items():
            for repo, tracname in (repos or {}).items():
                if tracname not in trac_repo_names:
                    logger.warning("Removing trac mapping from cydra for %s repo %s", repo, tracname)
                    del repos[repo]
                    if not repos:
                        del project.data.get('plugins', {}).get('trac', {})[repotype]

        # Now do the reverse
        revmap = dict([(y, x) for (x, y) in self.typemap.items()])

        for repo in trac_repos:
            logger.debug('Looking at trac repo %s', repo.reponame)

            try:
                baseparts = repo.get_base().split(':') # This is extremely naiive and possibly breaks some time
                repotype, path = baseparts[0], baseparts[-1]
            except:
                logger.error("Unable to parse: " + repo.get_base())

            reponame = os.path.basename(path)
            if repotype == 'git':
                reponame = reponame[:-4]

            try:
                repository = project.get_repository(revmap[repotype], reponame)
            except:
                logger.error("Unable to locate %s %s (%s)", repotype, reponame, path)
                repository = None

            logger.debug('Cydra repo %r', repository)

            if repository:
                # set this mapping if not there already
                project.data.setdefault('plugins', {}).setdefault('trac', {}).setdefault(repository.type, {})[repository.name] = repo.reponame
                logger.info('Setting trac mapping for %s %s -> %s', repository.type, repository.name, repo.reponame)
            else:
                logger.error("Unable to load %s %s (%s)", revmap[repotype], reponame, path)

        project.save()
开发者ID:akuendig,项目名称:cydra,代码行数:77,代码来源:__init__.py


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