本文整理汇总了Python中trac.config.Configuration.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.remove方法的具体用法?Python Configuration.remove怎么用?Python Configuration.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.config.Configuration
的用法示例。
在下文中一共展示了Configuration.remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do
# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import remove [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
示例2: MockEnvironment
# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import remove [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)