refactor of how plugins load

This commit is contained in:
BJ Dierkes 2009-12-14 19:53:41 -06:00
parent 7865cb55ad
commit 07547fb3d5
9 changed files with 45 additions and 21 deletions

2
README
View File

@ -1,6 +1,6 @@
NAME: Cement
CREATOR/MAINTAINER: BJ Dierkes <wdierkes@5dollarwhitebox.org
CREATOR/MAINTAINER: BJ Dierkes <wdierkes@5dollarwhitebox.org>
DESCRIPTION:

View File

@ -143,10 +143,12 @@ def run_command(command_name):
raise CementArgumentError, \
"'%s' is a *namespace, not a command. See '%s --help' instead." % \
(namespace, namespace)
(cli_opts, cli_args) = parse_options(namespace=namespace)
set_config_opts_per_cli_opts(namespace, cli_opts)
# FIX ME: need a global_pre_command_hook here so that clibasic can
# look for -C and if so, parse the passed config files into the dict.
for res in run_hooks('global_post_options_hook'):
pass
@ -237,6 +239,7 @@ def lay_cement(default_app_config=None, version_banner=None):
log = get_logger(__name__)
load_all_plugins()
setup_logging('cement', clear_loggers=True)
setup_logging(namespaces['global'].config['app_module'])
@ -260,13 +263,17 @@ def load_plugin(plugin):
except ImportError, e:
raise CementConfigError, e
plugin_module = __import__('cement.plugins', globals(), locals(),
[plugin], -1)
try:
plugin_module = __import__('%s.plugins' % config['app_module'], globals(), locals(),
[plugin], -1)
getattr(plugin_module, plugin)
except AttributeError:
raise CementRuntimeError, "Failed loading plugin '%s', possibly syntax errors?" % plugin
except AttributeError, e:
try:
plugin_module = __import__('cement.plugins', globals(), locals(),
[plugin], -1)
getattr(plugin_module, plugin)
except AttributeError, e:
raise CementRuntimeError, "Failed loading plugin '%s', possibly syntax errors?" % plugin
plugin_config_file = os.path.join(
namespaces['global'].config['plugin_config_dir'], '%s.plugin' % plugin
@ -334,7 +341,7 @@ def parse_options(namespace='global'):
if namespace == 'global':
for nam in namespaces:
if nam != 'global':
if nam != 'global' and namespaces[nam].commands:
if line == ' ':
line += '*%s' % nam
elif len(line) + len(nam) < 55:

View File

@ -173,8 +173,11 @@ Example usage::
self.__dict__.update(self.options.__dict__)
if self.args:
self.project = self.args[0].lower()
self.plugin = self.args[1].lower()
try:
self.project = self.args[0].lower()
self.plugin = self.args[1].lower()
except IndexError:
pass
while not self.project:
self.project = raw_input("Enter project name: ").lower()

View File

@ -15,6 +15,8 @@ setup(name='{{project}}',
zip_safe=False,
install_requires=[
"ConfigObj",
"cement == {{cement_version}}",
"cement.plugins.clibasic",
],
setup_requires=[
"PasteScript >= 1.7"

View File

@ -16,10 +16,13 @@ setup(name='{{project}}_plugins_{{plugin}}',
zip_safe=False,
install_requires=[
"ConfigObj",
"Cement",
"cement",
"cement.plugins.clibasic",
"{{project}}",
],
setup_requires=[
"PasteScript >= 1.7"
"PasteScript >= 1.7",
"ConfigObj",
],
test_suite='nose.collector',
entry_points="""

View File

@ -1,7 +1,6 @@
"""An example application using the Cement framework."""
import sys, os
import re
from cement.core.log import get_logger
from cement.core.app_setup import lay_cement, ensure_abi_compat, run_command

View File

@ -23,12 +23,12 @@ class ExamplePlugin(CementPlugin):
self.required_abi = '20091207'
self.description = "Example Plugin for a Cement Application."
self.config = {
'config_source': ['defaults']
'config_source': ['defaults'],
'myplugin_opton' : 'My plugin value'
}
self.commands = {
'myplugin' : MyPluginCommand,
}
self.handlers = {}
self.options = init_parser(global_config)
# Cement allows you to expose command line options to the
@ -38,7 +38,7 @@ class ExamplePlugin(CementPlugin):
help='example option for myplugun plugin', metavar='VAR'
)
class MyClass(object):
def __init__(self, config):
pass

View File

@ -1,8 +1,8 @@
from setuptools import setup, find_packages
import sys, os
setup(name='CementPluginsCLIBasic',
version='0.1',
setup(name='cement.plugins.clibasic',
version='0.2',
description='Basic Commands for Applications Build on Cement',
classifiers=[],
keywords='',
@ -15,10 +15,11 @@ setup(name='CementPluginsCLIBasic',
zip_safe=False,
install_requires=[
"ConfigObj",
"cement",
"cement == 0.4",
],
setup_requires=[
"PasteScript >= 1.7"
"PasteScript >= 1.7",
"ConfigObj"
],
test_suite='nose.collector',
entry_points="""

View File

@ -23,7 +23,7 @@ using cement.
"""
setup(name='Cement',
setup(name='cement',
version=version,
description="Python CLI Application Framework",
long_description=LONG,
@ -42,6 +42,15 @@ setup(name='Cement',
"PasteScript",
"tempita",
],
setup_requires=[
"PasteScript >= 1.7",
"ConfigObj"
],
# FIX ME: This installs, but requiring CementABI == 0.4.20091211 doesn't
# work.
provides=[
"CementABI (0.4.20091211)",
],
entry_points="""
[paste.global_paster_command]
cement-app = cement.paste.commands:CementAppCommand