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


Python Configuration.set方法代码示例

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


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

示例1: set_home_config

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set [as 别名]
 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,代码行数:12,代码来源:migration.py

示例2: _update_sample_config

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set [as 别名]
 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,代码行数:16,代码来源:env.py

示例3: writeconfig

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set [as 别名]
 def writeconfig(self, filepath, dicts=[]):
     """Writes or updates a config file. A list of dictionaries is used so
     that options for different aspects of the configuration can be kept
     separate while being able to update the same sections. Note that the
     result is order dependent where two dictionaries update the same option.
     """
     config = Configuration(filepath)
     file_changed = False
     for data in dicts:
         for section, options in data.iteritems():
             for key, value in options.iteritems():
                 if config.get(section, key, None) != value:
                     # This should be expected to generate a false positive
                     # when two dictionaries update the same option
                     file_changed = True
                 config.set(section, key, value)
     if file_changed:
         if os.path.exists(filepath):
             backupfile(filepath)
         config.save()
开发者ID:domaemon,项目名称:bloodhound-qa,代码行数:22,代码来源:bloodhound_setup.py

示例4: create

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set [as 别名]
    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,代码行数:39,代码来源:env.py

示例5: do

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set [as 别名]
    def do(self):
        # Make backup of trac.ini before configuring it
        try:
            shutil.copy(self.conf_file, self.conf_file_back)
        except Exception:
            conf.log.exception("Could not create trac.ini backup")
            return False

        # Open trac.ini for configuration
        config = None
        try:
            config = Configuration(self.conf_file)
        except Exception:
            conf.log.exception("Error while reading config file!")
            return False

        # Enable correct plugin for repository
        try:
            vcs_plugin = self.__vcs_plugin()
            if vcs_plugin:
                config.set('components', vcs_plugin, 'enabled')

            config.set('trac', 'repository_type', self.vcs_type)
        except Exception:
            conf.log.exception("Could not set static settings for trac")
            return False

        try:
            config.set('project', 'descr', self.project.description)
        except Exception:
            conf.log.exception("Couldn't set description")
            return False

        # Remove attachment size (to enable global setting)
        try:
            config.remove("attachment", "max_size")
        except Exception:
            conf.log.exception("Could not remove attachment config property for a new project")

        # Save configuration
        try:
            config.save()
        except Exception:
            conf.log.exception("Failed to save configuration")
            return False

        self.success = True
        return True
开发者ID:juhamust,项目名称:multiproject,代码行数:50,代码来源:commands.py

示例6: EnvironmentStub

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set [as 别名]
class EnvironmentStub(Environment):
    """A stub of the trac.env.Environment object for testing."""

    global_databasemanager = None
    required = False

    def __init__(self, default_data=False, enable=None, disable=None,
                 path=None, destroying=False):
        """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.
        :param disable: A list of component classes or name globs to
                        deactivate in the stub environment.
        :param path: The location of the environment in the file system.
                     No files or directories are created when specifying
                     this parameter.
        :param destroying: If True, the database will not be reset. This is
                           useful for cases when the object is being
                           constructed in order to call `destroy_db`.
        """
        if enable is not None and not isinstance(enable, (list, tuple)):
            raise TypeError('Keyword argument "enable" must be a list')
        if disable is not None and not isinstance(disable, (list, tuple)):
            raise TypeError('Keyword argument "disable" must be a list')

        ComponentManager.__init__(self)

        self.systeminfo = []

        import trac
        self.path = path
        if self.path is None:
            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')
        else:
            self.config.set('components', 'tracopt.versioncontrol.*',
                            'enabled')
        for name_or_class in enable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'enabled')
        for name_or_class in disable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'disabled')

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

        # -- database
        self.config.set('components', 'trac.db.*', 'enabled')
        self.dburi = get_dburi()

        init_global = False
        if self.global_databasemanager:
            self.components[DatabaseManager] = self.global_databasemanager
        else:
            self.config.set('trac', 'database', self.dburi)
            self.global_databasemanager = DatabaseManager(self)
            self.config.set('trac', 'debug_sql', True)
            init_global = not destroying

        if default_data or init_global:
            self.reset_db(default_data)

        self.config.set('trac', 'base_url', 'http://example.org/trac.cgi')

        self.known_users = []
        translation.activate(locale_en)

    def reset_db(self, default_data=None):
        """Remove all data from Trac tables, keeping the tables themselves.
        :param default_data: after clean-up, initialize with default data
        :return: True upon success
        """
        from trac import db_default
        scheme, db_prop = _parse_db_str(self.dburi)
        tables = []
        remove_sqlite_db = False
        try:
            with self.db_transaction as db:
                db.rollback()  # make sure there's no transaction in progress
                # check the database version
                database_version = self.get_version()
        except Exception:
            # "Database not found ...",
#.........这里部分代码省略.........
开发者ID:exocad,项目名称:exotrac,代码行数:103,代码来源:test.py

示例7: EnvironmentStub

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set [as 别名]
class EnvironmentStub(Environment):
    """A stub of the trac.env.Environment object for testing."""

    href = abs_href = None
    dbenv = db = None

    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'))
        
    def get_read_db(self):
        return self.get_db_cnx()
    
    def get_db_cnx(self, destroying=False):
        if self.db:
            return self.db # in-memory SQLite

        # As most of the EnvironmentStubs are built at startup during
        # the test suite formation and the creation of test cases, we can't
        # afford to create a real db connection for each instance.
        # So we create a special EnvironmentStub instance in charge of
        # getting the db connections for all the other instances.
        dbenv = EnvironmentStub.dbenv
        if not dbenv:
            dbenv = EnvironmentStub.dbenv = EnvironmentStub()
            dbenv.config.set('trac', 'database', self.dburi)
            if not destroying:
                self.reset_db() # make sure we get rid of previous garbage
        return DatabaseManager(dbenv).get_connection()

    def reset_db(self, default_data=None):
        """Remove all data from Trac tables, keeping the tables themselves.
        :param default_data: after clean-up, initialize with default data
        :return: True upon success
        """
        from trac import db_default
        if EnvironmentStub.dbenv:
            db = self.get_db_cnx()
            scheme, db_prop = _parse_db_str(self.dburi)

            tables = []
            db.rollback() # make sure there's no transaction in progress
            try:
                # check the database version
                cursor = db.cursor()
                cursor.execute("SELECT value FROM system "
                               "WHERE name='database_version'")
                database_version = cursor.fetchone()
                if database_version:
                    database_version = int(database_version[0])
                if database_version == db_default.db_version:
                    # same version, simply clear the tables (faster)
                    m = sys.modules[__name__]
#.........这里部分代码省略.........
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:103,代码来源:test.py

示例8: EnvironmentStub

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set [as 别名]
class EnvironmentStub(Environment):
    """A stub of the trac.env.Environment class for testing."""

    global_databasemanager = None
    required = False
    abstract = True

    def __init__(self, default_data=False, enable=None, disable=None,
                 path=None, destroying=False):
        """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.
        :param disable: A list of component classes or name globs to
                        deactivate in the stub environment.
        :param path: The location of the environment in the file system.
                     No files or directories are created when specifying
                     this parameter.
        :param destroying: If True, the database will not be reset. This is
                           useful for cases when the object is being
                           constructed in order to call `destroy_db`.
        """
        if enable is not None and not isinstance(enable, (list, tuple)):
            raise TypeError('Keyword argument "enable" must be a list')
        if disable is not None and not isinstance(disable, (list, tuple)):
            raise TypeError('Keyword argument "disable" must be a list')

        ComponentManager.__init__(self)

        self.systeminfo = []

        import trac
        self.path = path
        if self.path is None:
            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')
        else:
            self.config.set('components', 'tracopt.versioncontrol.*',
                            'enabled')
        for name_or_class in enable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'enabled')
        for name_or_class in disable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'disabled')

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

        # -- database
        self.config.set('components', 'trac.db.*', 'enabled')
        self.dburi = get_dburi()

        init_global = False
        if self.global_databasemanager:
            self.components[DatabaseManager] = self.global_databasemanager
        else:
            self.config.set('trac', 'database', self.dburi)
            self.global_databasemanager = DatabaseManager(self)
            self.config.set('trac', 'debug_sql', True)
            init_global = not destroying

        if default_data or init_global:
            self.reset_db(default_data)

        self.config.set('trac', 'base_url', 'http://example.org/trac.cgi')

        translation.activate(locale_en)

    def reset_db(self, default_data=None):
        """Remove all data from Trac tables, keeping the tables themselves.

        :param default_data: after clean-up, initialize with default data
        :return: True upon success
        """
        from trac import db_default
        tables = []
        dbm = self.global_databasemanager
        try:
            with self.db_transaction as db:
                db.rollback()  # make sure there's no transaction in progress
                # check the database version
                db_version = dbm.get_database_version()
        except (TracError, self.env.db_exc.DatabaseError):
            pass
#.........这里部分代码省略.........
开发者ID:spsoft-RockWang,项目名称:project-_trac,代码行数:103,代码来源:test.py

示例9: sync

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set [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

示例10: _do_update

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set [as 别名]
    def _do_update(self, req):
        """Update component enablement."""
        components = req.args.getlist('component')
        oenabled = req.args.getlist('enable')
        penabled = req.args.getlist('prjenable')

        changes = False
        changed = {}

        # Set global project configuration
        prjconf = Configuration(conf.global_conf_path)

        for component in components:
            c_state = self.get_project_component_state(component, self.config)
            c_activated = (component in oenabled)

            if self.is_plugin_changed(c_state, c_activated):
                self.config.set('components', component,
                                c_activated and 'enabled' or 'disabled')
                self.log.info('%sabling component %s',
                                c_activated and 'En' or 'Dis', component)
                changes = True

            if prjconf:
                cip_state = self.get_project_component_state(component, prjconf)
                cip_activated = (component in penabled)

                if self.is_plugin_changed(cip_state, cip_activated):
                    self.log.info('%sabling project component %s',
                                    cip_activated and 'En' or 'Dis', component)
                    changed[component] = cip_activated and 'enabled' or 'disabled'
                    changes = True

        if prjconf:
            scomponents = req.args.getlist('setting')
            static_items = req.args.getlist('static_setting')

            for scomponent in scomponents:
                values = self.get_project_component_value(scomponent, None, prjconf)
                saved_value = self.parse_value(0, values)
                saved_static = self.parse_value(1, values)

                current_value = req.args.get(scomponent + '.value').replace('|', '')
                current_static = (scomponent in static_items)

                if saved_value != current_value or saved_static != current_static:
                    if current_static:
                        final_value = current_value
                    else:
                        final_value = current_value + '|no'

                    prjconf.set('settings', scomponent, final_value)
                    changes = True

        if changes:
            self.config.save()

            if prjconf:
                for key in changed.keys():
                    prjconf.set('components', key, changed[key])
                prjconf.save()
开发者ID:alvabai,项目名称:trac-multiproject,代码行数:63,代码来源:plugins.py

示例11: EnvironmentStub

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set [as 别名]
class EnvironmentStub(Environment):
    """A stub of the trac.env.Environment object for testing."""

    href = abs_href = None
    global_databasemanager = None

    def __init__(self, default_data=False, enable=None, disable=None,
                 path=None, destroying=False):
        """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 = path
        if self.path is None:
            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')
        else:
            self.config.set('components', 'tracopt.versioncontrol.svn.*',
                            'enabled')
        for name_or_class in enable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'enabled')
        for name_or_class in disable or ():
            config_key = self._component_name(name_or_class)
            self.config.set('components', config_key, 'disabled')

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

        # -- database
        self.config.set('components', 'trac.db.*', 'enabled')
        self.dburi = get_dburi()

        init_global = False
        if self.global_databasemanager:
            self.components[DatabaseManager] = self.global_databasemanager
        else:
            self.config.set('trac', 'database', self.dburi)
            self.global_databasemanager = DatabaseManager(self)
            self.config.set('trac', 'debug_sql', True)
            self.config.set('logging', 'log_type', 'stderr')
            self.config.set('logging', 'log_level', 'DEBUG')
            init_global = not destroying

        if default_data or init_global:
            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_en)

    def reset_db(self, default_data=None):
        """Remove all data from Trac tables, keeping the tables themselves.
        :param default_data: after clean-up, initialize with default data
        :return: True upon success
        """
        from trac import db_default
        scheme, db_prop = _parse_db_str(self.dburi)
        tables = []
        remove_sqlite_db = False
        try:
            with self.db_transaction as db:
                db.rollback() # make sure there's no transaction in progress
                # check the database version
                database_version = db(
                    "SELECT value FROM system WHERE name='database_version'")
                if database_version:
                    database_version = int(database_version[0][0])
                if database_version == db_default.db_version:
                    # same version, simply clear the tables (faster)
                    m = sys.modules[__name__]
                    reset_fn = 'reset_%s_db' % scheme
                    if hasattr(m, reset_fn):
                        tables = getattr(m, reset_fn)(self, db_prop)
                else:
#.........这里部分代码省略.........
开发者ID:thimalk,项目名称:bloodhound,代码行数:103,代码来源:test.py

示例12: MockEnvironment

# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import set [as 别名]
class MockEnvironment(Environment):
    """
    An mock Environment object which does not need real environment.
    Useful for when needing real environment like access to loaded plugins etc
    but no environment is at hand. Looks like normal project by default but can be
    made to look like home project environment or hybrid of both.

    .. WARNING:: Be careful when using this!
    """
    def __init__(self, config_file=None, enabled_plugins=None, path=None):
        """
        :param str config_file: path to the main configuration file.
            Defaults to ``/etc/trac/project.ini`` which is normal project configuration.
        :param list enabled_plugins:
            An explicit list of plugins to load, instead of reading enabled [components]
            from ``config_file``. If empty list is given no plugins are loaded.
            However plugins can be still listed via ``extra_plugins`` arg.
        :param str path: path to the imaginary trac location.
        """
        if config_file is None:
            # TODO: switch to some constant when can be done without conf
            from multiproject.core.configuration import conf
            config_file = conf.config_file

        # From Environment.setup_config:
        self.config = Configuration(config_file)

        if path is None:
            path = os.path.join(self.config.get('multiproject', 'sys_projects_root'), '__mock_environment__')
        if enabled_plugins is not None:
            # explicit list given, disable all from configuration
            for key, val in self.config.options('components'):
                self.config.remove('components', key)
            # and replace with the given list
            for plugin in enabled_plugins:
                self.config.set('components', plugin, u'enabled')

        # We override the Environment.__init__ here.

        # Environment.__init__ is as follows:

        # ComponentManager.__init__(self)
        #
        # self.path = path
        # self.systeminfo = []
        # self._href = self._abs_href = None
        #
        # if create:
        #     self.create(options)
        # else:
        #     self.verify()
        #     self.setup_config()
        #
        # if create:
        #     for setup_participant in self.setup_participants:
        #         setup_participant.environment_created()

        # The Environment.setup_config is as follows:

        # self.config = Configuration(os.path.join(self.path, 'conf',
        #         'trac.ini'))
        #         self.setup_log()
        #         from trac.loader import load_components
        #         plugins_dir = self.shared_plugins_dir
        #         load_components(self, plugins_dir and (plugins_dir,))

        # We use suitable lines from these as follows:

        # From Environment.__init__:
        ComponentManager.__init__(self)

        self.path = path
        self.systeminfo = []
        self._href = self._abs_href = None

        # Our own plugin hack ends here, and setup_config lines continue here
        self.setup_log()
        from trac.loader import load_components
        load_components(self)
开发者ID:alvabai,项目名称:trac-multiproject,代码行数:81,代码来源:mockenv.py


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