本文整理汇总了Python中config.Configuration.getbool方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.getbool方法的具体用法?Python Configuration.getbool怎么用?Python Configuration.getbool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类config.Configuration
的用法示例。
在下文中一共展示了Configuration.getbool方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Environment
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import getbool [as 别名]
class Environment(Component, ComponentManager):
"""The environment loads plugins """
commands = ExtensionPoint(IShellCommandProvider)
console_objects = ExtensionPoint(IShellConsoleObjectProvider)
env_objects = ExtensionPoint(IEnvObjectProvider)
def __init__(self, config=None, entry_point=None, plugins=None,
logger=None, locals=None):
"""Initialize the Dustbowl environment.
@param config: the absolute path to a configuration file.
@param entry_point: The entry point used to locate plugins.
@param plugins: a list of tuples containing paths in which to look for
plugins and a boolean indicating whether or not
plugins loaded from the specified path should be
auto-enabled.
@param logger: a Python logger instance.
``sys.path`` will be automatically added to the list of plugin
directories. All entries of ``sys.path`` will not be auto-enabled.
"""
ComponentManager.__init__(self)
self.setup_config(config)
self.setup_log(logger)
# Load plugins
self.plugin_data = dict()
if not plugins:
plugins = list()
self.load_modules(plugins, entry_point=entry_point)
if locals:
self.parent_locals = locals
for provider in self.console_objects:
for key, value in provider.get_console_objects():
self.add_console_object(key, value, provider.__class__.__name__)
continue
continue
for provider in self.env_objects:
for key, value in provider.get_env_objects():
self.add_env_object(key, value, provider.__class__.__name__)
continue
continue
def component_activated(self, component):
"""Initialize additional member variables for components.
Every component activated through the `Environment` object gets three
member variables: `env` (the environment object), `config` (the
environment configuration) and `log` (a logger object)."""
component.env = self
component.config = self.config
component.log = self.log
def is_component_enabled(self, cls):
"""Implemented to only allow activation of components that are not
disabled in the configuration.
This is called by the `ComponentManager` base class when a component is
about to be activated. If this method returns false, the component does
not get activated."""
if not isinstance(cls, basestring):
component_name = (cls.__module__ + '.' + cls.__name__).lower()
else:
component_name = cls.lower()
for key, value in self.plugin_data.iteritems():
if component_name == key or component_name.startswith(key + '.'):
value['activated'] = True
return value['loaded']
return False
def setup_config(self, configpath):
"""Load the configuration file."""
self.config = Configuration(configpath)
def setup_log(self, logger):
"""Initialize the logging sub-system."""
if logger:
self.log = logger
else:
self.log = NullLogger()
def is_enabled(self, module_name):
""" Return whether a module is enabled in the config.
"""
for key, value in self.config.options('components'):
k = key.lower()
mod = module_name.lower()
if mod == k or k.endswith('*') and mod.startswith(k[:-1]):
return self.config.getbool('components', key)
return False
def load_modules(self, plugins=None, entry_point='dustbowl.modules'):
#.........这里部分代码省略.........