From a9d4e6114fcc3786781e869140f35567f99d24b5 Mon Sep 17 00:00:00 2001 From: BJ Dierkes Date: Fri, 3 Aug 2012 17:26:10 -0500 Subject: [PATCH] Further resolves Issue #100 --- ChangeLog | 13 ++++++++++--- cement/core/foundation.py | 2 +- cement/core/log.py | 8 ++++---- cement/core/plugin.py | 22 ++++++++++++++-------- cement/ext/ext_logging.py | 19 +++++++++---------- cement/ext/ext_plugin.py | 9 +++------ tests/core/log_tests.py | 4 ++++ tests/core/plugin_tests.py | 16 ++++++++-------- tests/ext/logging_tests.py | 2 +- 9 files changed, 54 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 259523aa..3360815a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/cement/core/foundation.py b/cement/core/foundation.py index d3cd4483..2888cc6e 100644 --- a/cement/core/foundation.py +++ b/cement/core/foundation.py @@ -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: diff --git a/cement/core/log.py b/cement/core/log.py index 7e006c58..c997903a 100644 --- a/cement/core/log.py +++ b/cement/core/log.py @@ -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): diff --git a/cement/core/plugin.py b/cement/core/plugin.py index 70cccbc0..9b1b9100 100644 --- a/cement/core/plugin.py +++ b/cement/core/plugin.py @@ -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): """ diff --git a/cement/ext/ext_logging.py b/cement/ext/ext_logging.py index cbb9423e..4a32f098 100644 --- a/cement/ext/ext_logging.py +++ b/cement/ext/ext_logging.py @@ -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: diff --git a/cement/ext/ext_plugin.py b/cement/ext/ext_plugin.py index 9a5545ae..adc4b59f 100644 --- a/cement/ext/ext_plugin.py +++ b/cement/ext/ext_plugin.py @@ -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 diff --git a/tests/core/log_tests.py b/tests/core/log_tests.py index 274e2e5e..806ef829 100644 --- a/tests/core/log_tests.py +++ b/tests/core/log_tests.py @@ -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() diff --git a/tests/core/plugin_tests.py b/tests/core/plugin_tests.py index 6e39e3d7..a91afaf0 100644 --- a/tests/core/plugin_tests.py +++ b/tests/core/plugin_tests.py @@ -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) diff --git a/tests/ext/logging_tests.py b/tests/ext/logging_tests.py index 8c2803c0..316fe693 100644 --- a/tests/ext/logging_tests.py +++ b/tests/ext/logging_tests.py @@ -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()