Further resolves Issue #100

This commit is contained in:
BJ Dierkes 2012-08-03 17:26:10 -05:00
parent ac52c1372d
commit a9d4e6114f
9 changed files with 54 additions and 41 deletions

View File

@ -40,6 +40,14 @@ Features:
Incompatible Changes:
* :issue:`100` - Interfaces audit.
* ILog.level() redefined as ILog.get_level()
* IPlugin.loaded_plugins attribute redefined as
IPlugin.get_loaded_plugins()
* IPlugin.enable_plugins attribute redefined as
IPlugin.get_enabled_plugins()
* IPlugin.disabled_plugins attribute redefined as
IPlugin.get_disabled_plugins()
* :issue:`145` - The IArgument interface no longer specifies that the
`parsed_args` be maintained by the handler implementation. This means
that `app.args.parsed_args` is no longer available, however
@ -55,12 +63,11 @@ Incompatible Changes:
instead.
* :issue:`154` - Validate for handler config_defaults and config_section
by default. Only incompatible if not previously sub-classing from
handler.CementBaseHandler.
handler.CementBaseHandler.
* :issue:`157` - CementRuntimeError renamed as FrameworkError
* :issue:`158` - CementSignalError renamed as CaughtSignal
* :issue:`159` - CementInterfaceError renamed as InterfaceError
Misc:
* :issue:`155` - Removed unused CementArgumentError, and

View File

@ -677,7 +677,7 @@ class CementApp(meta.MetaMixin):
self.plugin = self._resolve_handler('plugin',
self._meta.plugin_handler)
self.plugin.load_plugins(self._meta.plugins)
self.plugin.load_plugins(self.plugin.enabled_plugins)
self.plugin.load_plugins(self.plugin.get_enabled_plugins())
def _setup_output_handler(self):
if self._meta.output_handler is None:

View File

@ -12,7 +12,7 @@ def log_validator(klass, obj):
'_setup',
'clear_loggers',
'set_level',
'level',
'get_level',
'info',
'warn',
'error',
@ -70,12 +70,12 @@ class ILog(interface.Interface):
def set_level():
"""
Set the log level. Must except one of: ``['INFO', 'WARN', 'ERROR',
'DEBUG', or 'FATAL']``.
Set the log level. Must except atleast one of:
``['INFO', 'WARN', 'ERROR', 'DEBUG', or 'FATAL']``.
"""
def level():
def get_level():
"""Return a string representation of the log level."""
def info(msg):

View File

@ -11,9 +11,9 @@ def plugin_validator(klass, obj):
'_setup',
'load_plugin',
'load_plugins',
'loaded_plugins',
'enabled_plugins',
'disabled_plugins',
'get_loaded_plugins',
'get_enabled_plugins',
'get_disabled_plugins',
]
interface.validate(IPlugin, obj, members)
@ -45,9 +45,6 @@ class IPlugin(interface.Interface):
# Must be provided by the implementation
Meta = interface.Attribute('Handler meta-data')
loaded_plugins = interface.Attribute('List of loaded plugins')
enabled_plugins = interface.Attribute('List of enabled plugins')
disabled_plugins = interface.Attribute('List of disabled plugins')
def _setup(app_obj):
"""
@ -59,7 +56,7 @@ class IPlugin(interface.Interface):
"""
def load_plugin(self, plugin_name):
def load_plugin(plugin_name):
"""
Load a plugin whose name is 'plugin_name'.
@ -67,13 +64,22 @@ class IPlugin(interface.Interface):
"""
def load_plugins(self, plugin_list):
def load_plugins(plugin_list):
"""
Load all plugins from plugin_list.
:param plugin_list: A list of plugin names to load.
"""
def get_loaded_plugins():
"""Returns a list of plugins that have been loaded."""
def get_enabled_plugins():
"""Returns a list of plugins that are enabled in the config."""
def get_disabled_plugins():
"""Returns a list of plugins that are disabled in the config."""
class CementPluginHandler(handler.CementBaseHandler):
"""

View File

@ -146,7 +146,11 @@ class LoggingLogHandler(log.CementLogHandler):
for handler in logging.getLogger(self._meta.namespace).handlers:
handler.setLevel(level)
def get_level(self):
"""Returns the current log level."""
return logging.getLevelName(self.backend.level)
def clear_loggers(self):
"""Clear any previously configured logging namespaces."""
@ -162,12 +166,12 @@ class LoggingLogHandler(log.CementLogHandler):
"""Add a console log handler."""
console_handler = logging.StreamHandler()
if self.level() == logging.getLevelName(logging.DEBUG):
if self.get_level() == logging.getLevelName(logging.DEBUG):
format = logging.Formatter(self._meta.debug_format)
else:
format = logging.Formatter(self._meta.console_format)
console_handler.setFormatter(format)
console_handler.setLevel(getattr(logging, self.level()))
console_handler.setLevel(getattr(logging, self.get_level()))
self.backend.addHandler(console_handler)
def _setup_file_log(self):
@ -189,18 +193,13 @@ class LoggingLogHandler(log.CementLogHandler):
from logging import FileHandler
file_handler = FileHandler(file)
if self.level() == logging.getLevelName(logging.DEBUG):
if self.get_level() == logging.getLevelName(logging.DEBUG):
format = logging.Formatter(self._meta.debug_format)
else:
format = logging.Formatter(self._meta.file_format)
file_handler.setFormatter(format)
file_handler.setLevel(getattr(logging, self.level()))
file_handler.setLevel(getattr(logging, self.get_level()))
self.backend.addHandler(file_handler)
def level(self):
"""Returns the current log level."""
return logging.getLevelName(self.backend.level)
def _get_logging_kwargs(self, namespace, **kw):
if namespace is None:

View File

@ -181,18 +181,15 @@ class CementPluginHandler(plugin.CementPluginHandler):
for plugin_name in plugin_list:
self.load_plugin(plugin_name)
@property
def loaded_plugins(self):
def get_loaded_plugins(self):
"""List of plugins that have been loaded."""
return self._loaded_plugins
@property
def enabled_plugins(self):
def get_enabled_plugins(self):
"""List of plugins that are enabled (not necessary loaded yet)."""
return self._enabled_plugins
@property
def disabled_plugins(self):
def get_disabled_plugins(self):
"""List of disabled plugins"""
return self._disabled_plugins

View File

@ -44,6 +44,10 @@ class LogTestCase(test.CementTestCase):
app.log._setup(app)
app.log.set_level('BOGUS')
def test_get_level(self):
self.app.setup()
self.eq('INFO', self.app.log.get_level())
def test_console_log(self):
app = self.make_app('test', debug=True)
app.setup()

View File

@ -107,19 +107,19 @@ class PluginTestCase(test.CementTestCase):
shutil.rmtree(tmpdir)
# some more checks
res = 'myplugin' in app.plugin.enabled_plugins
res = 'myplugin' in app.plugin.get_enabled_plugins()
self.ok(res)
res = 'myplugin' in app.plugin.loaded_plugins
res = 'myplugin' in app.plugin.get_loaded_plugins()
self.ok(res)
res = 'myplugin2' in app.plugin.disabled_plugins
res = 'myplugin2' in app.plugin.get_disabled_plugins()
self.ok(res)
res = 'myplugin2' not in app.plugin.enabled_plugins
res = 'myplugin2' not in app.plugin.get_enabled_plugins()
self.ok(res)
res = 'myplugin2' not in app.plugin.loaded_plugins
res = 'myplugin2' not in app.plugin.get_loaded_plugins()
self.ok(res)
def test_disabled_plugins_from_files(self):
@ -144,7 +144,7 @@ class PluginTestCase(test.CementTestCase):
res = 'test_output_handler' not in backend.handlers['output']
self.ok(res)
res = 'myplugin2' not in app.plugin.enabled_plugins
res = 'myplugin2' not in app.plugin.get_enabled_plugins()
self.ok(res)
def test_bogus_plugin_from_files(self):
@ -167,7 +167,7 @@ class PluginTestCase(test.CementTestCase):
app.setup()
shutil.rmtree(tmpdir)
res = 'bogus_plugin' not in app.plugin.enabled_plugins
res = 'bogus_plugin' not in app.plugin.get_enabled_plugins()
self.ok(res)
@test.raises(exc.FrameworkError)
@ -209,7 +209,7 @@ class PluginTestCase(test.CementTestCase):
)
app.setup()
res = 'ext_json' in app.plugin.enabled_plugins
res = 'ext_json' in app.plugin.get_enabled_plugins()
self.ok(res)
shutil.rmtree(tmpdir)

View File

@ -57,7 +57,7 @@ class LoggingExtTestCase(test.CementTestCase):
)
app = self.make_app(config_defaults=defaults)
app.setup()
self.eq(app.log.level(), 'INFO')
self.eq(app.log.get_level(), 'INFO')
def test_clear_loggers(self):
self.app.setup()