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


Python config.Configuration类代码示例

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


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

示例1: getSettings

    def getSettings(self, cls, store):
        if not isinstance(cls, basestring):
            mymodule = cls.__module__.lower()
        else:
            mymodule = cls.lower()

        # Do not add duplicates
        for object in store:
            if mymodule in object['module']:
                return

        mycount = len(mymodule.split('.'))

        prjconf = Configuration(conf.global_conf_path)

        rules = [(name.lower(), value.lower())
                 for name, value in prjconf.options('components')]
        rules.sort(lambda a, b:-cmp(len(a[0]), len(b[0])))

        for pattern, value in rules:
            if pattern.startswith(mymodule + '.'):
                item = pattern.split(".")
                count = len(item)
                if count > mycount:
                    header = item[mycount]
                    if count > (mycount + 1):
                        store.append({
                                'module': mymodule,
                                'name':  header + '.' + item[mycount + 1],
                                'default': self.parse_value(0, value),
                                'static':  self.parse_boolean_value(1, value, True)
                            })
开发者ID:alvabai,项目名称:trac-multiproject,代码行数:32,代码来源:plugins.py

示例2: cli_command

    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,代码行数:59,代码来源:__init__.py

示例3: load_workflow_config_snippet

def load_workflow_config_snippet(config, filename):
    """Loads the ticket-workflow section from the given file (expected to be in
    the 'workflows' tree) into the provided config.
    """
    filename = resource_filename('trac.ticket', 'workflows/%s' % filename)
    new_config = Configuration(filename)
    for name, value in new_config.options('ticket-workflow'):
        config.set('ticket-workflow', name, value)
开发者ID:pkdevbox,项目名称:trac,代码行数:8,代码来源:default_workflow.py

示例4: SvnServePasswordStore

class SvnServePasswordStore(Component):
    """PasswordStore implementation for reading svnserve's password file format
    """

    implements(IPasswordStore)

    filename = EnvRelativePathOption('account-manager', 'password_file',
        doc="""Path to the users file; leave blank to locate the users file
        by reading svnserve.conf from the default repository.
        """)

    _userconf = None

    @property
    def _config(self):
        filename = self.filename or self._get_password_file()
        if self._userconf is None or filename != self._userconf.filename:
            self._userconf = Configuration(filename)
            # Overwrite default with str class to preserve case.
            self._userconf.parser.optionxform = str
            self._userconf.parse_if_needed(force=True)
        else:
            self._userconf.parse_if_needed()
        return self._userconf

    def _get_password_file(self):
        repos = RepositoryManager(self.env).get_repository('')
        if not repos:
            return None
        if isinstance(repos, CachedRepository):
            repos = repos.repos
        if repos.params['type'] in ('svn', 'svnfs', 'direct-svnfs'):
            conf = Configuration(os.path.join(repos.path, 'conf',
                                              'svnserve.conf'))
            return conf['general'].getpath('password-db')

    # IPasswordStore methods

    def get_users(self):
        return [user for (user, password) in self._config.options('users')]

    def has_user(self, user):
        return user in self._config['users']

    def set_password(self, user, password, old_password=None):
        cfg = self._config
        cfg.set('users', user, password)
        cfg.save()

    def check_password(self, user, password):
        if self.has_user(user):
            return password == self._config.get('users', user)
        return None

    def delete_user(self, user):
        cfg = self._config
        cfg.remove('users', user)
        cfg.save()
开发者ID:t-kenji,项目名称:trac-account-manager-plugin,代码行数:58,代码来源:svnserve.py

示例5: readconfig

def readconfig(filename):
    """Returns a list of raw config options"""
    config = Configuration(filename)
    rawactions = list(config.options('ticket-workflow'))
    debug("%s\n" % str(rawactions))
    if not rawactions:
        sys.stderr.write("ERROR: You don't seem to have a [ticket-workflow] "
                         "section.\n")
        sys.exit(1)
    return rawactions
开发者ID:pkdevbox,项目名称:trac,代码行数:10,代码来源:workflow_parser.py

示例6: set_home_config

 def set_home_config(self, values):
     syspath = self.conf.getEnvironmentSysPath("home")
     setconf = Configuration(syspath + '/conf/trac.ini')
     try:
         for (main, sub, value) in values:
             setconf.set(main, sub, value)
         setconf.save()
     except:
         return False
     return True
开发者ID:alvabai,项目名称:trac-multiproject,代码行数:10,代码来源:migration.py

示例7: SvnServePasswordStore

class SvnServePasswordStore(Component):
    """PasswordStore implementation for reading svnserve's password file format
    """

    implements(IPasswordStore)

    filename = EnvRelativePathOption('account-manager', 'password_file',
        doc = N_("""Path to the users file; leave blank to locate
                the users file by reading svnserve.conf"""))

    def __init__(self):
        repo_dir = RepositoryManager(self.env).repository_dir
        self._svnserve_conf = Configuration(os.path.join(os.path.join(
                                  repo_dir, 'conf'), 'svnserve.conf'))
        self._userconf = None

    def _config(self):
        filename = self.filename
        if not filename:
            self._svnserve_conf.parse_if_needed()
            filename = self._svnserve_conf['general'].getpath('password-db')
        if self._userconf is None or filename != self._userconf.filename:
            self._userconf = Configuration(filename)
        else:
            self._userconf.parse_if_needed()
        return self._userconf
    _config = property(_config)

    # IPasswordStore methods

    def get_users(self):
        return [user for (user,password) in self._config.options('users')]

    def has_user(self, user):
        return user in self._config['users']
 
    def set_password(self, user, password, old_password = None):
        cfg = self._config
        cfg.set('users', user, password)
        cfg.save()
 
    def check_password(self, user, password):
        if self.has_user(user):
            return password == self._config.get('users', user)
        return None

    def delete_user(self, user):
        cfg = self._config
        cfg.remove('users', user)
        cfg.save()
开发者ID:lkraav,项目名称:trachacks,代码行数:50,代码来源:svnserve.py

示例8: _update_sample_config

 def _update_sample_config(self):
     filename = os.path.join(self.env.config_file_path + ".sample")
     if not os.path.isfile(filename):
         return
     config = Configuration(filename)
     for (section, name), option in Option.get_registry().iteritems():
         config.set(section, name, option.dumps(option.default))
     try:
         config.save()
         self.log.info(
             "Wrote sample configuration file with the new " "settings and their default values: %s", filename
         )
     except IOError as e:
         self.log.warn("Couldn't write sample configuration file (%s)", e, exc_info=True)
开发者ID:spsoft-RockWang,项目名称:project-_trac,代码行数:14,代码来源:env.py

示例9: _config

 def _config(self):
     filename = self.filename
     if not filename:
         self._svnserve_conf.parse_if_needed()
         filename = self._svnserve_conf['general'].getpath('password-db')
     if self._userconf is None or filename != self._userconf.filename:
         self._userconf = Configuration(filename)
     else:
         self._userconf.parse_if_needed()
     return self._userconf
开发者ID:lkraav,项目名称:trachacks,代码行数:10,代码来源:svnserve.py

示例10: post_process_request

    def post_process_request(self, req, template, content_type):
        global_scripts = Configuration.getlist(self.config, 'flexjs', 'global')
        for script in global_scripts:
            add_script(req, 'common/js/flex/'+script)

        ext_scripts = Configuration.getlist(self.config, 'flexjs', 'ext')
        idx = 0
        js = req.hdf.get('chrome.scripts.%i.href' % idx)
        idx = len(js)
        for script in ext_scripts:
            req.hdf['chrome.scripts.%i' % idx] = {'href': script, 'type': 'text/javascript'}
            idx += 1
            
        local_scripts = Configuration.getlist(self.config, 'flexjs', 'local')
        for script in local_scripts:
            add_script(req, 'site/js/'+script)
        
        return (template, content_type)
        
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:18,代码来源:flexjs.py

示例11: _config

 def _config(self):
     filename = self.filename or self._get_password_file()
     if self._userconf is None or filename != self._userconf.filename:
         self._userconf = Configuration(filename)
         # Overwrite default with str class to preserve case.
         self._userconf.parser.optionxform = str
         self._userconf.parse_if_needed(force=True)
     else:
         self._userconf.parse_if_needed()
     return self._userconf
开发者ID:t-kenji,项目名称:trac-account-manager-plugin,代码行数:10,代码来源:svnserve.py

示例12: _config

 def _config(self):
     filename = self.filename
     if not filename:
         self._svnserve_conf.parse_if_needed()
         filename = self._svnserve_conf['general'].getpath('password-db')
     if self._userconf is None or filename != self._userconf.filename:
         self._userconf = Configuration(filename)
         # Overwrite default with str class to preserve case.
         self._userconf.parser.optionxform = str
         self._userconf.parse_if_needed(force=True)
     else:
         self._userconf.parse_if_needed()
     return self._userconf
开发者ID:51reboot,项目名称:huangweiyi,代码行数:13,代码来源:svnserve.py

示例13: __init__

    def __init__(self, default_data=False, enable=None):
        """Construct a new Environment stub object.

        :param default_data: If True, populate the database with some
                             defaults.
        :param enable: A list of component classes or name globs to
                       activate in the stub environment.
        """
        ComponentManager.__init__(self)
        Component.__init__(self)
        self.systeminfo = []

        import trac
        self.path = os.path.dirname(trac.__file__)
        if not os.path.isabs(self.path):
            self.path = os.path.join(os.getcwd(), self.path)

        # -- configuration
        self.config = Configuration(None)
        # We have to have a ticket-workflow config for ''lots'' of things to
        # work.  So insert the basic-workflow config here.  There may be a
        # better solution than this.
        load_workflow_config_snippet(self.config, 'basic-workflow.ini')
        self.config.set('logging', 'log_level', 'DEBUG')
        self.config.set('logging', 'log_type', 'stderr')
        if enable is not None:
            self.config.set('components', 'trac.*', 'disabled')
        for name_or_class in enable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'enabled')

        # -- logging
        from trac.log import logger_handler_factory
        self.log, self._log_handler = logger_handler_factory('test')

        # -- database
        self.dburi = get_dburi()
        if self.dburi.startswith('sqlite'):
            self.config.set('trac', 'database', 'sqlite::memory:')
            self.db = InMemoryDatabase()

        if default_data:
            self.reset_db(default_data)

        from trac.web.href import Href
        self.href = Href('/trac.cgi')
        self.abs_href = Href('http://example.org/trac.cgi')

        self.known_users = []
        translation.activate(Locale and Locale('en', 'US'))
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:50,代码来源:test.py

示例14: create

    def create(self, options=[]):
        """Create the basic directory structure of the environment,
        initialize the database and populate the configuration file
        with default values.

        If options contains ('inherit', 'file'), default values will
        not be loaded; they are expected to be provided by that file
        or other options.
        """
        # Create the directory structure
        if not os.path.exists(self.path):
            os.mkdir(self.path)
        os.mkdir(self.get_log_dir())
        os.mkdir(self.get_htdocs_dir())
        os.mkdir(os.path.join(self.path, 'plugins'))

        # Create a few files
        create_file(os.path.join(self.path, 'VERSION'), _VERSION + '\n')
        create_file(os.path.join(self.path, 'README'),
                    'This directory contains a Trac environment.\n'
                    'Visit http://trac.edgewall.org/ for more information.\n')

        # Setup the default configuration
        os.mkdir(os.path.join(self.path, 'conf'))
        create_file(self.config_file_path + '.sample')
        config = Configuration(self.config_file_path)
        for section, name, value in options:
            config.set(section, name, value)
        config.save()
        self.setup_config()
        if not any((section, option) == ('inherit', 'file')
                   for section, option, value in options):
            self.config.set_defaults(self)
            self.config.save()

        # Create the database
        DatabaseManager(self).init_db()
开发者ID:pkdevbox,项目名称:trac,代码行数:37,代码来源:env.py

示例15: __init__

    def __init__(self, default_data=False, enable=None):
        """Construct a new Environment stub object.

        default_data: If True, populate the database with some defaults.
        enable: A list of component classes or name globs to activate in the
                stub environment.
        """
        ComponentManager.__init__(self)
        Component.__init__(self)
        self.enabled_components = enable or ['trac.*']
        self.systeminfo = [('Python', sys.version)]

        import trac
        self.path = os.path.dirname(trac.__file__)
        if not os.path.isabs(self.path):
            self.path = os.path.join(os.getcwd(), self.path)

        # -- configuration
        self.config = Configuration(None)
        # We have to have a ticket-workflow config for ''lots'' of things to
        # work.  So insert the basic-workflow config here.  There may be a
        # better solution than this.
        load_workflow_config_snippet(self.config, 'basic-workflow.ini')
        self.config.set('logging', 'log_level', 'DEBUG')
        self.config.set('logging', 'log_type', 'stderr')

        # -- logging
        from trac.log import logger_factory
        self.log = logger_factory('test')

        # -- database
        self.dburi = get_dburi()
        if self.dburi.startswith('sqlite'):
            self.db = InMemoryDatabase()

        if default_data:
            self.reset_db(default_data)

        from trac.web.href import Href
        self.href = Href('/trac.cgi')
        self.abs_href = Href('http://example.org/trac.cgi')

        self.known_users = []
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:43,代码来源:test.py


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