diff --git a/LICENSE b/LICENSE index f7be018c..c00a85d2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,23 +1,27 @@ -The MIT License: +Copyright (c) 2009-2011, BJ Dierkes +All rights reserved. -Copyright (c) 2009-2010 BJ Dierkes +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Rackspace US, Inc. nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/cement.devtools/LICENSE b/src/cement.devtools/LICENSE deleted file mode 100644 index f7be018c..00000000 --- a/src/cement.devtools/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ - -The MIT License: - -Copyright (c) 2009-2010 BJ Dierkes - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - diff --git a/src/cement.devtools/MANIFEST.in b/src/cement.devtools/MANIFEST.in deleted file mode 100644 index 70bf8161..00000000 --- a/src/cement.devtools/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -recursive-include cementdevtools/paste/templates * diff --git a/src/cement.devtools/README b/src/cement.devtools/README deleted file mode 100644 index 8514f839..00000000 --- a/src/cement.devtools/README +++ /dev/null @@ -1,53 +0,0 @@ - -NAME: cement.devtools - -AUTHOR: BJ Dierkes - -DESCRIPTION: - -Cement is an advanced CLI Application Framework for Python. The 'devtools' -package provides tools and libraries needed for developing applications that -are built on Cement. Note that this is only part of 'cement' as a whole. The -entire source is available from: - - http://builtoncement.org/cement/0.8/download/ - - -The Cement CLI Application Framework is Open Source and is distributed under -The MIT License. - - -MORE INFORMATION: - -All documentation is available from the official website: - - http://builtoncement.org - - -GETTING STARTED: - -Stable versions can be installed via the cheeze shop: -:: - $ easy_install cement.devtools - - -Development versions can be checked out of Git: -:: - $ git clone git://github.com/derks/cement.git - - $ cd cement/src/cement.devtools/ - - $ python setup.py install - - -With the 'devtools' package, Cement applications and plugins can be -created via PasteScript. The following command will create a command line -application built on top of the Cement Framework: -:: - $ paster cement-app myapp - - -The following command will create an external plugin for your application: -:: - $ paster cement-plugin myapp myplugin - diff --git a/src/cement.devtools/cementdevtools/__init__.py b/src/cement.devtools/cementdevtools/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/cement.devtools/cementdevtools/paste/__init__.py b/src/cement.devtools/cementdevtools/paste/__init__.py deleted file mode 100644 index a27427d6..00000000 --- a/src/cement.devtools/cementdevtools/paste/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -""" -The module handles the integration with PasteScript enabling the following -plugins to the 'paste' command line utility: - - cement-app - Generates a base application built on Cement. - - cement-plugin - Generates an external plugin for an application built on Cement. - - cement-helper - Generates an external helper for an application built on Cement. - -Usage: - -.. code-block:: - - $ paster cement-app helloworld - - $ paster cement-plugin helloworld myplugin - - $ paster cement-helper helloworld myhelper - -""" -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/commands.py b/src/cement.devtools/cementdevtools/paste/commands.py deleted file mode 100644 index ae8a0ff6..00000000 --- a/src/cement.devtools/cementdevtools/paste/commands.py +++ /dev/null @@ -1,272 +0,0 @@ -""" -A significant portion of this file was derived from the tg.devtools software -which is licensed under the MIT license. The following license applies to -the work in *this* file only, and not any other part of the Cement Framework -unless otherwise noted: - ------------------------------------------------------------------------------ -Copyright (c) 2008 TurboGears Team - - Permission is hereby granted, free of charge, to any person - obtaining a copy of this software and associated documentation - files (the "Software"), to deal in the Software without - restriction, including without limitation the rights to use, - copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following - conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------ - - -Paste commands to generate a new Cement projects and plugins. - -""" - -# Taken mostly from tg.devtools... Thank you! - -import sys, os -import re -import pkg_resources -import optparse -from paste.script import command -from paste.script import create_distro - -beginning_letter = re.compile(r"^[^a-z]*") -valid_only = re.compile(r"[^a-z0-9_\.]") - -CEMENT_VERSION = pkg_resources.get_distribution('cement').version - -(base, major) = CEMENT_VERSION.split('.')[:2] -CEMENT_MAJOR_VERSION = '.'.join(CEMENT_VERSION.split('.')[:2]) - -if int(major)%2==0: - CEMENT_NEXT_VERSION = float(CEMENT_MAJOR_VERSION) + 0.1 -else: - CEMENT_NEXT_VERSION = float(CEMENT_MAJOR_VERSION) + 0.2 - -class CementAppCommand(command.Command): - """Create a new CLI Application using the Cement Framework. - -Example usage:: - - $ paster cement-app yourproject - - """ - version = CEMENT_VERSION - summary = __doc__.splitlines()[0] - usage = '\n' + __doc__ - name = None - group_name = "Cement" - dry_run = False - templates = "cementapp" - - parser = command.Command.standard_parser(quiet=True) - parser = optparse.OptionParser( - usage="%prog cement-app [options] [project name]", - version="%prog " + version - ) - parser.add_option("-t", "--templates", - help="user specific templates", - dest="templates", default=templates - ) - parser.add_option("--dry-run", - help="dry run (don't actually do anything)", - action="store_true", dest="dry_run" - ) - - def command(self): - """LayCement for the new project.""" - - self.__dict__.update(self.options.__dict__) - - if self.args: - self.name = self.args[0] - - while not self.name: - self.name = raw_input("Enter project name: ").strip() - - self.name = pkg_resources.safe_name(self.name) - - package = self.name.lower() - package = beginning_letter.sub("", package) - package = valid_only.sub("_", package) - self.package = raw_input( - "Enter module name [%s]: " % package).strip() or package - - self.description = raw_input( - "Project Description: ").strip() - self.creator = raw_input( - "Project Creator: ").strip() - self.creator_email = raw_input( - "Project Creator Email: ").strip() - self.url = raw_input( - "Project URL: ").strip() - self.license = raw_input( - "Project License: ").strip() - - env = pkg_resources.Environment() - if self.name.lower() in env: - print 'The name "%s" is already in use by ' % self.name, - for dist in env[self.name]: - print dist - return - - import imp - try: - if imp.find_module(self.package): - print 'The package name "%s" is already in use' % self.package - return - except ImportError: - pass - - if os.path.exists(self.name): - print 'A directory called "%s" already exists. Exiting.' % self.name - return - - command = create_distro.CreateDistroCommand("create") - cmd_args = [] - for template in self.templates.split(): - cmd_args.append("--template=%s" % template) - - cmd_args.append(self.name) - cmd_args.append("package=%s" % self.package) - cmd_args.append("cement_version=%s" % CEMENT_VERSION) - cmd_args.append("cement_next_version=%s" % CEMENT_NEXT_VERSION) - cmd_args.append("description=%s" % self.description) - cmd_args.append("creator=%s" % self.creator) - cmd_args.append("creator_email=%s" % self.creator_email) - cmd_args.append("url=%s" % self.url) - cmd_args.append("license=%s" % self.license) - - command.run(cmd_args) - - if not self.dry_run: - sys.argv = ["setup.py", "egg_info"] - - # dirty hack to allow "empty" dirs - for base, path, files in os.walk("./"): - for file in files: - if file == "empty": - os.remove(os.path.join(base, file)) - - -class CementPluginCommand(command.Command): - """Create a plugin for an application using the Cement Framework. - -Example usage:: - - $ paster cement-plugin yourproject yourplugin - """ - version = CEMENT_VERSION - summary = __doc__.splitlines()[0] - usage = '\n' + __doc__ - name = None - group_name = "Cement" - dry_run = False - templates = "cementplugin" - project = None - plugin = None - - parser = command.Command.standard_parser(quiet=True) - parser = optparse.OptionParser( - usage="%prog cement-plugin [options] [project name] [plugin_name]", - version="%prog " + version - ) - parser.add_option("-t", "--templates", - help="user specific templates", - dest="templates", default=templates - ) - parser.add_option("--dry-run", - help="dry run (don't actually do anything)", - action="store_true", dest="dry_run" - ) - - def command(self): - """LayCement for the new project plugin.""" - - self.__dict__.update(self.options.__dict__) - - if self.args: - 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() - - package = "%s" % self.project - package = beginning_letter.sub("", package) - package = valid_only.sub("_", package) - - self.package = raw_input( - "Enter module name [%s]: " % package).strip() or package - - while not self.plugin: - self.plugin = raw_input("Enter plugin name: ").lower() - - self.plugin = beginning_letter.sub("", self.plugin) - self.plugin = valid_only.sub("_", self.plugin) - - self.creator = raw_input( - "Project Creator: ").strip() - self.creator_email = raw_input( - "Project Creator Email: ").strip() - self.url = raw_input( - "Project URL: ").strip() - self.license = raw_input( - "Project License: ").strip() - - name = "%s.%s" % (self.project, self.plugin) - self.name = pkg_resources.safe_name(name) - - env = pkg_resources.Environment() - if self.name.lower() in env: - print 'The name "%s" is already in use by' % self.name, - for dist in env[self.name]: - print dist - return - - if os.path.exists(self.name): - print 'A directory called "%s" already exists. Exiting.' % self.name - return - - command = create_distro.CreateDistroCommand("create") - cmd_args = [] - for template in self.templates.split(): - cmd_args.append("--template=%s" % template) - cmd_args.append(self.name) - cmd_args.append("project=%s" % self.project) - cmd_args.append("package=%s" % self.package) - cmd_args.append("plugin=%s" % self.plugin) - cmd_args.append("cement_version=%s" % CEMENT_VERSION) - cmd_args.append("cement_next_version=%s" % CEMENT_NEXT_VERSION) - cmd_args.append("creator=%s" % self.creator) - cmd_args.append("creator_email=%s" % self.creator_email) - cmd_args.append("url=%s" % self.url) - cmd_args.append("license=%s" % self.license) - - command.run(cmd_args) - - if not self.dry_run: - sys.argv = ["setup.py", "egg_info"] - - # dirty hack to allow "empty" dirs - for base, path, files in os.walk("./"): - for file in files: - if file == "empty": - os.remove(os.path.join(base, file)) - \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/template.py b/src/cement.devtools/cementdevtools/paste/template.py deleted file mode 100644 index 65e46955..00000000 --- a/src/cement.devtools/cementdevtools/paste/template.py +++ /dev/null @@ -1,86 +0,0 @@ -""" -Definition for Cement laycement templates. - -A significant portion of this file was derived from the tg.devtools software -which is licensed under the MIT license. The following license applies to -the work in *this* file only, and not any other part of the Cement Framework -unless otherwise noted: - ------------------------------------------------------------------------------ -Copyright (c) 2008 TurboGears Team - - Permission is hereby granted, free of charge, to any person - obtaining a copy of this software and associated documentation - files (the "Software"), to deal in the Software without - restriction, including without limitation the rights to use, - copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following - conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------ -""" - -from paste.script import templates -from tempita import paste_script_template_renderer - -class CementAppTemplate(templates.Template): - """ - Cement default paste template class - """ - _template_dir = 'templates/cementapp' - template_renderer = staticmethod(paste_script_template_renderer) - summary = 'Cement Standard Template' - egg_plugins = ['PasteScript', 'cement'] - vars = [ - templates.var("package", "Package module name", default=''), - templates.var("cement_version", "Cement version", default=None), - templates.var("cement_next_version", "Cement Next Version", - default=None), - templates.var("description", "Description", default=''), - templates.var("creator", "Creator", default=''), - templates.var("creator_email", "Creator Email", default=''), - templates.var("url", "URL", default=''), - templates.var("license", "License", default=''), - ] - - def pre(self, command, output_dir, vars): - """Called before template is applied.""" - pass - -class CementPluginTemplate(templates.Template): - """ - Cement plugin default paste template class. - """ - _template_dir = 'templates/cementplugin' - template_renderer = staticmethod(paste_script_template_renderer) - summary = 'Cement Plugin Standard Template' - egg_plugins = ['PasteScript', 'cement'] - vars = [ - templates.var("plugin", "cement plugin name", default=None), - templates.var("project", "Parent application this plugin is for", - default=None), - templates.var("package", "Package module name", default=''), - templates.var("cement_version", "Cement version", default=None), - templates.var("cement_next_version", "Cement Next Version", - default=None), - templates.var("creator", "Creator", default=''), - templates.var("creator_email", "Creator Email", default=''), - templates.var("url", "URL", default=''), - templates.var("license", "License", default=''), - ] - - def pre(self, command, output_dir, vars): - """Called before template is applied.""" - pass diff --git a/src/cement.devtools/cementdevtools/paste/templates/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/__init__.py deleted file mode 100644 index de40ea7c..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/bootstrap/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/bootstrap/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/bootstrap/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/bootstrap/example.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/bootstrap/example.py_tmpl deleted file mode 100644 index 58bf41dc..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/bootstrap/example.py_tmpl +++ /dev/null @@ -1,39 +0,0 @@ - -from cement.core.hook import define_hook -from cement.core.namespace import CementNamespace, register_namespace - -define_hook('my_example_hook') - -# Setup the 'example' namespace object -example = CementNamespace( - label='example', - controller='ExampleController', - description='Example Plugin for {{project}}', - provider='{{project}}' - ) - -# Example namespace default configurations, overwritten by the [example] -# section of the applications config file(s). Once registered, this dict is -# accessible as: -# -# from cement.core.namespace import get_config -# example_config = get_config('example') -# -# Or simply as: -# -# root_config = get_config() -# root_config['example'] -# -example.config['foo'] = 'bar' - -# Example namespace options. These options show up under: -# -# $ {{package}} example --help -# -example.options.add_option('-F', '--foo', action='store', - dest='foo', default=None, help='Example Foo Option' - ) - -# Officialize and register the namespace -register_namespace(example) - diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/bootstrap/root.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/bootstrap/root.py_tmpl deleted file mode 100644 index 3dd3b05c..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/bootstrap/root.py_tmpl +++ /dev/null @@ -1,32 +0,0 @@ -""" -The bootstrap module should be used to setup parts of your application -that need to exist before all controllers are loaded. It is best used to -define hooks, setup namespaces, and the like. The root namespace is -already bootstrapped by Cement, however you can extend that functionality -by importing additional bootstrap files here. -""" - -from cement.core.opt import init_parser -from cement.core.hook import register_hook - -# Register root options -@register_hook() -def options_hook(*args, **kwargs): - # This hook allows us to append options to the root namespace - root_options = init_parser() - root_options.add_option('-R', '--root-option', action ='store_true', - dest='root_option', default=None, help='Example root option') - root_options.add_option('--json', action='store_true', - dest='enable_json', default=None, - help='render output as json (CLI-API)') - root_options.add_option('--debug', action='store_true', - dest='debug', default=None, help='toggle debug output') - root_options.add_option('--quiet', action='store_true', - dest='quiet', default=None, help='disable console logging') - return ('root', root_options) - -# Import all additional (non-plugin) bootstrap libraries here -# -# from {{package}}.bootstrap import example -# - \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/controllers/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/controllers/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/controllers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/controllers/controller.template_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/controllers/controller.template_tmpl deleted file mode 100644 index c7c3596f..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/controllers/controller.template_tmpl +++ /dev/null @@ -1,17 +0,0 @@ -"""{{package}} controller.""" - -from cement.core.namespace import get_config -from cement.core.log import get_logger -from cement.core.controller import CementController, expose -from cement.core.hook import run_hooks - -from {{package}}.model.example import ExampleModel - -log = get_logger(__name__) -config = get_config() - -class ExampleController(CementController): - @expose('{{package}}.templates.example.cmd', namespace='example') - def cmd(self): - # do something here - pass \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/controllers/example.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/controllers/example.py_tmpl deleted file mode 100644 index 104a160a..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/controllers/example.py_tmpl +++ /dev/null @@ -1,108 +0,0 @@ -""" -This is the ExampleController for the {{project}} application. This can be used -to expose commands to the example namespace which will be accessible under: - - $ {{package}} example --help - -""" - -from cement.core.namespace import get_config -from cement.core.log import get_logger -from cement.core.controller import CementController, expose -from cement.core.hook import run_hooks - -from {{package}}.model.example import ExampleModel - -log = get_logger(__name__) - -class ExampleController(CementController): - @expose(namespace='example') # no template - def ex1(self): - """ - This is how to expose a subcommand because it will be under the - 'example' namespace. You would access this subcommand as: - - $ {{package}} example ex1 - - """ - - # You can get the root application config like this: - config = get_config('root') - - # Or you can get your example namespace config like this: - config = get_config('example') - - # You can print or log output however you like since this function - # does not render out to a template. - - # Controllers are all passed the opts and args from the command line. - # So if you have added cli options in your {{project}}.bootstrap.example - # file, you could access them here as: - # - # self.cli_opts. - # self.cli_args[0] # first argument *after* your command - # - - # Here we show how to run a hook that we've defined in - # {{package}}.bootstrap.example: - for res in run_hooks('my_example_hook'): - print res - - # This command has no template, but if we return something we - # can still access the json output via --json. - return dict(foo='bar') - - @expose(namespace='example') - def ex1_help(self): - """ - Help methods are found by way of _help. This would be - executed when you run: - - $ {{package}} example ex1-help - - """ - print "This is the help method for ex1." - - @expose('{{package}}.templates.example.ex2', namespace='example') - def ex2(self): - """ - This is another command, also in the 'example' namespace but that is - rendered by a genshi template. - - Notice that you can specify the namespace via the decorator parameters. - If a plugin has any non-root commands they are grouped under a - single command to the base cli application. For example, you will - see root commands and namespaces* when you execute: - - $ {{package}} --help - - - If 'example' has local commands, you will see 'example*' show up in - the root commands list, and then the subcommands will be seen under: - - $ {{package}} myplugin --help - - - This is done to give different options in how your application works. - - """ - - # Here we are using our Example model, and then returning a dictionary - # to our @expose() decorator where it will be rendered with Genshi. - example = ExampleModel() - example.label = 'This is my Example Model' - - # You can see if options where passed. These are set in - # {{package}}/bootstrap/example.py: - if self.cli_opts.foo: - # --foo was passed, do something - log.info('%s passed by --foo option' % self.cli_opts.foo) - - return dict(foo=self.cli_opts.foo, example=example, items=['one', 'two', 'three']) - - @expose(namespace='root') - def cmd2(self): - """This command will be displayed under the root namespace.""" - foo = "In {{package}}.controllers.example.cmd2()" - print foo - return dict(foo=foo) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/controllers/root.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/controllers/root.py_tmpl deleted file mode 100644 index c3d46a51..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/controllers/root.py_tmpl +++ /dev/null @@ -1,93 +0,0 @@ -""" -This is the RootController for the {{project}} application. This can be used -to expose commands to the root namespace which will be accessible under: - - $ {{package}} --help - -""" - -from cement.core.controller import CementController, expose -from cement.core.namespace import get_config -from cement.core.log import get_logger - -from {{package}}.core.exc import {{package.capitalize()}}ArgumentError - -log = get_logger(__name__) -config = get_config() - -class RootController(CementController): - @expose('{{package}}.templates.root.error', is_hidden=True) - def error(self, errors=[]): - """ - This can be called when catching exceptions giving the developer a - clean way of presenting errors to the user. - - Required Arguments: - - errors - A list of tuples in the form of [('ErrorCode', 'Error message')]. - - - The best way to use this is with an 'abort' function... something like: - - .. code-block:: python - - from cement.core.controller import run_controller_command - - def abort(errors): - run_controller_command('root', 'error', errors=errors) - - errors = [] - # do something, if error - errors.append(('MyErrorCode', 'My Error Message')) - - abort(errors) - - # continue work (no errors) - - """ - return dict(errors=errors) - - @expose(is_hidden=True) - def nosetests(self): - """This method is added for nose testing.""" - pass - - @expose(is_hidden=True) - def default(self): - """ - This is the default command method. If no commands are passed to - {{package}}, this one will be executed. By default it raises an - exception. - - """ - raise {{project.capitalize()}}ArgumentError, "A command is required. See --help?" - - @expose('{{package}}.templates.root.cmd1') - def cmd1(self): - """This is an example 'root' command.""" - foo = 'bar' - items = ['one', 'two', 'three'] - return dict(foo=foo, items=items) - - @expose() - def cmd1_help(self): - """This is an example 'root' -help command. It should be replaced.""" - foo = 'In {{package}}.controllers.root.cmd1_help()' - return dict(foo=foo) - - @expose('{{package}}.templates.root.get-started') - def get_started(self): - features = [ - 'Multiple Configuration file parsing (default: /etc, ~/)', - 'Command line argument and option parsing', - 'Dual Console/File Logging Support', - 'Full Internal and External (3rd Party) Plugin support', - 'Basic "hook" support', - 'Full MVC support for advanced application design', - 'Text output rendering with Genshi templates', - 'Json output rendering allows other programs to access your CLI-API', - ] - - genshi_link = "http://genshi.edgewall.org/wiki/Documentation/text-templates.html" - return dict(config=config, features=features, genshi_link=genshi_link) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/core/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/core/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/core/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/core/appmain.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/core/appmain.py_tmpl deleted file mode 100644 index 548955f1..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/core/appmain.py_tmpl +++ /dev/null @@ -1,100 +0,0 @@ -""" -This is the application's core code. Unless you know the "ins-and-outs" of -The Cement CLI Application Framework, you probably should not modify the -main() function of this file. - -""" - -import sys -from pkg_resources import get_distribution - -from cement.core.exc import CementArgumentError, CementConfigError -from cement.core.exc import CementRuntimeError -from cement.core.log import get_logger -from cement.core.app_setup import lay_cement -from cement.core.command import run_command - -from {{package}}.core.config import default_config -from {{package}}.core.exc import {{package.capitalize()}}ArgumentError, {{package.capitalize()}}ConfigError -from {{package}}.core.exc import {{package.capitalize()}}RuntimeError - -VERSION = get_distribution('{{project}}').version -BANNER = """ -{{project}} version %s -""" % VERSION - -def main(args=None): - try: - if not args: - args = sys.argv - - lay_cement(config=default_config, banner=BANNER, args=args, - version=VERSION) - - log = get_logger(__name__) - log.debug("Cement Framework Initialized!") - - if not len(args) > 1: - args.append('default') - - run_command(args[1]) - - except CementArgumentError, e: - # Display the apps exception names instead for the Cement exceptions. - print("{{package.capitalize()}}ArgumentError > %s" % e) - sys.exit(e.code) - except CementConfigError, e: - print("{{package.capitalize()}}ConfigError > %s" % e) - sys.exit(e.code) - except CementRuntimeError, e: - print("{{package.capitalize()}}RuntimeError > %s" % e) - sys.exit(e.code) - except {{package.capitalize()}}ArgumentError, e: - print("{{package.capitalize()}}ArgumentError > %s" % e) - sys.exit(e.code) - except {{package.capitalize()}}ConfigError, e: - print("{{package.capitalize()}}ConfigError > %s" % e) - sys.exit(e.code) - except {{package.capitalize()}}RuntimeError, e: - print("{{package.capitalize()}}RuntimeError > %s" % e) - sys.exit(e.code) - sys.exit(0) - -def nose_main(args, test_config): - """ - This function provides an alternative to main() that is more friendly for - nose tests as it doesn't catch any exceptions. - - Required Arguments: - - args - The args to pass to lay_cement - - test_config - A test config to pass to lay_cement - - Usage: - - .. code-block:: python - - from {{package}}.core.appmain import nose_main - from {{package}}.core.config import get_nose_config - - args = [__file__, 'nosetests', '--quiet'] - (res_dict, output_text) = nose_main(args, get_nose_config()) - - """ - - lay_cement(config=test_config, banner=BANNER, args=args) - log = get_logger(__name__) - log.debug("Cement Framework Initialized!") - - if not len(args) > 1: - args.append('default') - - (res, output_txt) = run_command(args[1]) - return (res, output_txt) - -if __name__ == '__main__': - main() - diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/core/config.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/core/config.py_tmpl deleted file mode 100644 index a2893dd1..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/core/config.py_tmpl +++ /dev/null @@ -1,70 +0,0 @@ -""" -This is the applications default configuration. You can feel free to alter -this file to your needs, however it should be noted that all these variables -are overridden by settings in /etc/{{package}}/{{package}}.conf and/or -~/.{{package}}.conf (by default) and therefore, any default configurations -you want to make obvious to your users should be set in your default config -file as packaged with the software. -""" - -import os -from configobj import ConfigObj - -from cement.core.exc import CementConfigError - -# This is a sane default for development/no config -prefix = os.path.join(os.environ['HOME'], '.{{package}}') - - -dcf = ConfigObj() # default config -dcf['config_source'] = ['defaults'] -dcf['app_name'] = '{{project}}' # name for cli like /etc/ -dcf['app_egg_name'] = '{{project}}' # name from setup.py -dcf['app_module'] = '{{package}}' # name of the library dir - -dcf['enabled_plugins'] = [] # no default plugins, add via the config file -dcf['debug'] = False -dcf['datadir'] = os.path.join(prefix, 'data') -dcf['tmpdir'] = os.path.join(prefix, 'tmp') -dcf['log_file'] = os.path.join(prefix, 'log', dcf['app_name']) -dcf['plugin_config_dir'] = os.path.join(prefix, 'etc', 'plugins.d') -dcf['log_to_console'] = True -dcf['output_handler'] = 'genshi' -dcf['show_plugin_load'] = False - -# By default look in /etc and ~/ for config files. Developers for non *nix -# audiences will want to change this. -dcf['config_files'] = [ - os.path.join('/etc', dcf['app_name'], '%s.conf' % dcf['app_name']), - os.path.join(prefix, 'etc', '%s.conf' % dcf['app_name']), - os.path.join(os.environ['HOME'], '.%s.conf' % dcf['app_name']), - ] - -default_config = dcf - -def get_default_config(): - """Return the default application config.""" - return default_config - -def get_nose_config(prefix=None): - if not prefix: - from tempfile import mkdtemp - prefix = mkdtemp() - - tcf = ConfigObj() # test config - tcf['config_files'] = [os.path.abspath('./config/{{package}}.conf-test')] - tcf['config_source'] = ['defaults'] - tcf['app_name'] = '{{project}}' - tcf['app_egg_name'] = '{{project}}' - tcf['app_module'] = '{{package}}' - tcf['enabled_plugins'] = [] - tcf['debug'] = False - tcf['datadir'] = '%s/data' % prefix - tcf['tmpdir'] = '%s/tmp' % prefix - tcf['log_file'] = '%s/log/%s.log' % (prefix, tcf['app_name']) - tcf['plugin_config_dir'] = './config/plugins.d' - tcf['log_to_console'] = False - tcf['output_engine'] = 'genshi' - tcf['show_plugin_load'] = False - return tcf - \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/core/exc.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/core/exc.py_tmpl deleted file mode 100644 index 0242b972..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/core/exc.py_tmpl +++ /dev/null @@ -1,32 +0,0 @@ -"""{{project}} exception classes.""" - -class {{package.capitalize()}}Error(Exception): - """Generic errors.""" - def __init__(self, value, code=1): - Exception.__init__(self) - self.msg = value - self.code = code - - def __str__(self): - return self.msg - - def __unicode__(self): - return unicode(self.msg) - -class {{package.capitalize()}}ConfigError({{package.capitalize()}}Error): - """Config parsing and setup errors.""" - def __init__(self, value): - code = 10 - {{package.capitalize()}}Error.__init__(self, value, code) - -class {{package.capitalize()}}RuntimeError({{package.capitalize()}}Error): - """Runtime errors.""" - def __init__(self, value): - code = 20 - {{package.capitalize()}}Error.__init__(self, value, code) - -class {{package.capitalize()}}ArgumentError({{package.capitalize()}}Error): - """Argument errors.""" - def __init__(self, value): - code = 40 - {{package.capitalize()}}Error.__init__(self, value, code) diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/helpers/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/helpers/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/helpers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/lib/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/lib/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/lib/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/model/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/model/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/model/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/model/example.py b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/model/example.py deleted file mode 100644 index 28fceb9b..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/model/example.py +++ /dev/null @@ -1,13 +0,0 @@ -""" -This is an example model. This can be anything, just a straight class -or perhaps an SQLAlchemy DeclarativeBase, etc. -""" - -from cement.core.log import get_logger - -log = get_logger(__name__) - -class ExampleModel(object): - id = int() - label = u'' - description = u'' \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/model/root.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/model/root.py_tmpl deleted file mode 100644 index 9f6e37b4..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/model/root.py_tmpl +++ /dev/null @@ -1,28 +0,0 @@ -""" -The root model can be used to consolidate all of your models under one. - -A recommended way of accessing your model throughout your application is to -import all model classes into the 'root' model file like so: - -**helloworld/model/root.py** - -.. code-block:: python - - from helloworld.model.example import Example - from helloworld.model.user import User - from helloworld.model.product import Product - - -Then, throughout your application you can access all of you module objects -like this: - -.. code-block:: python - - from helloworld.model import root as model - - user = model.User() - product = model.Product() - -""" - -# from helloworld.model.example import Example diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/example/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/example/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/example/ex2.txt b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/example/ex2.txt deleted file mode 100644 index 06db74c0..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/example/ex2.txt +++ /dev/null @@ -1,28 +0,0 @@ -{# This is an example Genshi Text Template. Documentation is available #}\ -{# at: #}\ -{# #}\ -{# http://genshi.edgewall.org/wiki/Documentation/text-templates.html #}\ -{# #}\ -\ -\ -{# --------------------- 78 character baseline --------------------------- #}\ - -There are a number of things you can do such as conditional statements: - -{% if foo %}\ -Label: ${example.label} -{% end %}\ - -Or a for loop: - -{% for item in items %}\ - * ${item} -{% end %}\ - -And functions: - -{% def greeting(name) %}\ - Hello, ${name}! -{% end %}\ -${greeting('World')}\ -${greeting('Edward')} \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/root/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/root/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/root/cmd1.txt b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/root/cmd1.txt deleted file mode 100644 index ce58f856..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/root/cmd1.txt +++ /dev/null @@ -1,2 +0,0 @@ -{# --------------------- 78 character baseline --------------------------- #}\ -$foo \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/root/error.txt b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/root/error.txt deleted file mode 100644 index d9117e25..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/root/error.txt +++ /dev/null @@ -1,7 +0,0 @@ -{# --------------------- 78 character baseline --------------------------- #}\ - -The following errors were encountered: ------------------------------------------------------------------------------ -{% for error in errors %}\ - * ${error[0]} => ${error[1]} -{% end %} \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/root/get-started.txt_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/root/get-started.txt_tmpl deleted file mode 100644 index abeedc19..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/+package+/templates/root/get-started.txt_tmpl +++ /dev/null @@ -1,62 +0,0 @@ -{# --------------------- 78 character baseline --------------------------- #}\ -Welcome to ${config['app_name']}. - -This application is built on Cement, and is ready to rock! Out of the box you -already have: - -{% for feature in features %}\ - * $feature -{% end %}\ - -If your config file is setup right, you should notice that your app is already -loading an 'example' plugin. Plugins are enabled by adding a plugin config -file in your plugin_config_dir (see {{package}}.conf). The plugin config -must have a [] section and under that section you must set the -following setting - - * enable_plugin=true - -This will tell Cement to load that plugin. You can also load plugins from -other projects built on Cement by also adding the following setting: - - * provider = someotherapp - -Where 'someotherapp' is the package name of the application providing the -plugin. - -The included example plugin is a great starting point to learn how to build on -top of the Cement Framework. The following files and directories should be -explored: - - * ./{{package}}/bootstrap/example.py - * ./{{package}}/controllers/example.py - * ./{{package}}/model/example.py - * ./{{package}}/templates/example/ - - -This command is defined in the RootController in: - - {{package}}/controllers/root.py - - -Additionally, the output of this command is rendered by the Genshi templating -engine. The template is at {{package}}/templates/root/get-started.txt. -You can find documentation here on the template syntax here: - - * $genshi_link - - -That said, you can also render the output of commands as JSON. Don't believe -me? Just run it again with the --json flag. - -To make the included 'example' plugin a permanent part of your application you -simply need to add the following to {{package}}/bootstrap/root.py: - - from {{package}}.bootstrap import example - - -That said, by following the example plugin you can easily create built in code -or additional plugins in the same fashion. - -Go forth, and code! - diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/INSTALL_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/INSTALL_tmpl deleted file mode 100644 index a9967cb9..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/INSTALL_tmpl +++ /dev/null @@ -1,11 +0,0 @@ - -SOURCE INSTALLATION: - - $ sudo python setup.py install - - $ sudo cp -a ./etc /etc/{{package}} - - -USAGE: - - $ {{package}} --help \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/LICENSE b/src/cement.devtools/cementdevtools/paste/templates/cementapp/LICENSE deleted file mode 100644 index e69de29b..00000000 diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/MANIFEST.in_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/MANIFEST.in_tmpl deleted file mode 100644 index e3a99f0a..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/MANIFEST.in_tmpl +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include {{package}}/templates * -recursive-include tests * \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/README_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/README_tmpl deleted file mode 100644 index 0bb045ae..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/README_tmpl +++ /dev/null @@ -1,64 +0,0 @@ -NAME: {{package}} - -AUTHOR: - -DESCRIPTION: - -Describe your application here. - -{{project}} is built on the Cement CLI Application Framework. - - -USAGE: - - $ {{package}} --help - - -CONFIGURATION: - -Application configuration files are parsed in the following order: - - * /etc/{{package}}/{{package}}.conf - * ~/.{{package}}.conf - - -PLUGIN DEVELOPMENT: - -{{project}} supports external plugins via the Cement Framework. To quick -start a new plugin for {{project}} you can use the paster utility. - -Setup a virtual environment for development: - - $ virtualenv --no-site-package /path/to/env - - $ source /path/to/env/bin/activate - - -Install {{project}}: - - $ cd /path/to/{{project}} - - $ python setup.py develop - - -Create and install the plugin: - - $ mkdir plugins - - $ cd plugins - - $ paster cement-plugin {{package}} myplugin - - $ cd {{package}}.myplugin - - $ python setup.py develop - - -Once your plugin is installed, you can enable it by adding a [plugin] block -to a plugin config in /etc/{{package}}/plugins.d/myplugin.conf. You should -then see some example commands/options show up with: - - $ {{package}} --help - - -Then, code away! diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/config/+project+.conf-dev_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/config/+project+.conf-dev_tmpl deleted file mode 100644 index 985b7fca..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/config/+project+.conf-dev_tmpl +++ /dev/null @@ -1,67 +0,0 @@ -[root] -# This is an example application config using cement. - -# PLUGINS -# -# Plugins are enabled under their [plugin] config either in this -# file or in the plugins.d config file for that plugin. An example plugin -# config looks like: -# -# [example] -# enable_plugin = true -# provider = rosendale -# -# -# The 'provider' is the package that provides it. If it is an internal plugin -# this can be left blank. -# - -# DIRECTORIES -# -# these should probably be changed for production installations if you -# follow the FHS (and you should). -datadir = ~/{{project}}/data -tmpdir = ~/{{project}}/tmp - -# This should be the path to your development tree ... -# -# i.e. /path/to/{{package}}/etc/plugins.d -# -plugin_config_dir = ~/devel/{{project}}/config/plugins.d - - -# This is just a cosmetic option... whether to show 'loading plugin...' -# on application startup. -# -show_plugin_load = false - -# LOGGING -# -# Log file path, comment out if no log is required. -log_file = ~/{{project}}/log/{{project}}.log - -# Toggle debug output... can be true, false -debug = false - -# Toggle the log level... can be info, warn, error, fatal, debug -log_level = warn - -# Whether or not to log to console (this is overridden by 'debug') -log_to_console = true - -# Max bytes to rotate log file on. Comment out to not rotate log file. -# -# 512000000 = 512M -# -#log_max_bytes = 512000000 -#log_max_files = 4 - -# ROOT APPLICATION SETTINGS -# -# Add any config options you'd like here -# -# myoption = this is my option - - -# [namespace] -# Additional namespace/plugin configurations can go here. diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/config/+project+.conf-test_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/config/+project+.conf-test_tmpl deleted file mode 100644 index 850786c7..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/config/+project+.conf-test_tmpl +++ /dev/null @@ -1,8 +0,0 @@ -# This configuration is specifically meant to be used for testing -[root] - -# This is how you'd enable a plugin for testing -[example] -enable_plugin = true -provider = {{package}} -foo = 'some value' \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/config/+project+.conf_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/config/+project+.conf_tmpl deleted file mode 100644 index e64996cb..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/config/+project+.conf_tmpl +++ /dev/null @@ -1,61 +0,0 @@ -[root] -# This is an example application config using cement. - -# PLUGINS -# -# Plugins are enabled under their [plugin] config either in this -# file or in the plugins.d config file for that plugin. An example plugin -# config looks like: -# -# [example] -# enable_plugin = true -# provider = rosendale -# -# -# The 'provider' is the package that provides it. If it is an internal plugin -# this can be left blank. -# - -# DIRECTORIES -# -# These settings tend to follow the FHS, and may need to be modified for your -# environment. -datadir = /var/lib/{{project}} -tmpdir = /tmp -plugin_config_dir = /etc/{{project}}/plugins.d - - -# This is just a cosmetic option... whether to show 'loading plugin...' -# on application startup. -# -show_plugin_load = false - -# LOGGING -# -# Log file path, comment out if no log is required. -log_file = /var/log/{{project}}/{{project}}.log - -# Toggle debug output... can be true, false -debug = false - -# Toggle the log level... can be info, warn, error, fatal, debug -log_level = warn - -# Whether or not to log to console (this is overridden by 'debug') -log_to_console = true - -# Max bytes to rotate log file on. Comment out to not rotate log file. -# -# 512000000 = 512M -# -#log_max_bytes = 512000000 -#log_max_files = 4 - -# ROOT APPLICATION SETTINGS -# -# Add any config options you'd like here -# -# myoption = this is my option - -# [namespace] -# Additional namespace/plugin configurations can go here. \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/config/plugins.d/example.conf b/src/cement.devtools/cementdevtools/paste/templates/cementapp/config/plugins.d/example.conf deleted file mode 100644 index 12493685..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/config/plugins.d/example.conf +++ /dev/null @@ -1,29 +0,0 @@ -[example] -# This is an example of a cement plugin configuration file. Once parsed, the -# values from here will be accessible from: -# -# namespaces[{{plugin}}].config['param'] = value -# -# -# Some options are built into cement (such as merge_root_options) and -# some are not. -# - -# Whether to enable plugin or not -enable_plugin = true - -# Whether or not to merge root options -merge_root_options = true - -debug = false -param1 = value1 -param2 = value two - -# equates to True in Python -param3 = true - -# equates to False in python -param4 = false - -# equates to ['my', 'list', 'of', 'values'] -param5 = my, list, of, values, \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/setup.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/setup.py_tmpl deleted file mode 100644 index fe5bc5e7..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/setup.py_tmpl +++ /dev/null @@ -1,41 +0,0 @@ - -from setuptools import setup, find_packages -import sys, os - -setup(name='{{project}}', - version='0.1', - description='{{description}}', - classifiers=[], - keywords='', - author='{{creator}}', - author_email='{{creator_email}}', - url='{{url}}', - license='{{license}}', - packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), - include_package_data=True, - zip_safe=False, - install_requires=[ - "configobj", - # remove if not using genshi templating - "genshi", - "cement >={{cement_version}}, <{{cement_next_version}}", - ], - setup_requires=[ - # uncomment for nose testing - # "nose", - ], - test_suite='nose.collector', - entry_points=""" - [console_scripts] - {{project}} = {{package}}.core.appmain:main - """, - namespace_packages=[ - '{{package}}', - '{{package}}.lib', - '{{package}}.bootstrap', - '{{package}}.controllers', - '{{package}}.model', - '{{package}}.helpers', - '{{package}}.templates', - ], - ) diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/tests/00_initialize_tests.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/tests/00_initialize_tests.py_tmpl deleted file mode 100644 index 0bc924fa..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/tests/00_initialize_tests.py_tmpl +++ /dev/null @@ -1,19 +0,0 @@ -""" -Initialize the application for nose testing, must be loaded first before -other tests. -""" - -from tempfile import mkdtemp - -from {{package}}.core.config import get_nose_config -from {{package}}.core.appmain import nose_main - -# use an altername config for testing -config = get_nose_config(mkdtemp()) - -# run the initial main, which bootstraps the base application -nose_main([__file__, 'nosetests', '--quiet'], config) - -def test_initialize(): - # We put this here just to ensure nose picks up this file. - pass \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/tests/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementapp/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementapp/tests/example_tests.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementapp/tests/example_tests.py_tmpl deleted file mode 100644 index 12773b95..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementapp/tests/example_tests.py_tmpl +++ /dev/null @@ -1,64 +0,0 @@ -""" -The purpose of this module is to test application functionality. It is here -as an example of how one might perform nose testing on an application built -on top of the Cement Framework. It is not a fully comprehensive test, of the -application... and needs to be expanded as the application grows. - -The initial file loaded by nose runs the application. Additional calls are -then made via the 'simulate' function rather than needing to reload the -application for every test. -""" - -import os -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import namespaces -from cement.core.namespace import get_config -from cement.core.testing import simulate -from cement.core.exc import CementRuntimeError - -from {{package}}.core.exc import {{project.capitalize()}}ArgumentError - -config = get_config() - -def setup_func(): - """Setup operations before every test.""" - pass - -def teardown_func(): - """Teardown operations after every test.""" - pass - -@with_setup(setup_func, teardown_func) -def test_cmd1_output(): - # Simulate returns the result dictionary, and the render output when - # running the controller command. This can be used to validate that the - # command ran successfully. - (res_dict, output_txt) = simulate([__file__, 'cmd1']) - - # You can test that the rendered output is what we expected - eq_(output_txt, 'bar') - - # You can test values in the result dictionary directly - ok_(res_dict['foo']) - -@raises({{project.capitalize()}}ArgumentError) -@with_setup(setup_func, teardown_func) -def test_default_cmd(): - # The default action is to raise an application error if an unknown - # command is called. This is how we test that the exception is raised. - simulate([__file__, 'default']) - -@with_setup(setup_func, teardown_func) -def test_config_cli_options(): - # Using the test configuration file in ./config we can test config options - # this way. We are also using the example plugin for this test - - # First it is set by what is in the config file - eq_(config['example']['foo'], 'some value') - - # Then overridden by cli_opts - simulate([__file__, 'example', 'ex1', '--foo=bar']) - - # now we validate that the config option was set by the cli_opt --foo - eq_(config['example']['foo'], 'bar') diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/bootstrap/+plugin+.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/bootstrap/+plugin+.py_tmpl deleted file mode 100644 index 2da48d0a..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/bootstrap/+plugin+.py_tmpl +++ /dev/null @@ -1,34 +0,0 @@ -""" -This bootstrap module should be used to setup parts of the {{plugin}} plugin -that need to exist before all controllers are loaded. It is best used to -define/register hooks, setup namespaces, and the like. - -""" - -from pkg_resources import get_distribution -from cement.core.namespace import CementNamespace, register_namespace - -VERSION = get_distribution('{{project}}.{{plugin}}').version - -# Setup the '{{plugin}}' namespace object -{{plugin}} = CementNamespace( - label='{{plugin}}', - description='{{plugin.capitalize()}} Plugin for {{project.capitalize()}}', - version=VERSION, - controller='{{plugin.capitalize()}}Controller', - provider='{{package}}' - ) - -# Add a config option to the {{plugin}} namespace. This is effectively the -# default setting for the config option. Overridden by config files, and then -# cli options. -{{plugin}}.config['foo'] = 'bar' - -# Add a cli option to the {{plugin}} namespace. This overrides the -# coresponding config option if passed -{{plugin}}.options.add_option('-F', '--foo', action='store', dest='foo', - help='example {{plugin}} option') - -# Officialize and register the namespace -register_namespace({{plugin}}) - diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/bootstrap/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/bootstrap/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/bootstrap/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/controllers/+plugin+.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/controllers/+plugin+.py_tmpl deleted file mode 100644 index 26b349c3..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/controllers/+plugin+.py_tmpl +++ /dev/null @@ -1,35 +0,0 @@ -"""{{plugin}} controller class to expose commands for {{project}}.""" - -from cement.core.controller import CementController, expose - -from {{package}}.model.{{plugin}} import {{plugin.capitalize()}}Model - -class {{plugin.capitalize()}}Controller(CementController): - @expose() - def {{plugin}}_command(self): - """Register root command that doesn't use a template.""" - foo = 'bar' - - # Even if you're not using a template, return relevant data so that - # you can still use the --json engine, or similar. - return dict(foo=foo) - - @expose() - def {{plugin}}_command_help(self): - """help methods are accessed as 'command-help'.""" - print "{{plugin}} root command help method." - - @expose('{{project}}.templates.{{plugin}}.{{plugin}}_command') - def {{plugin}}_command2(self, *args, **kw): - """Register root command, with Genshi templating.""" - foo = "Hello" - bar = "World" - return dict(foo=foo, bar=bar) - - @expose(namespace='{{plugin}}') - def {{plugin}}_sub_command(self): - """Register sub command for the {{plugin}} namespace.""" - foo = 'bar' - print foo - return dict(foo=foo) - diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/controllers/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/controllers/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/controllers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/helpers/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/helpers/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/helpers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/lib/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/lib/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/lib/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/model/+plugin+.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/model/+plugin+.py_tmpl deleted file mode 100644 index dc8c2bae..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/model/+plugin+.py_tmpl +++ /dev/null @@ -1,5 +0,0 @@ -"""{{plugin}} model classes.""" - -class {{plugin.capitalize()}}Model(object): - # define model class - pass \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/model/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/model/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/model/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/templates/+plugin+/+plugin+_command.txt_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/templates/+plugin+/+plugin+_command.txt_tmpl deleted file mode 100644 index 3a387985..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/templates/+plugin+/+plugin+_command.txt_tmpl +++ /dev/null @@ -1,9 +0,0 @@ -{# This is an example Genshi Text Template. Documentation is available #}\ -{# at: #}\ -{# #}\ -{# http://genshi.edgewall.org/wiki/Documentation/text-templates.html #}\ -{# #}\ -\ -\ -{# --------------------- 78 character baseline --------------------------- #}\ -${foo} ${bar} diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/templates/+plugin+/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/templates/+plugin+/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/templates/+plugin+/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/templates/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/templates/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/+package+/templates/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/INSTALL_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/INSTALL_tmpl deleted file mode 100644 index 729d0841..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/INSTALL_tmpl +++ /dev/null @@ -1,15 +0,0 @@ - -SOURCE INSTALLATION: - - $ sudo python setup.py install - - # The following is one command - $ sudo cp -a ./etc/{{project}}/plugins.d/{{plugin}}.conf \ - /etc/{{project}}/plugins.d/ - - -USAGE: - - $ {{project}} --help - - $ {{project}} {{plugin}} --help \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/LICENSE b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/LICENSE deleted file mode 100644 index e69de29b..00000000 diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/MANIFEST.in_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/MANIFEST.in_tmpl deleted file mode 100644 index ff1e3ad2..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/MANIFEST.in_tmpl +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include {{project}}/templates/{{plugin}} * -recursive-include tests * \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/README b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/README deleted file mode 100644 index 8b137891..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/README +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/config/+project+.conf-test_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/config/+project+.conf-test_tmpl deleted file mode 100644 index e7d07bc7..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/config/+project+.conf-test_tmpl +++ /dev/null @@ -1,8 +0,0 @@ -# This configuration is specifically meant to be used for testing -[root] - -# This is how you'd enable a plugin for testing -[{{plugin}}] -enable_plugin = true -provider = {{package}} -foo = 'some value' \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/config/plugins.d/+plugin+.conf_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/config/plugins.d/+plugin+.conf_tmpl deleted file mode 100644 index 166a7bca..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/config/plugins.d/+plugin+.conf_tmpl +++ /dev/null @@ -1,14 +0,0 @@ -# {{plugin.capitalize()}} Configuration Settings -# -# Note: Default values can be set via .bootstrap..py -# - -[{{plugin}}] -enable_plugin = true - -# The module name of the provider application -provider = {{package}} - -# Add any configurations here, note that defaults should also be added -# to this plugins bootstrap file. -foo = 'some value' \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/setup.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/setup.py_tmpl deleted file mode 100644 index 96bfdc43..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/setup.py_tmpl +++ /dev/null @@ -1,37 +0,0 @@ - -from setuptools import setup, find_packages -import sys, os - -# You probably want to change the name, this is a healthy default for paster -setup(name='{{project}}.{{plugin}}', - version='0.1', - description='{{plugin.capitalize()}} plugin for {{project.capitalize()}}', - classifiers=[], - keywords='', - author='{{creator}}', - author_email='{{creator_email}}', - url='{{url}}', - license='{{license}}', - packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), - include_package_data=True, - zip_safe=False, - install_requires=[ - "genshi", - "cement >={{cement_version}}, <{{cement_next_version}}", - "{{project}}", - ], - setup_requires=[ - ], - test_suite='nose.collector', - entry_points=""" - """, - namespace_packages=[ - '{{package}}', - '{{package}}.lib', - '{{package}}.bootstrap', - '{{package}}.controllers', - '{{package}}.model', - '{{package}}.helpers', - '{{package}}.templates', - ], - ) diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/tests/+plugin+_tests.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/tests/+plugin+_tests.py_tmpl deleted file mode 100644 index c19e403e..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/tests/+plugin+_tests.py_tmpl +++ /dev/null @@ -1,65 +0,0 @@ -""" -The purpose of this module is to test plugin functionality. It is here -as an example of how one might perform nose testing on an application built -on top of the Cement Framework. It is not a fully comprehensive test, of the -application... and needs to be expanded as the application and plugin grow. - -The initial file loaded by nose runs the application. Additional calls are -then made via the 'simulate' function rather than needing to reload the -application for every test. -""" - -import os -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import namespaces -from cement.core.namespace import get_config -from cement.core.testing import simulate -from cement.core.exc import CementRuntimeError - -from {{package}}.core.exc import {{project.capitalize()}}ArgumentError - -config = get_config() - -def setup_func(): - """Setup operations before every test.""" - pass - -def teardown_func(): - """Teardown operations after every test.""" - pass - -@with_setup(setup_func, teardown_func) -def test_{{plugin}}_cmd_output(): - # Simulate returns the result dictionary, and the render output when - # running the controller command. This can be used to validate that the - # command ran successfully. - (res_dict, output_txt) = simulate([__file__, '{{plugin}}-command2']) - - # You can test that the rendered output is what we expected - eq_(output_txt, 'Hello World\n') - - # You can test values in the result dictionary directly - ok_(res_dict['foo']) - -@raises({{project.capitalize()}}ArgumentError) -@with_setup(setup_func, teardown_func) -def test_default_cmd(): - # The default action is to raise an application error if an unknown - # command is called. This is how we test that the exception is raised. - simulate([__file__, 'default']) - -@with_setup(setup_func, teardown_func) -def test_config_cli_options(): - # Using the test configuration file in ./config dir of the base - # application we can test config options this way. We are also using the - # example plugin for this test - - # First it is set by what is in the config file - eq_(config['{{plugin}}']['foo'], 'some value') - - # Then overridden by cli_opts - simulate([__file__, '{{plugin}}', '{{plugin}}-sub-command', '--foo=bar']) - - # now we validate that the config option was set by the cli_opt --foo - eq_(config['{{plugin}}']['foo'], 'bar') diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/tests/00_initialize_tests.py_tmpl b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/tests/00_initialize_tests.py_tmpl deleted file mode 100644 index 2b64f9c4..00000000 --- a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/tests/00_initialize_tests.py_tmpl +++ /dev/null @@ -1,19 +0,0 @@ -""" -Initialize the base application for nose testing, must be loaded first before -other tests. -""" - -from tempfile import mkdtemp - -from {{package}}.core.config import get_nose_config -from {{package}}.core.appmain import nose_main - -# use an altername config for testing -config = get_nose_config(mkdtemp()) - -# run the initial main, which bootstraps the base application -nose_main([__file__, 'nosetests', '--quiet'], config) - -def test_initialize(): - # We put this here just to ensure nose picks up this file. - pass \ No newline at end of file diff --git a/src/cement.devtools/cementdevtools/paste/templates/cementplugin/tests/__init__.py b/src/cement.devtools/cementdevtools/paste/templates/cementplugin/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/cement.devtools/setup.py b/src/cement.devtools/setup.py deleted file mode 100644 index 351683c6..00000000 --- a/src/cement.devtools/setup.py +++ /dev/null @@ -1,85 +0,0 @@ -from setuptools import setup, find_packages -import sys, os - -VERSION = '0.8.16' - -LONG = """ -Cement is an advanced CLI Application Framework for Python. The 'devtools' -package provides tools and libraries needed for developing applications that -are built on Cement. Note that this is only part of 'cement' as a whole. The -entire source is available from: - - http://builtoncement.org/cement/0.8/download/ - - -The Cement CLI Application Framework is Open Source and is distributed under -The MIT License. - - -MORE INFORMATION: - -All documentation is available from the official website: - - http://builtoncement.org - - -GETTING STARTED: - -Stable versions can be installed via the cheeze shop: -:: - $ easy_install cement.devtools - - -Development versions can be checked out of Git: -:: - $ git clone git://github.com/derks/cement.git - - $ cd cement/src/cement.devtools/ - - $ python setup.py install - - -With the 'devtools' package, Cement applications and plugins can be -created via PasteScript. The following command will create a command line -application built on top of the Cement Framework: -:: - $ paster cement-app myapp - - -The following command will create an external plugin for your application: -:: - $ paster cement-plugin myapp myplugin - -""" - - -setup(name='cement.devtools', - version=VERSION, - description="Development Tools for the Cement CLI Application Framework", - long_description=LONG, - classifiers=[], - keywords='cli framework', - author='BJ Dierkes', - author_email='wdierkes@5dollarwhitebox.org', - url='http://builtoncement.org', - license='MIT', - packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), - include_package_data=True, - zip_safe=False, - install_requires=[ - "PasteScript", - "tempita", - "cement == %s" % VERSION, - ], - setup_requires=[ - ], - entry_points=""" - [paste.global_paster_command] - cement-app = cementdevtools.paste.commands:CementAppCommand - cement-plugin = cementdevtools.paste.commands:CementPluginCommand - [paste.paster_create_template] - cementapp = cementdevtools.paste.template:CementAppTemplate - cementplugin = cementdevtools.paste.template:CementPluginTemplate - """, - namespace_packages=[], - ) diff --git a/src/cement.test/LICENSE b/src/cement.test/LICENSE deleted file mode 100644 index f7be018c..00000000 --- a/src/cement.test/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ - -The MIT License: - -Copyright (c) 2009-2010 BJ Dierkes - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - diff --git a/src/cement.test/MANIFEST.in b/src/cement.test/MANIFEST.in deleted file mode 100644 index f419be83..00000000 --- a/src/cement.test/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include cement_test/templates * -recursive-include tests * diff --git a/src/cement.test/README b/src/cement.test/README deleted file mode 100644 index 6f1d23ad..00000000 --- a/src/cement.test/README +++ /dev/null @@ -1,42 +0,0 @@ - -NAME: cement.test - -AUTHOR: BJ Dierkes - -DESCRIPTION: - -Cement is an advanced CLI Application Framework for Python. The 'test' -package provides an external application built on top of Cement, with -additional nose tests to provide unit testing of the framework. To fully -test the framework, a running application is required to cover all bits of the -code. The 'cement.test' application is simply an application created using -the paster utility (cement.devtools) with a bit of added code for testing. -It is only meant to be used in development, for testing. Note that this is -only part of 'cement' as a whole. The entire source is available from: - - http://builtoncement.org/cement/0.8/download/ - - -The Cement CLI Application Framework is Open Source and is distributed under -The MIT License. - - -MORE INFORMATION: - -All documentation is available from the official website: - - http://builtoncement.org - - -GETTING STARTED: - -Development versions can be checked out of Git: -:: - $ git clone git://github.com/derks/cement.git - - $ cd cement/src/cement.test/ - - $ python setup.py install - - $ nosetests --verbosity 3 - diff --git a/src/cement.test/cement_test/__init__.py b/src/cement.test/cement_test/__init__.py deleted file mode 100644 index de40ea7c..00000000 --- a/src/cement.test/cement_test/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) diff --git a/src/cement.test/cement_test/bootstrap/__init__.py b/src/cement.test/cement_test/bootstrap/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.test/cement_test/bootstrap/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.test/cement_test/bootstrap/example.py b/src/cement.test/cement_test/bootstrap/example.py deleted file mode 100644 index 0c4bf169..00000000 --- a/src/cement.test/cement_test/bootstrap/example.py +++ /dev/null @@ -1,33 +0,0 @@ - -from cement.core.hook import register_hook, define_hook -from cement.core.namespace import CementNamespace, register_namespace - -# Setup the 'example' namespace object -example = CementNamespace( - label='example', - controller='ExampleController', - description='Example Plugin for Cement Test', - required_api='0.7-0.8:20100210', - provider='cement_test' - ) -example.config['foo'] = 'bar' -example.options.add_option('-F', '--foo', action='store', - dest='foo', default=None, help='Example Foo Option' - ) - -register_namespace(example) - -@register_hook(weight=99) -def my_example_hook(): - return 99 - -@register_hook(name='my_example_hook') -def some_other_hook_name(): - return 0 - -@register_hook(weight=-100) -def my_example_hook(): - return -100 - - - diff --git a/src/cement.test/cement_test/bootstrap/example2.py b/src/cement.test/cement_test/bootstrap/example2.py deleted file mode 100644 index aacca3c9..00000000 --- a/src/cement.test/cement_test/bootstrap/example2.py +++ /dev/null @@ -1,34 +0,0 @@ - -from cement.core.hook import register_hook, define_hook -from cement.core.namespace import CementNamespace, register_namespace - -# Setup the 'example' namespace object -example = CementNamespace( - label='example2', - controller='Example2Controller', - description='Example Plugin for Cement Test', - required_api='0.7-0.8:20100210', - provider='cement_test', - is_hidden=True, - ) -example.config['foo'] = 'bar' -example.options.add_option('-F', '--foo', action='store', - dest='foo', default=None, help='Example Foo Option' - ) - -register_namespace(example) - -@register_hook(weight=99) -def my_example_hook(): - return 99 - -@register_hook(name='my_example_hook') -def some_other_hook_name(): - return 0 - -@register_hook(weight=-100) -def my_example_hook(): - return -100 - - - diff --git a/src/cement.test/cement_test/bootstrap/example3.py b/src/cement.test/cement_test/bootstrap/example3.py deleted file mode 100644 index e9d81186..00000000 --- a/src/cement.test/cement_test/bootstrap/example3.py +++ /dev/null @@ -1,33 +0,0 @@ - -from cement.core.hook import register_hook, define_hook -from cement.core.namespace import CementNamespace, register_namespace - -# Setup the 'example' namespace object -example = CementNamespace( - label='example3', - controller='Example3Controller', - description='Example Plugin for Cement Test', - required_api='0.7-0.8:20100210', - provider='cement_test' - ) -example.config['foo'] = 'bar' -example.options.add_option('-F', '--foo', action='store', - dest='foo', default=None, help='Example Foo Option' - ) - -register_namespace(example) - -@register_hook(weight=99) -def my_example_hook(): - return 99 - -@register_hook(name='my_example_hook') -def some_other_hook_name(): - return 0 - -@register_hook(weight=-100) -def my_example_hook(): - return -100 - - - diff --git a/src/cement.test/cement_test/bootstrap/example4.py b/src/cement.test/cement_test/bootstrap/example4.py deleted file mode 100644 index 2e2fbb38..00000000 --- a/src/cement.test/cement_test/bootstrap/example4.py +++ /dev/null @@ -1,33 +0,0 @@ - -from cement.core.hook import register_hook, define_hook -from cement.core.namespace import CementNamespace, register_namespace - -# Setup the 'example' namespace object -example = CementNamespace( - label='example4', - controller='Example4Controller', - description='Example Plugin for Cement Test', - required_api='0.7-0.8:20100210', - provider='cement_test' - ) -example.config['foo'] = 'bar' -example.options.add_option('-F', '--foo', action='store', - dest='foo', default=None, help='Example Foo Option' - ) - -register_namespace(example) - -@register_hook(weight=99) -def my_example_hook(): - return 99 - -@register_hook(name='my_example_hook') -def some_other_hook_name(): - return 0 - -@register_hook(weight=-100) -def my_example_hook(): - return -100 - - - diff --git a/src/cement.test/cement_test/bootstrap/example_five.py b/src/cement.test/cement_test/bootstrap/example_five.py deleted file mode 100644 index 0522a362..00000000 --- a/src/cement.test/cement_test/bootstrap/example_five.py +++ /dev/null @@ -1,32 +0,0 @@ - -from cement.core.hook import register_hook, define_hook -from cement.core.namespace import CementNamespace, register_namespace - -# Setup the 'example' namespace object -example = CementNamespace( - label='example_five', - controller='ExampleFiveController', - description='Example Plugin for Cement Test', - provider='cement_test' - ) -example.config['foo'] = 'bar' -example.options.add_option('-F', '--foo', action='store', - dest='foo', default=None, help='Example Foo Option' - ) - -register_namespace(example) - -@register_hook(weight=99) -def my_example_hook(): - return 99 - -@register_hook(name='my_example_hook') -def some_other_hook_name(): - return 0 - -@register_hook(weight=-100) -def my_example_hook(): - return -100 - - - diff --git a/src/cement.test/cement_test/bootstrap/root.py b/src/cement.test/cement_test/bootstrap/root.py deleted file mode 100644 index 8dc5081f..00000000 --- a/src/cement.test/cement_test/bootstrap/root.py +++ /dev/null @@ -1,61 +0,0 @@ -""" -The bootstrap module should be used to setup parts of your application -that need to exist before all controllers are loaded. It is best used to -define hooks, setup namespaces, and the like. The root namespace is -already bootstrapped by Cement, however you can extend that functionality -by importing additional bootstrap files here. -""" - -from cement.core.opt import init_parser -from cement.core.hook import register_hook, define_hook - -define_hook('my_example_hook') - -# Register root options -@register_hook() -def options_hook(*args, **kwargs): - # This hook allows us to append options to the root namespace - root_options = init_parser() - root_options.add_option('-R', '--root-option', action ='store_true', - dest='root_option', default=None, help='Example root option') - root_options.add_option('--json', action='store_true', - dest='enable_json', default=None, - help='render output as json (CLI-API)') - root_options.add_option('--debug', action='store_true', - dest='debug', default=None, help='toggle debug output') - root_options.add_option('--quiet', action='store_true', - dest='quiet', default=None, help='disable console logging') - root_options.add_option('--test-option', action='store', - dest='test_option', default=None, help='test option') - return ('root', root_options) - -@register_hook() -def post_bootstrap_hook(): - pass - -@register_hook() -def validate_config_hook(config): - pass - -@register_hook() -def pre_plugins_hook(): - pass - -#@register_hook(name='options_hook') -#def bogus_namespace(): -# parser = init_parser() -# parser.add_option('--bogus-option', action='store', dest='bogus_option') -# return ('bogus_namespace', parser) - -@register_hook() -def post_plugins_hook(): - pass - -@register_hook() -def post_options_hook(cli_opts, cli_args): - pass - -# Import all additional (non-plugin) bootstrap libraries here -# -# from cement_test.bootstrap import example - diff --git a/src/cement.test/cement_test/controllers/__init__.py b/src/cement.test/cement_test/controllers/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.test/cement_test/controllers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.test/cement_test/controllers/example.py b/src/cement.test/cement_test/controllers/example.py deleted file mode 100644 index 36db302f..00000000 --- a/src/cement.test/cement_test/controllers/example.py +++ /dev/null @@ -1,32 +0,0 @@ -""" -This is the ExampleController for the cement_test application. This can be used -to expose commands to the example namespace which will be accessible under: - - $ cement_test example --help - -""" - -import sys - -from cement.core.namespace import get_config -from cement.core.log import get_logger -from cement.core.controller import CementController, expose -from cement.core.hook import run_hooks - -from cement_test.model.example import ExampleModel - -log = get_logger(__name__) - -class ExampleController(CementController): - @expose(namespace='example') - def default(self): - print "default command!" - - @expose(namespace='example') - def cmd1(self): - foo='bar' - print foo - return dict(foo=foo) - - - \ No newline at end of file diff --git a/src/cement.test/cement_test/controllers/example2.py b/src/cement.test/cement_test/controllers/example2.py deleted file mode 100644 index 322c6047..00000000 --- a/src/cement.test/cement_test/controllers/example2.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This is the ExampleController for the cement_test application. This can be used -to expose commands to the example namespace which will be accessible under: - - $ cement_test example --help - -""" - -import sys - -from cement.core.namespace import get_config -from cement.core.log import get_logger -from cement.core.controller import CementController, expose -from cement.core.hook import run_hooks - -log = get_logger(__name__) - -class Example2Controller(CementController): - @expose(namespace='example2') - def cmd1(self): - foo='bar' - print foo - return dict(foo=foo) diff --git a/src/cement.test/cement_test/controllers/example3.py b/src/cement.test/cement_test/controllers/example3.py deleted file mode 100644 index b5f94bbc..00000000 --- a/src/cement.test/cement_test/controllers/example3.py +++ /dev/null @@ -1,24 +0,0 @@ -""" -This is the ExampleController for the cement_test application. This can be used -to expose commands to the example namespace which will be accessible under: - - $ cement_test example --help - -""" - -import sys - -from cement.core.namespace import get_config -from cement.core.log import get_logger -from cement.core.controller import CementController, expose -from cement.core.hook import run_hooks - -log = get_logger(__name__) - -class Example3Controller(CementController): - @expose(namespace='example3') - def cmd1(self): - foo='bar' - print foo - return dict(foo=foo) - \ No newline at end of file diff --git a/src/cement.test/cement_test/controllers/example4.py b/src/cement.test/cement_test/controllers/example4.py deleted file mode 100644 index 5d64e6c3..00000000 --- a/src/cement.test/cement_test/controllers/example4.py +++ /dev/null @@ -1,24 +0,0 @@ -""" -This is the ExampleController for the cement_test application. This can be used -to expose commands to the example namespace which will be accessible under: - - $ cement_test example --help - -""" - -import sys - -from cement.core.namespace import get_config -from cement.core.log import get_logger -from cement.core.controller import CementController, expose -from cement.core.hook import run_hooks - -log = get_logger(__name__) - -class Example4Controller(CementController): - @expose(namespace='example4', is_hidden=True) - def cmd1(self): - foo='bar' - print foo - return dict(foo=foo) - \ No newline at end of file diff --git a/src/cement.test/cement_test/controllers/example_five.py b/src/cement.test/cement_test/controllers/example_five.py deleted file mode 100644 index 3ef83958..00000000 --- a/src/cement.test/cement_test/controllers/example_five.py +++ /dev/null @@ -1,24 +0,0 @@ -""" -This is the ExampleController for the cement_test application. This can be used -to expose commands to the example namespace which will be accessible under: - - $ cement_test example --help - -""" - -import sys - -from cement.core.namespace import get_config -from cement.core.log import get_logger -from cement.core.controller import CementController, expose -from cement.core.hook import run_hooks - -log = get_logger(__name__) - -class ExampleFiveController(CementController): - @expose(namespace='example_five', is_hidden=False) - def cmd1(self): - foo='bar' - print foo - return dict(foo=foo) - \ No newline at end of file diff --git a/src/cement.test/cement_test/controllers/root.py b/src/cement.test/cement_test/controllers/root.py deleted file mode 100644 index 1c325913..00000000 --- a/src/cement.test/cement_test/controllers/root.py +++ /dev/null @@ -1,99 +0,0 @@ -""" -This is the RootController for the cement_test application. This can be used -to expose commands to the root namespace which will be accessible under: - - $ cement_test --help - -""" - -from tempfile import mkstemp -from cement.core.controller import CementController, expose -from cement.core.namespace import get_config -from cement.core.log import get_logger - -from cement_test.core.exc import CementTestArgumentError - -log = get_logger(__name__) -config = get_config() - -class RootController(CementController): - @expose(is_hidden=True) - def nosetests(self, *args, **kw): - pass - - @expose('cement_test.templates.root.error', is_hidden=True) - def error(self, errors=[]): - """ - This can be called when catching exceptions giving the developer a - clean way of presenting errors to the user. - - Required Arguments: - - errors - A list of tuples in the form of [('ErrorCode', 'Error message')]. - - - The best way to use this is with an 'abort' function, such as the one - provided by the Rosendale Project. - - .. code-block:: python - - from rosendale.helpers.error import abort_on_error - - errors = [] - # do something, if error - errors.append(('MyErrorCode', 'My Error Message')) - - abort_on_error(errors) - - # continue work (no errors) - - """ - return dict(errors=errors) - - @expose(is_hidden=True) - def default(self): - """ - This is the default command method. If no commands are passed to - cement_test, this one will be executed. By default it raises an - exception. - - """ - raise CementTestArgumentError, "A command is required. See --help?" - - @expose('cement_test.templates.root.cmd1') - def cmd1(self): - """This is an example 'root' command. It should be replaced.""" - items = ['one', 'two', 'three'] - return dict(items=items) - - @expose() - def send_to_file(self): - f = mkstemp()[1] - return dict(output_file=f, foo='bar') - - @expose() - def cmd1_help(self): - """This is an example 'root' -help command. It should be replaced.""" - foo = 'In cement_test.controllers.root.cmd1_help()' - return dict(foo=foo) - - @expose('genshi:cement_test.templates.root.get-started') - def get_started(self): - features = [ - 'Multiple Configuration file parsing (default: /etc, ~/)', - 'Command line argument and option parsing', - 'Dual Console/File Logging Support', - 'Full Internal and External (3rd Party) Plugin support', - 'Basic "hook" support', - 'Full MVC support for advanced application design', - 'Text output rendering with Genshi templates', - 'Json output rendering allows other programs to access your CLI-API', - ] - - genshi_link = "http://genshi.edgewall.org/wiki/Documentation/text-templates.html" - return dict(config=config, features=features, genshi_link=genshi_link) - - @expose('bogus_handler:cement_test.templates.root.cmd1') - def bogus_cmd1(self): - pass diff --git a/src/cement.test/cement_test/core/__init__.py b/src/cement.test/cement_test/core/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.test/cement_test/core/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.test/cement_test/core/appmain.py b/src/cement.test/cement_test/core/appmain.py deleted file mode 100644 index 1496b8b4..00000000 --- a/src/cement.test/cement_test/core/appmain.py +++ /dev/null @@ -1,78 +0,0 @@ -""" -This is the application's core code. Unless you know the "ins-and-outs" of -The Cement CLI Application Framework, you probably should not modify the -main() function of this file. - -""" - -import sys -from pkg_resources import get_distribution - -from cement.core.exc import CementArgumentError, CementConfigError, \ - CementRuntimeError -from cement.core.log import get_logger -from cement.core.app_setup import lay_cement -from cement.core.configuration import ensure_api_compat -from cement.core.command import run_command - -from cement_test.core.config import default_config -from cement_test.core.exc import CementTestArgumentError, CementTestConfigError, \ - CementTestRuntimeError - -VERSION = get_distribution('cement.test').version -BANNER = """ -cement_test version %s -""" % VERSION - -def main(args=None): - try: - lay_cement(config=default_config, banner=BANNER, args=args) - - log = get_logger(__name__) - log.debug("Cement Framework Initialized!") - - if not len(sys.argv) > 1: - sys.argv.append('default') - - run_command(sys.argv[1]) - - except CementArgumentError, e: - # Display the apps exception names instead for the Cement exceptions. - print("CementTestArgumentError > %s" % e) - sys.exit(e.code) - except CementConfigError, e: - print("CementTestConfigError > %s" % e) - sys.exit(e.code) - except CementRuntimeError, e: - print("CementTestRuntimeError > %s" % e) - sys.exit(e.code) - except CementTestArgumentError, e: - print("CementTestArgumentError > %s" % e) - sys.exit(e.code) - except CementTestConfigError, e: - print("CementTestConfigError > %s" % e) - sys.exit(e.code) - except CementTestRuntimeError, e: - print("CementTestRuntimeError > %s" % e) - sys.exit(e.code) - sys.exit(0) - -def nose_main(args, test_config): - """ - This function provides an alternative to main() that is more friendly for - nose tests as it doesn't catch any exceptions. - """ - - lay_cement(config=test_config, banner=BANNER, args=args) - log = get_logger(__name__) - log.debug("Cement Framework Initialized!") - - if not len(args) > 1: - args.append('default') - - (res, output_txt) = run_command(args[1]) - return (res, output_txt) - -if __name__ == '__main__': - main() - diff --git a/src/cement.test/cement_test/core/config.py b/src/cement.test/cement_test/core/config.py deleted file mode 100644 index 52c29ea2..00000000 --- a/src/cement.test/cement_test/core/config.py +++ /dev/null @@ -1,67 +0,0 @@ -""" -This is the applications default configuration. You can feel free to alter -this file to your needs, however it should be noted that all these variables -are overridden by settings in /etc/cement_test/cement_test.conf and/or -~/.cement_test.conf (by default) and therefore, any default configurations -you want to make obvious to your users should be set in your default config -file as packaged with the software. -""" - -import os -from tempfile import mkdtemp -from configobj import ConfigObj - -from cement.core.exc import CementConfigError - -# This is a sane default for development/no config -prefix = os.path.join(os.environ['HOME'], '.cement_test') - -dcf = ConfigObj() # default config -dcf['config_source'] = ['defaults'] -dcf['app_name'] = 'cement-test' # name for cli like /etc/ -dcf['app_egg_name'] = 'cement.test' # name from setup.py -dcf['app_module'] = 'cement_test' # name of the library dir - -dcf['enabled_plugins'] = [] # no default plugins, add via the config file -dcf['debug'] = False -dcf['datadir'] = '%s/data' % prefix -dcf['tmpdir'] = '%s/tmp' % prefix -dcf['log_file'] = '%s/log/%s.log' % (prefix, dcf['app_name']) -dcf['plugin_config_dir'] = '%s/etc/plugins.d' % prefix -dcf['log_to_console'] = True -dcf['output_engine'] = 'genshi' -dcf['show_plugin_load'] = False - -# By default look in /etc and ~/ for config files. You should probably -# symlink /etc/ => ./etc/ for easy development. -dcf['config_files'] = [ - os.path.join('/etc', dcf['app_name'], '%s.conf' % dcf['app_name']), - os.path.join(prefix, 'etc', '%s.conf' % dcf['app_name']), - os.path.join(os.environ['HOME'], '.%s.conf' % dcf['app_name']), - ] - -default_config = dcf - -def get_nose_config(prefix=None): - if not prefix: - prefix = mkdtemp() - - tcf = ConfigObj() # test config - tcf['config_files'] = [os.path.abspath('./config/cement-test.conf')] - tcf['config_source'] = ['defaults'] - tcf['app_name'] = 'cement_test' - tcf['app_egg_name'] = 'cement.test' - tcf['app_module'] = 'cement_test' - tcf['app_basepath'] = os.path.dirname(__file__) - tcf['nosetests'] = True - tcf['enabled_plugins'] = [] - tcf['debug'] = False - tcf['datadir'] = '%s/data' % prefix - tcf['tmpdir'] = '%s/tmp' % prefix - tcf['log_file'] = '%s/log/%s.log' % (prefix, tcf['app_name']) - tcf['plugin_config_dir'] = './config/plugins.d' - tcf['log_to_console'] = False - tcf['output_engine'] = 'genshi' - tcf['show_plugin_load'] = False - tcf['ignore_duplicate_framework_exceptions'] = True - return tcf diff --git a/src/cement.test/cement_test/core/exc.py b/src/cement.test/cement_test/core/exc.py deleted file mode 100644 index e912d3ce..00000000 --- a/src/cement.test/cement_test/core/exc.py +++ /dev/null @@ -1,32 +0,0 @@ -"""cement_test exception classes.""" - -class CementTestError(Exception): - """Generic errors.""" - def __init__(self, value, code=1): - Exception.__init__(self) - self.msg = value - self.code = code - - def __str__(self): - return self.msg - - def __unicode__(self): - return unicode(self.msg) - -class CementTestConfigError(CementTestError): - """Config parsing and setup errors.""" - def __init__(self, value): - code = 10 - CementTestError.__init__(self, value, code) - -class CementTestRuntimeError(CementTestError): - """Runtime errors.""" - def __init__(self, value): - code = 20 - CementTestError.__init__(self, value, code) - -class CementTestArgumentError(CementTestError): - """Argument errors.""" - def __init__(self, value): - code = 40 - CementTestError.__init__(self, value, code) diff --git a/src/cement.test/cement_test/core/testing.py b/src/cement.test/cement_test/core/testing.py deleted file mode 100644 index f2eb2043..00000000 --- a/src/cement.test/cement_test/core/testing.py +++ /dev/null @@ -1,16 +0,0 @@ - -import os -import shutil -from tempfile import mkdtemp -from cement import namespaces - -def setup_func(): - """Setup operations before every test.""" - namespaces['root'].config['datadir'] = mkdtemp() - if not os.path.exists(namespaces['root'].config['datadir']): - os.makedirs(namespaces['root'].config['datadir']) - -def teardown_func(): - """Teardown operations after every test.""" - if os.path.exists(namespaces['root'].config['datadir']): - shutil.rmtree(namespaces['root'].config['datadir']) \ No newline at end of file diff --git a/src/cement.test/cement_test/helpers/__init__.py b/src/cement.test/cement_test/helpers/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.test/cement_test/helpers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.test/cement_test/lib/__init__.py b/src/cement.test/cement_test/lib/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.test/cement_test/lib/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.test/cement_test/model/__init__.py b/src/cement.test/cement_test/model/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.test/cement_test/model/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.test/cement_test/model/example.py b/src/cement.test/cement_test/model/example.py deleted file mode 100644 index 28fceb9b..00000000 --- a/src/cement.test/cement_test/model/example.py +++ /dev/null @@ -1,13 +0,0 @@ -""" -This is an example model. This can be anything, just a straight class -or perhaps an SQLAlchemy DeclarativeBase, etc. -""" - -from cement.core.log import get_logger - -log = get_logger(__name__) - -class ExampleModel(object): - id = int() - label = u'' - description = u'' \ No newline at end of file diff --git a/src/cement.test/cement_test/model/root.py b/src/cement.test/cement_test/model/root.py deleted file mode 100644 index 9f6e37b4..00000000 --- a/src/cement.test/cement_test/model/root.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -The root model can be used to consolidate all of your models under one. - -A recommended way of accessing your model throughout your application is to -import all model classes into the 'root' model file like so: - -**helloworld/model/root.py** - -.. code-block:: python - - from helloworld.model.example import Example - from helloworld.model.user import User - from helloworld.model.product import Product - - -Then, throughout your application you can access all of you module objects -like this: - -.. code-block:: python - - from helloworld.model import root as model - - user = model.User() - product = model.Product() - -""" - -# from helloworld.model.example import Example diff --git a/src/cement.test/cement_test/templates/__init__.py b/src/cement.test/cement_test/templates/__init__.py deleted file mode 100644 index b0d64337..00000000 --- a/src/cement.test/cement_test/templates/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file diff --git a/src/cement.test/cement_test/templates/example/__init__.py b/src/cement.test/cement_test/templates/example/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/cement.test/cement_test/templates/example/ex2.txt b/src/cement.test/cement_test/templates/example/ex2.txt deleted file mode 100644 index 06db74c0..00000000 --- a/src/cement.test/cement_test/templates/example/ex2.txt +++ /dev/null @@ -1,28 +0,0 @@ -{# This is an example Genshi Text Template. Documentation is available #}\ -{# at: #}\ -{# #}\ -{# http://genshi.edgewall.org/wiki/Documentation/text-templates.html #}\ -{# #}\ -\ -\ -{# --------------------- 78 character baseline --------------------------- #}\ - -There are a number of things you can do such as conditional statements: - -{% if foo %}\ -Label: ${example.label} -{% end %}\ - -Or a for loop: - -{% for item in items %}\ - * ${item} -{% end %}\ - -And functions: - -{% def greeting(name) %}\ - Hello, ${name}! -{% end %}\ -${greeting('World')}\ -${greeting('Edward')} \ No newline at end of file diff --git a/src/cement.test/cement_test/templates/root/__init__.py b/src/cement.test/cement_test/templates/root/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/cement.test/cement_test/templates/root/cmd1.txt b/src/cement.test/cement_test/templates/root/cmd1.txt deleted file mode 100644 index 1ac3e213..00000000 --- a/src/cement.test/cement_test/templates/root/cmd1.txt +++ /dev/null @@ -1 +0,0 @@ -{% for item in items %}$item {% end %} \ No newline at end of file diff --git a/src/cement.test/cement_test/templates/root/error.txt b/src/cement.test/cement_test/templates/root/error.txt deleted file mode 100644 index d9117e25..00000000 --- a/src/cement.test/cement_test/templates/root/error.txt +++ /dev/null @@ -1,7 +0,0 @@ -{# --------------------- 78 character baseline --------------------------- #}\ - -The following errors were encountered: ------------------------------------------------------------------------------ -{% for error in errors %}\ - * ${error[0]} => ${error[1]} -{% end %} \ No newline at end of file diff --git a/src/cement.test/cement_test/templates/root/get-started.txt b/src/cement.test/cement_test/templates/root/get-started.txt deleted file mode 100644 index 1a68831e..00000000 --- a/src/cement.test/cement_test/templates/root/get-started.txt +++ /dev/null @@ -1,62 +0,0 @@ -{# --------------------- 78 character baseline --------------------------- #}\ -Welcome to ${config['app_name']}. - -This application is built on Cement, and is ready to rock! Out of the box you -already have: - -{% for feature in features %}\ - * $feature -{% end %}\ - -If your config file is setup right, you should notice that your app is already -loading an 'example' plugin. Plugins are enabled by adding a plugin config -file in your plugin_config_dir (see cement_test.conf). The plugin config -must have a [] section and under that section you must set the -following setting - - * enable_plugin=true - -This will tell Cement to load that plugin. You can also load plugins from -other projects built on Cement by also adding the following setting: - - * provider = someotherapp - -Where 'someotherapp' is the package name of the application providing the -plugin. - -The included example plugin is a great starting point to learn how to build on -top of the Cement Framework. The following files and directories should be -explored: - - * ./cement_test/bootstrap/example.py - * ./cement_test/controllers/example.py - * ./cement_test/model/example.py - * ./cement_test/templates/example/ - - -This command is defined in the RootController in: - - cement_test/controllers/root.py - - -Additionally, the output of this command is rendered by the Genshi templating -engine. The template is at cement_test/templates/root/get-started.txt. -You can find documentation here on the template syntax here: - - * $genshi_link - - -That said, you can also render the output of commands as JSON. Don't believe -me? Just run it again with the --json flag. - -To make the included 'example' plugin a permanent part of your application you -simply need to add the following to cement_test/bootstrap/root.py: - - from cement_test.bootstrap import example - - -That said, by following the example plugin you can easily create built in code -or additional plugins in the same fashion. - -Go forth, and code! - diff --git a/src/cement.test/config/cement-test-logging.conf b/src/cement.test/config/cement-test-logging.conf deleted file mode 100644 index af2b1334..00000000 --- a/src/cement.test/config/cement-test-logging.conf +++ /dev/null @@ -1,23 +0,0 @@ -[loggers] -keys = root - -[handlers] -keys = hand01 - -[formatters] -keys = form01 - -[logger_root] -level=DEBUG -handlers=hand01 - -[handler_hand01] -class=StreamHandler -level=NOTSET -formatter=form01 -args=(sys.stdout,) - -[formatter_form01] -format=F1 %(asctime)s %(levelname)s %(message)s -datefmt= -class=logging.Formatter diff --git a/src/cement.test/config/cement-test.conf b/src/cement.test/config/cement-test.conf deleted file mode 100644 index 5cff01b0..00000000 --- a/src/cement.test/config/cement-test.conf +++ /dev/null @@ -1,31 +0,0 @@ -[root] -# This config file is meant for nose testing and should only be modified -# in a way that will allow nose tests to function. -test_option = 'foobar' -true_false_option = true -true_false_option2 = false -user_dir = '~/' - -[[section1]] -test_option = 'foobar' -true_false_option = true -true_false_option2 = false -user_dir = '~/' - -[[[section2]]] -test_option = 'foobar' -true_false_option = true -true_false_option2 = false -user_dir = '~/' - -# test loading a plugin with a provider specified -[example] -enable_plugin = true -provider = cement_test - -# test loading a plugin with *out* a provider specified -[example2] -enable_plugin = true - -[example_five] -enable_plugin = true diff --git a/src/cement.test/config/plugins.d/bogues_conf_file b/src/cement.test/config/plugins.d/bogues_conf_file deleted file mode 100644 index 09c18485..00000000 --- a/src/cement.test/config/plugins.d/bogues_conf_file +++ /dev/null @@ -1 +0,0 @@ -# don't remove this file, was added for test coverage diff --git a/src/cement.test/config/plugins.d/example3.conf b/src/cement.test/config/plugins.d/example3.conf deleted file mode 100644 index e5c53022..00000000 --- a/src/cement.test/config/plugins.d/example3.conf +++ /dev/null @@ -1,4 +0,0 @@ -# test loading a plugin with a provider specified -[example3] -enable_plugin = true -provider = cement_test diff --git a/src/cement.test/config/plugins.d/example4.conf b/src/cement.test/config/plugins.d/example4.conf deleted file mode 100644 index 28ca2e1f..00000000 --- a/src/cement.test/config/plugins.d/example4.conf +++ /dev/null @@ -1,3 +0,0 @@ -# test loading a plugin with no provider set -[example4] -enable_plugin = true diff --git a/src/cement.test/setup.py b/src/cement.test/setup.py deleted file mode 100644 index f4e0244b..00000000 --- a/src/cement.test/setup.py +++ /dev/null @@ -1,80 +0,0 @@ -from setuptools import setup, find_packages -import sys, os - -VERSION = '0.8.16' - -LONG = """ -Cement is an advanced CLI Application Framework for Python. The 'test' -package provides an external application built on top of Cement, with -additional nose tests to provide unit testing of the framework. To fully -test the framework, a running application is required to cover all bits of the -code. The 'cement.test' application is simply an application created using -the paster utility (cement.devtools) with a bit of added code for testing. -It is only meant to be used in development, for testing. Note that this is -only part of 'cement' as a whole. The entire source is available from: - - http://builtoncement.org/cement/0.8/download/ - - -The Cement CLI Application Framework is Open Source and is distributed under -The MIT License. - - -MORE INFORMATION: - -All documentation is available from the official website: - - http://builtoncement.org - - -GETTING STARTED: - -Development versions can be checked out of Git: -:: - $ git clone git://github.com/derks/cement.git - - $ cd cement/src/cement.test/ - - $ python setup.py install - - $ nosetests --verbosity 3 - -""" - -setup(name='cement.test', - version=VERSION, - description='Comprehensive Testing of the Cement CLI Application Framework', - long_description=LONG, - classifiers=[], - keywords='cement', - author='BJ Dierkes', - author_email='wdierkes@5dollarwhitebox.org', - url='http://builtoncement.org', - license='MIT', - packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), - include_package_data=True, - zip_safe=False, - install_requires=[ - "ConfigObj", - "Genshi", - "cement >=0.8.9, <0.9", - "nose", - "jsonpickle", - ], - setup_requires=[ - ], - test_suite='nose.collector', - entry_points=""" - [console_scripts] - cement-test = cement_test.core.appmain:main - """, - namespace_packages=[ - 'cement_test', - 'cement_test.lib', - 'cement_test.bootstrap', - 'cement_test.controllers', - 'cement_test.model', - 'cement_test.helpers', - 'cement_test.templates', - ], - ) diff --git a/src/cement.test/tests/00_tests_start.py b/src/cement.test/tests/00_tests_start.py deleted file mode 100644 index 5abe3fd8..00000000 --- a/src/cement.test/tests/00_tests_start.py +++ /dev/null @@ -1,19 +0,0 @@ - -import sys - -from tempfile import mkdtemp -from nose.tools import raises, with_setup - -from cement_test.core.config import get_nose_config -from cement_test.core.appmain import nose_main - -sys.path.insert(0, '.') -# use an altername config for testing -config = get_nose_config(mkdtemp()) - -# run the initial main, which bootstraps the base application -nose_main([__file__, 'nosetests', '--quiet'], config) - -def test_initialize(): - """We put this here just to ensure nose picks up this file.""" - pass diff --git a/src/cement.test/tests/__init__.py b/src/cement.test/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/cement.test/tests/app_setup_tests.py b/src/cement.test/tests/app_setup_tests.py deleted file mode 100644 index a58ff1d1..00000000 --- a/src/cement.test/tests/app_setup_tests.py +++ /dev/null @@ -1,51 +0,0 @@ - -from configobj import ConfigObj -from nose.tools import raises, with_setup - -from cement import hooks, namespaces, handlers -from cement.core.exc import CementConfigError -from cement.core.app_setup import lay_cement, define_default_hooks -from cement.core.app_setup import define_default_handler_types -from cement.core.app_setup import register_default_handlers - -from cement_test.core.testing import setup_func, teardown_func - -@with_setup(setup_func, teardown_func) -def test_defined_default_hooks(): - global hooks - expected_hooks = [ - 'options_hook', 'post_options_hook', 'validate_config_hook', - 'pre_plugins_hook', 'post_plugins_hook', 'post_bootstrap_hook' - ] - for hook_name in expected_hooks: - yield check_hook, hook_name - -def check_hook(hook_name): - assert hooks.has_key(hook_name) - -@with_setup(setup_func, teardown_func) -def test_defined_default_handler_types(): - global handlers - expected_handler_types = [ - 'output' - ] - for handler_type in expected_handler_types: - yield check_handler_type, handler_type - -def check_handler_type(handler_type): - assert handlers.has_key(handler_type) - -@with_setup(setup_func, teardown_func) -def test_registered_default_handlers(): - global handlers - expected_output = [ - 'genshi', 'json' - ] - for handler in expected_output: - yield check_handler, 'output', handler - -def check_handler(type, name): - assert handlers[type].has_key(name) - -# FIXME: How do you test lay_cement()? Needs a full working (and installed) -# application. diff --git a/src/cement.test/tests/bootstrap_tests.py b/src/cement.test/tests/bootstrap_tests.py deleted file mode 100644 index 7101e43b..00000000 --- a/src/cement.test/tests/bootstrap_tests.py +++ /dev/null @@ -1,17 +0,0 @@ -"""The purpose of this module is to test bootstrapping functionality.""" - -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import namespaces -from cement.core.namespace import get_config -from cement.core.testing import simulate - -from cement_test.core.testing import setup_func, teardown_func - -config = get_config() - -@with_setup(setup_func, teardown_func) -def test_import_install_plugin(): - # example plugin is imported in root bootstrap, so it should have - # a place in global namespaces - ok_(namespaces.has_key('example')) diff --git a/src/cement.test/tests/command_tests.py b/src/cement.test/tests/command_tests.py deleted file mode 100644 index 1d93e14c..00000000 --- a/src/cement.test/tests/command_tests.py +++ /dev/null @@ -1,36 +0,0 @@ -"""The purpose of this module is to test command functionality.""" - -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import namespaces -from cement.core.namespace import get_config -from cement.core.command import run_command -from cement.core.testing import simulate -from cement.core.exc import CementRuntimeError, CementArgumentError - -from cement_test.core.testing import setup_func, teardown_func - -config = get_config() - -@raises(CementArgumentError) -@with_setup(setup_func, teardown_func) -def test_run_command_namespace(): - # raises cause example is a namespace - run_command('example2') - -@raises(CementArgumentError) -@with_setup(setup_func, teardown_func) -def test_run_command_namespace_help(): - # raises cause example is a namespace - run_command('example-help') - -@with_setup(setup_func, teardown_func) -def test_run_command(): - # raises cause example is a namespace - run_command('cmd1') - -@raises(CementArgumentError) -@with_setup(setup_func, teardown_func) -def test_run_unknown_command(): - # raises cause blah doesn't exist - run_command('blah') \ No newline at end of file diff --git a/src/cement.test/tests/config_tests.py b/src/cement.test/tests/config_tests.py deleted file mode 100644 index c58d390c..00000000 --- a/src/cement.test/tests/config_tests.py +++ /dev/null @@ -1,62 +0,0 @@ - -from nose.tools import raises, with_setup, eq_, ok_ -from configobj import ConfigObj - -from cement import namespaces -from cement.core.namespace import get_config -from cement.core.testing import simulate -from cement.core.configuration import ensure_api_compat, validate_config -from cement.core.configuration import get_api_version -from cement.core.configuration import t_f_pass, set_config_opts_per_file -from cement.core.exc import CementRuntimeError, CementConfigError - -from cement_test.core.testing import setup_func, teardown_func -from cement_test.core.exc import CementTestArgumentError, CementTestRuntimeError - -config = get_config() - -@with_setup(setup_func, teardown_func) -def test_config_options(): - eq_(config['test_option'], 'foobar') - -@with_setup(setup_func, teardown_func) -def test_deprecated_api_version(): - get_api_version() - -@with_setup(setup_func, teardown_func) -def test_config_options_per_cli_opts(): - args = ['cement-test', 'nosetests', '--test-option=funions'] - simulate(args) - eq_(config['test_option'], 'funions') - -@with_setup(setup_func, teardown_func) -def test_ensure_api_compat(): - # deprecated - ensure_api_compat(__name__, 'xxxxx') - -@raises(CementConfigError) -@with_setup(setup_func, teardown_func) -def test_validate_config_bad(): - dcf = ConfigObj() # default config - validate_config(dcf) - -@with_setup(setup_func, teardown_func) -def test_t_f_pass(): - for val in ['true', 'True', True]: - yield check_true, val - - for val in ['false', 'False', False]: - yield check_false, val - - for val in ['a', 'Blah Hah', 100]: - yield check_pass, val - -def check_true(val): - assert t_f_pass(val) == True - -def check_false(val): - assert t_f_pass(val) == False - -def check_pass(val): - assert t_f_pass(val) == val - \ No newline at end of file diff --git a/src/cement.test/tests/controller_tests.py b/src/cement.test/tests/controller_tests.py deleted file mode 100644 index 07281d5a..00000000 --- a/src/cement.test/tests/controller_tests.py +++ /dev/null @@ -1,72 +0,0 @@ -"""The purpose of this module is to test controller functionality.""" - -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import namespaces -from cement.core.namespace import get_config -from cement.core.controller import expose, CementController -from cement.core.controller import run_controller_command -from cement.core.testing import simulate -from cement.core.exc import CementRuntimeError, CementArgumentError - -from cement_test.core.testing import setup_func, teardown_func -from cement_test.core.exc import CementTestArgumentError - -config = get_config() - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_bogus_output_handler(): - simulate([__file__, 'bogus-cmd1']) - -@with_setup(setup_func, teardown_func) -def test_error_handler(): - (res, out) = run_controller_command('root', 'error', errors=[('label', 'msg')]) - eq_(res, dict(errors=[('label', 'msg')])) - -@raises(CementTestArgumentError) -@with_setup(setup_func, teardown_func) -def test_default_cmd(): - (res, out) = simulate([__file__, 'default']) - -@with_setup(setup_func, teardown_func) -def test_default_namespace_cmd(): - (res, out) = simulate([__file__, 'example']) - -@raises(CementArgumentError) -@with_setup(setup_func, teardown_func) -def test_bogus_cmd(): - simulate([__file__, 'bogus-cmd-does-not-exist']) - -@with_setup(setup_func, teardown_func) -def test_controller_class(): - # FIXME: passing bogus cause cli_opts is actually an object, but we just - # want to test that self.cli_opts is getting assigned - c = CementController(cli_opts='bogus', cli_args=['a', 'b']) - assert c.cli_opts == 'bogus', "self.cli_opts is not getting set." - assert 'a' in c.cli_args, "self.cli_opts is not getting set." - -# test for coverage -@with_setup(setup_func, teardown_func) -def test_root_cmd1_help(): - simulate([__file__, 'cmd1-help', '--debug']) - -@with_setup(setup_func, teardown_func) -def test_get_started(): - simulate([__file__, 'get-started']) - -@with_setup(setup_func, teardown_func) -def test_example_cmd1(): - simulate([__file__, 'example', 'cmd1']) - -@with_setup(setup_func, teardown_func) -def test_example2_cmd1(): - simulate([__file__, 'example2', 'cmd1']) - -@with_setup(setup_func, teardown_func) -def test_example3_cmd1(): - simulate([__file__, 'example3', 'cmd1']) - -@with_setup(setup_func, teardown_func) -def test_example4_cmd1(): - simulate([__file__, 'example4', 'cmd1']) diff --git a/src/cement.test/tests/core_tests.py b/src/cement.test/tests/core_tests.py deleted file mode 100644 index d060ee09..00000000 --- a/src/cement.test/tests/core_tests.py +++ /dev/null @@ -1,39 +0,0 @@ - -"""The purpose of this module is to test core functionality.""" - -import jsonpickle -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import namespaces -from cement.core.namespace import get_config -from cement.core.testing import simulate -from cement.core.exc import CementArgumentError -from cement_test.core.testing import setup_func, teardown_func - -config = get_config() - -@with_setup(setup_func, teardown_func) -def test_json_output_handler(): - # bit of a hack, but this is handled before the nose stuff... so, have to - # redo it here to make it work - orig = namespaces['root'].config['output_handler_override'] - namespaces['root'].config['output_handler_override'] = 'json' - namespaces['root'].config['show_plugin_load'] = False - - (res, out_txt) = simulate([__file__, 'cmd1', '--json']) - res_json = jsonpickle.decode(out_txt) - eq_(res_json['items'][0], 'one') - - namespaces['root'].config['output_handler_override'] = orig - -@raises(CementArgumentError) -@with_setup(setup_func, teardown_func) -def test_root_command_that_does_not_exist(): - (res, out_txt) = simulate([__file__, 'non_existent']) - -@with_setup(setup_func, teardown_func) -def test_example_namespace(): - (res, out_txt) = simulate([__file__, 'example', 'cmd1']) - - - diff --git a/src/cement.test/tests/exc_tests.py b/src/cement.test/tests/exc_tests.py deleted file mode 100644 index 1db077ef..00000000 --- a/src/cement.test/tests/exc_tests.py +++ /dev/null @@ -1,72 +0,0 @@ -"""The purpose of this module is to test exception functionality.""" - -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import namespaces -from cement.core.namespace import get_config -from cement.core.controller import expose -from cement.core.testing import simulate -from cement.core.exc import CementError, CementRuntimeError, CementConfigError -from cement.core.exc import CementArgumentError - -from cement_test.core.testing import setup_func, teardown_func -from cement_test.core.exc import CementTestError, CementTestRuntimeError -from cement_test.core.exc import CementTestArgumentError, CementTestConfigError - -config = get_config() - -@raises(CementError) -@with_setup(setup_func, teardown_func) -def test_error(): - raise CementError, 'this is a cement error' - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_runtime_error(): - raise CementRuntimeError, 'this is a cement error' - -@raises(CementConfigError) -@with_setup(setup_func, teardown_func) -def test_config_error(): - raise CementConfigError, 'this is a cement error' - -@raises(CementArgumentError) -@with_setup(setup_func, teardown_func) -def test_argument_error(): - raise CementArgumentError, 'this is a cement error' - -@with_setup(setup_func, teardown_func) -def test_error_str_and_unicode(): - try: - raise CementError, 'this is a cement error' - except CementError, e: - eq_(e.__str__(), 'this is a cement error') - eq_(e.__unicode__(), u'this is a cement error') - -@raises(CementTestError) -@with_setup(setup_func, teardown_func) -def test_app_error(): - raise CementTestError, 'this is a cement test error' - -@raises(CementTestRuntimeError) -@with_setup(setup_func, teardown_func) -def test_app_runtime_error(): - raise CementTestRuntimeError, 'this is a cement test error' - -@raises(CementTestConfigError) -@with_setup(setup_func, teardown_func) -def test_app_config_error(): - raise CementTestConfigError, 'this is a cement test error' - -@raises(CementTestArgumentError) -@with_setup(setup_func, teardown_func) -def test_app_argument_error(): - raise CementTestArgumentError, 'this is a cement test error' - -@with_setup(setup_func, teardown_func) -def test_app_error_str_and_unicode(): - try: - raise CementTestError, 'this is a cement test error' - except CementTestError, e: - eq_(e.__str__(), 'this is a cement test error') - eq_(e.__unicode__(), u'this is a cement test error') \ No newline at end of file diff --git a/src/cement.test/tests/handler_tests.py b/src/cement.test/tests/handler_tests.py deleted file mode 100644 index 57f6bd85..00000000 --- a/src/cement.test/tests/handler_tests.py +++ /dev/null @@ -1,37 +0,0 @@ -"""The purpose of this module is to test handler functionality.""" - -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import namespaces -from cement.core.namespace import get_config -from cement.core.testing import simulate -from cement.core.handler import get_handler, define_handler, register_handler -from cement.core.exc import CementRuntimeError - -from cement_test.core.testing import setup_func, teardown_func - -config = get_config() - -@with_setup(setup_func, teardown_func) -def test_get_handler(): - get_handler('output', 'json') - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_get_handler_bad(): - get_handler('output', 'bogus handler name') - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_define_duplicate_handler(): - define_handler('output') - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_register_to_bogus_handler(): - register_handler('bogus_handler', 'bogus', None) - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_register_duplicate_handler(): - register_handler('output', 'json', None) \ No newline at end of file diff --git a/src/cement.test/tests/hook_tests.py b/src/cement.test/tests/hook_tests.py deleted file mode 100644 index a6ee6149..00000000 --- a/src/cement.test/tests/hook_tests.py +++ /dev/null @@ -1,46 +0,0 @@ -"""The purpose of this module is to test hook functionality.""" - -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import hooks -from cement.core.hook import run_hooks, define_hook, register_hook -from cement.core.namespace import get_config -from cement.core.testing import simulate -from cement.core.exc import CementRuntimeError - -from cement_test.core.testing import setup_func, teardown_func -from cement_test.core.exc import CementTestArgumentError, CementTestRuntimeError - -config = get_config() - -@with_setup(setup_func, teardown_func) -def test_my_example_hook(): - ok_(hooks.has_key('my_example_hook')) - - hook_results = [] - - for res in run_hooks('my_example_hook'): - hook_results.append(res) - - # return results are the weight of the hook and should be in numerical - # order - res = hook_results = [-100, 0, 99] - ok_(res) - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_define_duplicate_hook(): - define_hook('my_example_hook') - -@with_setup(setup_func, teardown_func) -@register_hook(name='bogus_hook_name') -def test_register_duplicate_hook(): - # this doesn't raise, just testing for coverage - pass - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_run_hook_that_does_not_exist(): - for res in run_hooks('bogus_hook'): - pass - diff --git a/src/cement.test/tests/log_tests.py b/src/cement.test/tests/log_tests.py deleted file mode 100644 index 892951c7..00000000 --- a/src/cement.test/tests/log_tests.py +++ /dev/null @@ -1,38 +0,0 @@ -"""The purpose of this module is to test logging functionality.""" - -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import namespaces, hooks -from cement.core.log import setup_logging -from cement.core.namespace import get_config -from cement.core.testing import simulate -from cement.core.exc import CementRuntimeError, CementConfigError - -from cement_test.core.testing import setup_func, teardown_func -from cement_test.core.exc import CementTestArgumentError, CementTestRuntimeError - -config = get_config() - -@with_setup(setup_func, teardown_func) -def test_setup_alternate_logging(): - namespaces['root'].config['debug'] = True - setup_logging(clear_loggers=True, level='DEBUG', to_console=True) - - namespaces['root'].config['debug'] = False - setup_logging(clear_loggers=True, level='INFO', to_console=True) - - namespaces['root'].config['log_max_bytes'] = 1024000 - namespaces['root'].config['log_level'] = 'warn' - setup_logging() - -@with_setup(setup_func, teardown_func) -def test_setup_logging_per_config_file(): - namespaces['root'].config['logging_config_file'] = './config/cement-test-logging.conf' - setup_logging() - -@raises(CementConfigError) -@with_setup(setup_func, teardown_func) -def test_setup_logging_per_bogus_config_file(): - namespaces['root'].config['logging_config_file'] = 'bollox' - setup_logging() - \ No newline at end of file diff --git a/src/cement.test/tests/namespace_tests.py b/src/cement.test/tests/namespace_tests.py deleted file mode 100644 index 5ecf72a3..00000000 --- a/src/cement.test/tests/namespace_tests.py +++ /dev/null @@ -1,46 +0,0 @@ -"""The purpose of this module is to test namespace functionality.""" - -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import namespaces -from cement.core.namespace import get_config, get_namespace, define_namespace -from cement.core.namespace import CementNamespace -from cement.core.testing import simulate -from cement.core.handler import get_handler, define_handler, register_handler -from cement.core.exc import CementRuntimeError - -from cement_test.core.testing import setup_func, teardown_func - -config = get_config() - -@with_setup(setup_func, teardown_func) -def test_get_handler(): - root = get_namespace('root') - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_get_bogus_handler(): - root = get_namespace('bogus_namespace') - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_get_bogus_config(): - _cnf = get_config('bogus_namespace') - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_define_duplicate_namespace(): - bogus = CementNamespace( - label='root', - controller='RootController', - version='1.0', - required_api='xxxx', - provider='cement_test') - define_namespace('root', bogus) - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_define_broken_namespace(): - bogus = CementNamespace( - label='root', - controller='RootController') \ No newline at end of file diff --git a/src/cement.test/tests/plugin_tests.py b/src/cement.test/tests/plugin_tests.py deleted file mode 100644 index 47429ac2..00000000 --- a/src/cement.test/tests/plugin_tests.py +++ /dev/null @@ -1,23 +0,0 @@ -"""The purpose of this module is to test plugin functionality.""" - -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import namespaces -from cement.core.namespace import get_config -from cement.core.plugin import load_plugin -from cement.core.testing import simulate -from cement.core.exc import CementRuntimeError, CementConfigError - -from cement_test.core.testing import setup_func, teardown_func - -config = get_config() - -@raises(CementRuntimeError) -@with_setup(setup_func, teardown_func) -def test_load_bogus_plugin(): - load_plugin('some_bogus_plugin') - -@raises(CementConfigError) -@with_setup(setup_func, teardown_func) -def test_load_plugin_with_bogus_provider(): - load_plugin('some_bogus_provider.plugin.example') \ No newline at end of file diff --git a/src/cement.test/tests/view_tests.py b/src/cement.test/tests/view_tests.py deleted file mode 100644 index ae0c03f3..00000000 --- a/src/cement.test/tests/view_tests.py +++ /dev/null @@ -1,32 +0,0 @@ -"""The purpose of this module is to test view functionality.""" - -from nose.tools import raises, with_setup, eq_, ok_ - -from cement import namespaces -from cement.core.namespace import get_config -from cement.core.controller import expose -from cement.core.testing import simulate -from cement.core.exc import CementRuntimeError - -from cement_test.core.testing import setup_func, teardown_func - -config = get_config() - -@with_setup(setup_func, teardown_func) -def test_genshi(): - orig = namespaces['root'].config['output_handler_override'] - namespaces['root'].config['output_handler_override'] = 'genshi' - - (res, out) = simulate([__file__, 'cmd1']) - eq_(out, 'one two three ') - namespaces['root'].config['output_handler_override'] = orig - -@with_setup(setup_func, teardown_func) -def test_output_file(): - (res, out) = simulate([__file__, 'send-to-file']) - -@with_setup(setup_func, teardown_func) -def test_log_to_console(): - namespaces['root'].config['log_to_console'] = True - (res, out) = simulate([__file__, 'cmd1']) - namespaces['root'].config['log_to_console'] = False diff --git a/src/cement/LICENSE b/src/cement/LICENSE deleted file mode 100644 index f7be018c..00000000 --- a/src/cement/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ - -The MIT License: - -Copyright (c) 2009-2010 BJ Dierkes - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - diff --git a/src/cement/LICENSE.psf b/src/cement/LICENSE.psf deleted file mode 100644 index 33110db8..00000000 --- a/src/cement/LICENSE.psf +++ /dev/null @@ -1,53 +0,0 @@ - -Cement has included ./src/cement/backports/pkgutil.py for backward -compatibility with Python < 2.6 (for pkgutil.get_data()). That file alone -has the following license: - -PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 --------------------------------------------- - -1. This LICENSE AGREEMENT is between the Python Software Foundation -("PSF"), and the Individual or Organization ("Licensee") accessing and -otherwise using this software ("Python") in source or binary form and -its associated documentation. - -2. Subject to the terms and conditions of this License Agreement, PSF hereby -grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, -analyze, test, perform and/or display publicly, prepare derivative works, -distribute, and otherwise use Python alone or in any derivative version, -provided, however, that PSF's License Agreement and PSF's notice of copyright, -i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 -Python Software Foundation; All Rights Reserved" are retained in Python alone or -in any derivative version prepared by Licensee. - -3. In the event Licensee prepares a derivative work that is based on -or incorporates Python or any part thereof, and wants to make -the derivative work available to others as provided herein, then -Licensee hereby agrees to include in any such work a brief summary of -the changes made to Python. - -4. PSF is making Python available to Licensee on an "AS IS" -basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR -IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND -DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS -FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT -INFRINGE ANY THIRD PARTY RIGHTS. - -5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON -FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS -A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, -OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. - -6. This License Agreement will automatically terminate upon a material -breach of its terms and conditions. - -7. Nothing in this License Agreement shall be deemed to create any -relationship of agency, partnership, or joint venture between PSF and -Licensee. This License Agreement does not grant permission to use PSF -trademarks or trade name in a trademark sense to endorse or promote -products or services of Licensee, or any third party. - -8. By copying, installing or otherwise using Python, Licensee -agrees to be bound by the terms and conditions of this License -Agreement. - diff --git a/src/cement/MANIFEST.in b/src/cement/MANIFEST.in deleted file mode 100644 index e69de29b..00000000 diff --git a/src/cement/README b/src/cement/README deleted file mode 100644 index 85b25040..00000000 --- a/src/cement/README +++ /dev/null @@ -1,44 +0,0 @@ - -NAME: cement - -AUTHOR: BJ Dierkes - -DESCRIPTION: - -Cement is an advanced CLI Application Framework for Python. This package -provides the core framework required to run an application built on top of -Cement. Note that this is only part of 'cement' as a whole. The entire -source is available from: - - http://builtoncement.org/cement/0.8/download/ - - -The Cement CLI Application Framework is Open Source and is distributed under -The MIT License. - - -MORE INFORMATION: - -All documentation is available from the official website: - - http://builtoncement.org - - -GETTING STARTED: - -Stable versions can be installed via the cheeze shop: -:: - $ easy_install cement - - -Development versions can be checked out of Git: -:: - $ git clone git://github.com/derks/cement.git - - $ cd cement/src/cement/ - - $ python setup.py install - - -For development, and actually building applications on Cement, please see the -cement.devtools package. \ No newline at end of file diff --git a/src/cement/cement/__init__.py b/src/cement/cement/__init__.py deleted file mode 100644 index d2c5aabb..00000000 --- a/src/cement/cement/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -"""Cement top level module""" - -import sys -from cement.core.configuration import namespaces, hooks, handlers - -SAVED_STDOUT = sys.stdout -SAVED_STDERR = sys.stderr - -class StdOutBuffer(object): - buffer = '' - def write(self, text): - self.buffer += text - -class StdErrBuffer(object): - buffer = '' - def write(self, text): - self.buffer += text - -# These will only be used if --quiet or --json are passed -buf_stdout = StdOutBuffer() -buf_stderr = StdErrBuffer() diff --git a/src/cement/cement/backports/__init__.py b/src/cement/cement/backports/__init__.py deleted file mode 100644 index d97cb1f1..00000000 --- a/src/cement/cement/backports/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -"""Cement backports (compatibility) module""" -__import__('pkg_resources').declare_namespace(__name__) diff --git a/src/cement/cement/backports/pkgutil.py b/src/cement/cement/backports/pkgutil.py deleted file mode 100644 index c50928f7..00000000 --- a/src/cement/cement/backports/pkgutil.py +++ /dev/null @@ -1,583 +0,0 @@ -"""Utilities to support packages.""" - -# NOTE: This module must remain compatible with Python 2.3, as it is shared -# by setuptools for distribution with Python 2.3 and up. - -import os -import sys -import imp -import os.path -from types import ModuleType - -__all__ = [ - 'get_importer', 'iter_importers', 'get_loader', 'find_loader', - 'walk_packages', 'iter_modules', - 'ImpImporter', 'ImpLoader', 'read_code', 'extend_path', -] - -def read_code(stream): - # This helper is needed in order for the PEP 302 emulation to - # correctly handle compiled files - import marshal - - magic = stream.read(4) - if magic != imp.get_magic(): - return None - - stream.read(4) # Skip timestamp - return marshal.load(stream) - - -def simplegeneric(func): - """Make a trivial single-dispatch generic function""" - registry = {} - def wrapper(*args, **kw): - ob = args[0] - try: - cls = ob.__class__ - except AttributeError: - cls = type(ob) - try: - mro = cls.__mro__ - except AttributeError: - try: - class cls(cls, object): - pass - mro = cls.__mro__[1:] - except TypeError: - mro = object, # must be an ExtensionClass or some such :( - for t in mro: - if t in registry: - return registry[t](*args, **kw) - else: - return func(*args, **kw) - try: - wrapper.__name__ = func.__name__ - except (TypeError, AttributeError): - pass # Python 2.3 doesn't allow functions to be renamed - - def register(typ, func=None): - if func is None: - return lambda f: register(typ, f) - registry[typ] = func - return func - - wrapper.__dict__ = func.__dict__ - wrapper.__doc__ = func.__doc__ - wrapper.register = register - return wrapper - - -def walk_packages(path=None, prefix='', onerror=None): - """Yields (module_loader, name, ispkg) for all modules recursively - on path, or, if path is None, all accessible modules. - - 'path' should be either None or a list of paths to look for - modules in. - - 'prefix' is a string to output on the front of every module name - on output. - - Note that this function must import all *packages* (NOT all - modules!) on the given path, in order to access the __path__ - attribute to find submodules. - - 'onerror' is a function which gets called with one argument (the - name of the package which was being imported) if any exception - occurs while trying to import a package. If no onerror function is - supplied, ImportErrors are caught and ignored, while all other - exceptions are propagated, terminating the search. - - Examples: - - # list all modules python can access - walk_packages() - - # list all submodules of ctypes - walk_packages(ctypes.__path__, ctypes.__name__+'.') - """ - - def seen(p, m={}): - if p in m: - return True - m[p] = True - - for importer, name, ispkg in iter_modules(path, prefix): - yield importer, name, ispkg - - if ispkg: - try: - __import__(name) - except ImportError: - if onerror is not None: - onerror(name) - except Exception: - if onerror is not None: - onerror(name) - else: - raise - else: - path = getattr(sys.modules[name], '__path__', None) or [] - - # don't traverse path items we've seen before - path = [p for p in path if not seen(p)] - - for item in walk_packages(path, name+'.', onerror): - yield item - - -def iter_modules(path=None, prefix=''): - """Yields (module_loader, name, ispkg) for all submodules on path, - or, if path is None, all top-level modules on sys.path. - - 'path' should be either None or a list of paths to look for - modules in. - - 'prefix' is a string to output on the front of every module name - on output. - """ - - if path is None: - importers = iter_importers() - else: - importers = map(get_importer, path) - - yielded = {} - for i in importers: - for name, ispkg in iter_importer_modules(i, prefix): - if name not in yielded: - yielded[name] = 1 - yield i, name, ispkg - - -#@simplegeneric -def iter_importer_modules(importer, prefix=''): - if not hasattr(importer, 'iter_modules'): - return [] - return importer.iter_modules(prefix) - -iter_importer_modules = simplegeneric(iter_importer_modules) - - -class ImpImporter: - """PEP 302 Importer that wraps Python's "classic" import algorithm - - ImpImporter(dirname) produces a PEP 302 importer that searches that - directory. ImpImporter(None) produces a PEP 302 importer that searches - the current sys.path, plus any modules that are frozen or built-in. - - Note that ImpImporter does not currently support being used by placement - on sys.meta_path. - """ - - def __init__(self, path=None): - self.path = path - - def find_module(self, fullname, path=None): - # Note: we ignore 'path' argument since it is only used via meta_path - subname = fullname.split(".")[-1] - if subname != fullname and self.path is None: - return None - if self.path is None: - path = None - else: - path = [os.path.realpath(self.path)] - try: - file, filename, etc = imp.find_module(subname, path) - except ImportError: - return None - return ImpLoader(fullname, file, filename, etc) - - def iter_modules(self, prefix=''): - if self.path is None or not os.path.isdir(self.path): - return - - yielded = {} - import inspect - - filenames = os.listdir(self.path) - filenames.sort() # handle packages before same-named modules - - for fn in filenames: - modname = inspect.getmodulename(fn) - if modname=='__init__' or modname in yielded: - continue - - path = os.path.join(self.path, fn) - ispkg = False - - if not modname and os.path.isdir(path) and '.' not in fn: - modname = fn - for fn in os.listdir(path): - subname = inspect.getmodulename(fn) - if subname=='__init__': - ispkg = True - break - else: - continue # not a package - - if modname and '.' not in modname: - yielded[modname] = 1 - yield prefix + modname, ispkg - - -class ImpLoader: - """PEP 302 Loader that wraps Python's "classic" import algorithm - """ - code = source = None - - def __init__(self, fullname, file, filename, etc): - self.file = file - self.filename = filename - self.fullname = fullname - self.etc = etc - - def load_module(self, fullname): - self._reopen() - try: - mod = imp.load_module(fullname, self.file, self.filename, self.etc) - finally: - if self.file: - self.file.close() - # Note: we don't set __loader__ because we want the module to look - # normal; i.e. this is just a wrapper for standard import machinery - return mod - - def get_data(self, pathname): - return open(pathname, "rb").read() - - def _reopen(self): - if self.file and self.file.closed: - mod_type = self.etc[2] - if mod_type==imp.PY_SOURCE: - self.file = open(self.filename, 'rU') - elif mod_type in (imp.PY_COMPILED, imp.C_EXTENSION): - self.file = open(self.filename, 'rb') - - def _fix_name(self, fullname): - if fullname is None: - fullname = self.fullname - elif fullname != self.fullname: - raise ImportError("Loader for module %s cannot handle " - "module %s" % (self.fullname, fullname)) - return fullname - - def is_package(self, fullname): - fullname = self._fix_name(fullname) - return self.etc[2]==imp.PKG_DIRECTORY - - def get_code(self, fullname=None): - fullname = self._fix_name(fullname) - if self.code is None: - mod_type = self.etc[2] - if mod_type==imp.PY_SOURCE: - source = self.get_source(fullname) - self.code = compile(source, self.filename, 'exec') - elif mod_type==imp.PY_COMPILED: - self._reopen() - try: - self.code = read_code(self.file) - finally: - self.file.close() - elif mod_type==imp.PKG_DIRECTORY: - self.code = self._get_delegate().get_code() - return self.code - - def get_source(self, fullname=None): - fullname = self._fix_name(fullname) - if self.source is None: - mod_type = self.etc[2] - if mod_type==imp.PY_SOURCE: - self._reopen() - try: - self.source = self.file.read() - finally: - self.file.close() - elif mod_type==imp.PY_COMPILED: - if os.path.exists(self.filename[:-1]): - f = open(self.filename[:-1], 'rU') - self.source = f.read() - f.close() - elif mod_type==imp.PKG_DIRECTORY: - self.source = self._get_delegate().get_source() - return self.source - - - def _get_delegate(self): - return ImpImporter(self.filename).find_module('__init__') - - def get_filename(self, fullname=None): - fullname = self._fix_name(fullname) - mod_type = self.etc[2] - if self.etc[2]==imp.PKG_DIRECTORY: - return self._get_delegate().get_filename() - elif self.etc[2] in (imp.PY_SOURCE, imp.PY_COMPILED, imp.C_EXTENSION): - return self.filename - return None - - -try: - import zipimport - from zipimport import zipimporter - - def iter_zipimport_modules(importer, prefix=''): - dirlist = zipimport._zip_directory_cache[importer.archive].keys() - dirlist.sort() - _prefix = importer.prefix - plen = len(_prefix) - yielded = {} - import inspect - for fn in dirlist: - if not fn.startswith(_prefix): - continue - - fn = fn[plen:].split(os.sep) - - if len(fn)==2 and fn[1].startswith('__init__.py'): - if fn[0] not in yielded: - yielded[fn[0]] = 1 - yield fn[0], True - - if len(fn)!=1: - continue - - modname = inspect.getmodulename(fn[0]) - if modname=='__init__': - continue - - if modname and '.' not in modname and modname not in yielded: - yielded[modname] = 1 - yield prefix + modname, False - - iter_importer_modules.register(zipimporter, iter_zipimport_modules) - -except ImportError: - pass - - -def get_importer(path_item): - """Retrieve a PEP 302 importer for the given path item - - The returned importer is cached in sys.path_importer_cache - if it was newly created by a path hook. - - If there is no importer, a wrapper around the basic import - machinery is returned. This wrapper is never inserted into - the importer cache (None is inserted instead). - - The cache (or part of it) can be cleared manually if a - rescan of sys.path_hooks is necessary. - """ - try: - importer = sys.path_importer_cache[path_item] - except KeyError: - for path_hook in sys.path_hooks: - try: - importer = path_hook(path_item) - break - except ImportError: - pass - else: - importer = None - sys.path_importer_cache.setdefault(path_item, importer) - - if importer is None: - try: - importer = ImpImporter(path_item) - except ImportError: - importer = None - return importer - - -def iter_importers(fullname=""): - """Yield PEP 302 importers for the given module name - - If fullname contains a '.', the importers will be for the package - containing fullname, otherwise they will be importers for sys.meta_path, - sys.path, and Python's "classic" import machinery, in that order. If - the named module is in a package, that package is imported as a side - effect of invoking this function. - - Non PEP 302 mechanisms (e.g. the Windows registry) used by the - standard import machinery to find files in alternative locations - are partially supported, but are searched AFTER sys.path. Normally, - these locations are searched BEFORE sys.path, preventing sys.path - entries from shadowing them. - - For this to cause a visible difference in behaviour, there must - be a module or package name that is accessible via both sys.path - and one of the non PEP 302 file system mechanisms. In this case, - the emulation will find the former version, while the builtin - import mechanism will find the latter. - - Items of the following types can be affected by this discrepancy: - imp.C_EXTENSION, imp.PY_SOURCE, imp.PY_COMPILED, imp.PKG_DIRECTORY - """ - if fullname.startswith('.'): - raise ImportError("Relative module names not supported") - if '.' in fullname: - # Get the containing package's __path__ - pkg = '.'.join(fullname.split('.')[:-1]) - if pkg not in sys.modules: - __import__(pkg) - path = getattr(sys.modules[pkg], '__path__', None) or [] - else: - for importer in sys.meta_path: - yield importer - path = sys.path - for item in path: - yield get_importer(item) - if '.' not in fullname: - yield ImpImporter() - -def get_loader(module_or_name): - """Get a PEP 302 "loader" object for module_or_name - - If the module or package is accessible via the normal import - mechanism, a wrapper around the relevant part of that machinery - is returned. Returns None if the module cannot be found or imported. - If the named module is not already imported, its containing package - (if any) is imported, in order to establish the package __path__. - - This function uses iter_importers(), and is thus subject to the same - limitations regarding platform-specific special import locations such - as the Windows registry. - """ - if module_or_name in sys.modules: - module_or_name = sys.modules[module_or_name] - if isinstance(module_or_name, ModuleType): - module = module_or_name - loader = getattr(module, '__loader__', None) - if loader is not None: - return loader - fullname = module.__name__ - else: - fullname = module_or_name - return find_loader(fullname) - -def find_loader(fullname): - """Find a PEP 302 "loader" object for fullname - - If fullname contains dots, path must be the containing package's __path__. - Returns None if the module cannot be found or imported. This function uses - iter_importers(), and is thus subject to the same limitations regarding - platform-specific special import locations such as the Windows registry. - """ - for importer in iter_importers(fullname): - loader = importer.find_module(fullname) - if loader is not None: - return loader - - return None - - -def extend_path(path, name): - """Extend a package's path. - - Intended use is to place the following code in a package's __init__.py: - - from pkgutil import extend_path - __path__ = extend_path(__path__, __name__) - - This will add to the package's __path__ all subdirectories of - directories on sys.path named after the package. This is useful - if one wants to distribute different parts of a single logical - package as multiple directories. - - It also looks for *.pkg files beginning where * matches the name - argument. This feature is similar to *.pth files (see site.py), - except that it doesn't special-case lines starting with 'import'. - A *.pkg file is trusted at face value: apart from checking for - duplicates, all entries found in a *.pkg file are added to the - path, regardless of whether they are exist the filesystem. (This - is a feature.) - - If the input path is not a list (as is the case for frozen - packages) it is returned unchanged. The input path is not - modified; an extended copy is returned. Items are only appended - to the copy at the end. - - It is assumed that sys.path is a sequence. Items of sys.path that - are not (unicode or 8-bit) strings referring to existing - directories are ignored. Unicode items of sys.path that cause - errors when used as filenames may cause this function to raise an - exception (in line with os.path.isdir() behavior). - """ - - if not isinstance(path, list): - # This could happen e.g. when this is called from inside a - # frozen package. Return the path unchanged in that case. - return path - - pname = os.path.join(*name.split('.')) # Reconstitute as relative path - # Just in case os.extsep != '.' - sname = os.extsep.join(name.split('.')) - sname_pkg = sname + os.extsep + "pkg" - init_py = "__init__" + os.extsep + "py" - - path = path[:] # Start with a copy of the existing path - - for dir in sys.path: - if not isinstance(dir, basestring) or not os.path.isdir(dir): - continue - subdir = os.path.join(dir, pname) - # XXX This may still add duplicate entries to path on - # case-insensitive filesystems - initfile = os.path.join(subdir, init_py) - if subdir not in path and os.path.isfile(initfile): - path.append(subdir) - # XXX Is this the right thing for subpackages like zope.app? - # It looks for a file named "zope.app.pkg" - pkgfile = os.path.join(dir, sname_pkg) - if os.path.isfile(pkgfile): - try: - f = open(pkgfile) - except IOError, msg: - sys.stderr.write("Can't open %s: %s\n" % - (pkgfile, msg)) - else: - for line in f: - line = line.rstrip('\n') - if not line or line.startswith('#'): - continue - path.append(line) # Don't check for existence! - f.close() - - return path - -def get_data(package, resource): - """Get a resource from a package. - - This is a wrapper round the PEP 302 loader get_data API. The package - argument should be the name of a package, in standard module format - (foo.bar). The resource argument should be in the form of a relative - filename, using '/' as the path separator. The parent directory name '..' - is not allowed, and nor is a rooted name (starting with a '/'). - - The function returns a binary string, which is the contents of the - specified resource. - - For packages located in the filesystem, which have already been imported, - this is the rough equivalent of - - d = os.path.dirname(sys.modules[package].__file__) - data = open(os.path.join(d, resource), 'rb').read() - - If the package cannot be located or loaded, or it uses a PEP 302 loader - which does not support get_data(), then None is returned. - """ - - loader = get_loader(package) - if loader is None or not hasattr(loader, 'get_data'): - return None - mod = sys.modules.get(package) or loader.load_module(package) - if mod is None or not hasattr(mod, '__file__'): - return None - - # Modify the resource name to be compatible with the loader.get_data - # signature - an os.path format "filename" starting with the dirname of - # the package's __file__ - parts = resource.split('/') - parts.insert(0, os.path.dirname(mod.__file__)) - resource_name = os.path.join(*parts) - return loader.get_data(resource_name) diff --git a/src/cement/cement/core/__init__.py b/src/cement/cement/core/__init__.py deleted file mode 100644 index 67bd98db..00000000 --- a/src/cement/cement/core/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -"""Cement core module, holds all core framework code.""" -__import__('pkg_resources').declare_namespace(__name__) diff --git a/src/cement/cement/core/app_setup.py b/src/cement/cement/core/app_setup.py deleted file mode 100644 index 6985422a..00000000 --- a/src/cement/cement/core/app_setup.py +++ /dev/null @@ -1,197 +0,0 @@ -"""Cement methods to setup the framework for applications using it.""" - -import sys -import logging - -from cement import namespaces -from cement import buf_stdout, buf_stderr, SAVED_STDOUT, SAVED_STDERR -from cement.core.exc import CementConfigError -from cement.core.configuration import set_config_opts_per_file -from cement.core.configuration import validate_config, get_default_config -from cement.core.plugin import load_all_plugins -from cement.core.namespace import CementNamespace, define_namespace, get_config -from cement.core.log import setup_logging, get_logger -from cement.core.hook import define_hook, run_hooks -from cement.core.handler import define_handler, register_handler -from cement.core.view import GenshiOutputHandler, JsonOutputHandler - -def define_default_hooks(): - """ - Defines Cement framework hooks. - - Hook definitions: - - options_hook - Used to add options to a namespaces options object - - post_options_hook - Run after all options have been setup and merged - - validate_config_hook - Run after config options are setup - - pre_plugins_hook - Run just before all plugins are loaded (run once) - - post_plugins_hook - Run just after all plugins are loaded (run once) - - post_bootstrap_hook - Run just after the root bootstrap is loaded. - - """ - define_hook('options_hook') - define_hook('post_options_hook') - define_hook('validate_config_hook') - define_hook('pre_plugins_hook') - define_hook('post_plugins_hook') - define_hook('post_bootstrap_hook') - -def define_default_handler_types(): - """ - Defines Cement framework handlers. - - Handler Definitions: - - output - Output handlers are responsible for rendering output as returned - from controller functions. This may be 'Genshi', 'json', 'yaml', - 'Jinja2', etc. - - """ - define_handler('output') - -def register_default_handlers(): - """ - Register the default base level handlers required to run a Cement - application. - """ - register_handler('output', 'genshi', GenshiOutputHandler) - register_handler('output', 'json', JsonOutputHandler) - -def lay_cement(config, **kw): - """ - Primary method to setup an application for Cement. - - Required Arguments: - - config - Dict containing application config. - - Optional Keyword Arguments: - - banner - Optional text to display for --version - - args - Args to use (default: sys.argv)... if passed, args overrides - sys.argv because optparse accesses sys.argv. - - clear_loggers - Defaults to 'True', whether or not to clear existing loggers. - - Usage: - - .. code-block:: python - - from cement.core.configuration import get_default_config - from cement.core.app_setup import lay_cement - - lay_cement(get_default_config()) - - """ - - args = kw.get('args', None) - banner = kw.get('banner', None) - version = kw.get('version', None) - clear_loggers = kw.get('clear_loggers', True) - - if not version: - from pkg_resources import get_distribution - version = get_distribution(config['app_egg_name']).version - - # DEPRECATED: compat with 0.8.8 - if not args and kw.get('cli_args', None): - args = kw['cli_args'] - - # a bit of a hack, but optparse and others use sys.argv - if args: - sys.argv = args - - try: - assert config, "default config required!" - except AssertionError, error: - raise CementConfigError, error.message - - if not banner: - banner = "%s version %s" % ( - config['app_name'], - version) - - namespace = CementNamespace( - label='root', - version=version, - config=get_default_config(), - banner=banner, - provider=config['app_module'] - ) - define_namespace('root', namespace) - namespaces['root'].config.update(config) - - root_mod = __import__("%s.controllers.root" % \ - namespaces['root'].config['app_module'], - globals(), locals(), ['root']) - namespaces['root'].controller = getattr(root_mod, 'RootController') - - for config_file in namespaces['root'].config['config_files']: - set_config_opts_per_file('root', 'root', config_file) - - validate_config(namespaces['root'].config) - - # hardcoded hacks - if '--quiet' in sys.argv: - namespaces['root'].config['log_to_console'] = False - sys.stdout = buf_stdout - sys.stderr = buf_stderr - if '--json' in sys.argv: - sys.stdout = buf_stdout - sys.stderr = buf_stderr - namespaces['root'].config['output_handler_override'] = 'json' - namespaces['root'].config['show_plugin_load'] = False - # debug trumps everything - if '--debug' in sys.argv: - namespaces['root'].config['debug'] = True - namespaces['root'].config['log_to_console'] = True - sys.stdout = SAVED_STDOUT - sys.stderr = SAVED_STDERR - - # Setup logging for console and file - setup_logging(to_console=namespaces['root'].config['log_to_console'], - clear_loggers=clear_loggers) - log = get_logger(__name__) - log.debug('logging initialized') - log.debug('setup app per the following configs: %s' % \ - namespaces['root'].config['config_files']) - define_default_hooks() - define_default_handler_types() - - register_default_handlers() - - __import__("%s.bootstrap" % namespaces['root'].config['app_module'], - globals(), locals(), ['root']) - - for res in run_hooks('post_bootstrap_hook'): - pass - - # load all plugins - load_all_plugins() - - # Allow plugins to add config validation for the global namespace - for res in run_hooks('validate_config_hook', - config=namespaces['root'].config): - pass - - # Merge namespaces under root dict - for nam in namespaces: - if nam != 'root': - namespaces['root'].config[nam] = get_config(nam) diff --git a/src/cement/cement/core/command.py b/src/cement/cement/core/command.py deleted file mode 100644 index 7a3a38e5..00000000 --- a/src/cement/cement/core/command.py +++ /dev/null @@ -1,74 +0,0 @@ -"""These methods and classes controller how commands are parsed and run.""" - -import re - -from cement import namespaces -from cement.core.log import get_logger -from cement.core.hook import run_hooks -from cement.core.opt import parse_options -from cement.core.controller import run_controller_command -from cement.core.exc import CementArgumentError - -log = get_logger(__name__) - -def run_command(cmd_name=None, ignore_conflicts=False): - """ - Run the command or namespace-subcommand as defined by the 'expose()' - decorator used on a Controller function. - - Keyword arguments: - - cmd_name - The command name as store in the global 'namespaces'. For - example, namespaces['root'].commands['cmd_name']. - - """ - log.debug("processing passed command '%s'", cmd_name) - - # bit of a hack... but if cmd_name starts with - then no command passed - if cmd_name.startswith('-'): - cmd_name = 'default' - - orig_cmd = cmd_name - cmd_name = re.sub('-', '_', cmd_name) - - if cmd_name in namespaces.keys(): - namespace = cmd_name - else: - namespace = 'root' - - # Parse cli options and arguments - (cli_opts, cli_args) = parse_options(namespace=namespace, - ignore_conflicts=ignore_conflicts) - - # Run all post options hooks - for res in run_hooks('post_options_hook', cli_opts, cli_args): - pass # Doesn't expect a result - - # If it isn't the root namespace, then the first arg is the namespace - # and the second is the actual command. - if namespace == 'root': - actual_cmd = cmd_name - else: - try: - actual_cmd = re.sub('-', '_', cli_args[1]) - except IndexError: - if namespaces[namespace].commands.has_key('default'): - actual_cmd = 'default' - else: - raise CementArgumentError, \ - "%s is a namespace* " % namespace + \ - "which requires a sub-command. See " + \ - "'%s --help'" % namespace - - if namespaces[namespace].commands.has_key(actual_cmd): - cmd = namespaces[namespace].commands[actual_cmd] - log.debug("executing command '%s'" % actual_cmd) - (res, out_txt) = run_controller_command(cmd['controller_namespace'], - cmd['func'], - cli_opts, cli_args) - return (res, out_txt) - else: - raise CementArgumentError, "Unknown command '%s', see --help?" % \ - actual_cmd - diff --git a/src/cement/cement/core/configuration.py b/src/cement/cement/core/configuration.py deleted file mode 100644 index 9be78f95..00000000 --- a/src/cement/cement/core/configuration.py +++ /dev/null @@ -1,229 +0,0 @@ -"""Cement methods for handling config file parsing.""" - -import os -from configobj import ConfigObj, Section - -from cement.core.exc import CementConfigError - -def get_default_config(): - """Get a default config dict.""" - dcf = ConfigObj() - dcf['config_source'] = ['defaults'] - dcf['config_files'] = [] - dcf['enabled_plugins'] = [] - dcf['debug'] = False - dcf['show_plugin_load'] = True - dcf['output_engine'] = 'genshi' # deprecated - dcf['output_handler'] = 'genshi' - dcf['output_handler_override'] = None - dcf['logging_config_file'] = None - return dcf - -def get_default_namespace_config(): - """Get a default plugin config dict.""" - dcf = ConfigObj() - dcf['config_source'] = ['defaults'] - dcf['merge_root_options'] = True - return dcf - -# global hooks dictionary -hooks = {} - -# global namespace dict -namespaces = {} - -# global handlers dict -handlers = {} - -def get_api_version(): - """Get the Cement API Version.""" - #return CEMENT_API - print "The use of CEMENT_API is deprecated as of 0.8.9." - return None - -def ensure_api_compat(module_name, required_api): - """ - Ensure the application is compatible with this version of Cement. - - Required Arguments: - - module_name - Name of the applications module. - - required_api - The Cement API version required by the application. - - """ - print "WARNING: The use of CEMENT_API is deprecated as of 0.8.9. Called from %s" % module_name - return True - -def t_f_pass(value): - """ - A quick hack for making true/false type values actually True/False in - python. - - Required arguments: - - value - The presumed 'true' or 'false' value. - - - Returns: - - boolean - True/False based on logic of the operation. - - """ - try: - if str(value.lower()) in ['true', True]: - return True - if str(value.lower()) in ['false', False]: - return False - else: - return value - except: - return value - - -def set_config_opts_per_file(namespace, section, config_file): - """ - Parse config file options for into config dict. Will do nothing if the - config file does not exist. - - Required arguments: - - namespace - The namespace to set config options for - - section - Section of the configuration file to read. - - config_file - The config file to parse. - - """ - config = namespaces[namespace].config - - if not config.has_key('config_source'): - config['config_source'] = [] - - if os.path.exists(config_file): - try: - cnf = ConfigObj(config_file) - config.update(cnf[section]) - config['config_source'].append(config_file) - except IOError, error: - # the file is not readable, so remove it from config_files - if config_file in config['config_files']: - config['config_files'].remove(config_file) - namespaces[namespace].config = config - return - except KeyError, error: - # FIX ME: can't log here... - # log.debug('missing section %s in %s.' % (section, config_file)) - return - - - # FIX ME: Is there an easier way to ensure true/false values are - # actually True/False. I think ConfigSpec, but don't have time right - # now. - # - # But since we are parsing config before our plugins load then how - # do you have a config spec for the app and plugin? UPDATE: i think - # with the new bootstrap layout a spec could be possible. - # - # Regardless... the point of this nonsense below is to ensure - # true false values equate to True/False in python. We go 3 levels - # deep into: - # - # [section] - # [[section2]] - # [[section3]] - # - sec1 = cnf[section] - for opt1 in sec1: - if not type(sec1[opt1]) == Section: - config[opt1] = t_f_pass(sec1[opt1]) - try: - if sec1[opt1].startswith('~'): - config[opt1] = os.path.expanduser(sec1[opt1]) - except AttributeError: - pass - else: - # This is another level of the same loop. If the option is - # actually a configobj.Section, we need to run the loop on - # that section. - sec2 = sec1[opt1] - for opt2 in sec2: - if not type(sec2[opt2]) == Section: - config[opt1][opt2] = t_f_pass(sec2[opt2]) - if opt2.startswith('~'): - config[opt1][opt2] = os.path.expanduser(sec2[opt2]) - else: - # This is yet another level of the same loop. Only - # willing to go 3 levels deep though. - sec3 = sec2[opt2] - for opt3 in sec3: - if not type(sec3[opt3]) == Section: - config[opt1][opt2][opt3] = t_f_pass(sec3[opt3]) - if opt3.startswith('~'): - config[opt1][opt2][opt3] = os.path.expanduser(sec3[opt3]) - - # overwrite the namespace config - namespaces[namespace].config = config - -def set_config_opts_per_cli_opts(namespace, cli_opts): - """ - Determine if any config optons were passed via cli options, and if so - override the config option. Overwrites the global - namespaces['namespace'].config dict. - - Required arguments: - - namespace - The namespace of whose config to modify. - - cli_opts - The cli_opts as parsed from OptParse. - - """ - for opt in namespaces[namespace].config: - try: - val = getattr(cli_opts, opt) - if val: - namespaces[namespace].config[opt] = val - except AttributeError: - pass - -def validate_config(config): - """ - Validate that all required cement configuration options are set. Also - creates any common directories based on config settings if they do not - exist. - - Required arguments: - - config - The config dict to validate. - - - Possible Exceptions: - - CementConfigError - Raised on invalid configuration. - - """ - required_settings = [ - 'config_source', 'config_files', 'debug', 'datadir', - 'enabled_plugins', 'plugin_config_dir', 'app_module', 'app_name', - 'tmpdir', 'output_handler' - ] - for s in required_settings: - if not config.has_key(s): - raise CementConfigError, "config['%s'] value missing!" % s - - # create all directories if missing - for d in [os.path.dirname(config['log_file']), config['datadir'], - config['plugin_config_dir'], config['tmpdir']]: - if not os.path.exists(d): - os.makedirs(d) diff --git a/src/cement/cement/core/controller.py b/src/cement/cement/core/controller.py deleted file mode 100644 index f43ce619..00000000 --- a/src/cement/cement/core/controller.py +++ /dev/null @@ -1,163 +0,0 @@ -"""Methods and classes to handle Cement Controller functions.""" - -from cement import namespaces -from cement.core.log import get_logger -from cement.core.exc import CementRuntimeError -from cement.core.view import render -from cement.core.configuration import set_config_opts_per_cli_opts - -log = get_logger(__name__) - -class CementController(object): - """Currently just a place holder for more featureful controller.""" - def __init__(self, cli_opts=None, cli_args=None): - self.cli_opts = cli_opts - self.cli_args = cli_args - - -def run_controller_command(namespace, func, cli_opts=None, cli_args=None, - *args, **kw): - """ - Cleanly run a command function from a controller. Returns a tuple of - (result_dict, output_txt). - - Arguments: - - namespace - The namespace of the controller - func - The name of the function - cli_opts - Options passed to the command line - cli_args - Arguments passed to the command line - args - Any additional arguments to pass to the function - kwargs - Any additional keyword arguments to pass to the function. - - - Usage: - - .. code-block:: python - - from cement.core.controller import run_controller_command - - run_controller_command('root', 'cmd_name', myarg=True) - - """ - - # set configurations per what is passed at cli - for nam in namespaces: - set_config_opts_per_cli_opts(nam, cli_opts) - - controller = namespaces[namespace].controller(cli_opts, cli_args) - (res, out_txt) = getattr(controller, func)(*args, **kw) - return (res, out_txt) - -class expose(object): - """ - Decorator function for plugins to expose commands. Used as: - - Arguments: - - template - A template in python module form (i.e 'myapp.templates.mytemplate') - namespace - The namespace to expose the command in. Default: root - - - Optional Keyword Arguments: - - is_hidden - True/False whether command should display on --help. - - - Usage: - - .. code-block:: python - - class MyController(CementController): - @expose('myapp.templates.mycontroller.cmd', namespace='root') - def cmd(self): - foo="Foo" - bar="Bar" - return dict(foo=foo, bar=bar) - - """ - def __init__(self, template=None, namespace='root', **kwargs): - # These get set in __call__ - self.func = None - self.name = kwargs.get('name', None) - self.template = template - self.namespace = namespace - self.tmpl_module = None - self.tmpl_file = None - self.config = namespaces['root'].config - self.is_hidden = kwargs.get('is_hidden', False) - self.desc = kwargs.get('desc', None) - - if not self.namespace in namespaces: - raise CementRuntimeError, \ - "The namespace '%s' is not defined!" % self.namespace - - # First set output_handler from config - # DEPRECATION: output_engine - self.output_handler = None - if not self.config.has_key('output_handler'): - if self.config.has_key('output_engine'): - self.output_handler = self.config['output_engine'] - else: - self.output_handler = self.config['output_handler'] - - # The override output_handler from @expose() - if self.template: - parts = template.split(':') - if len(parts) >= 2: - self.output_handler = parts[0] - self.template = parts[1] - elif len(parts) == 1: - self.template = parts[0] - else: - raise CementRuntimeError, "Invalid handler:template identifier." - - def __get__(self, obj, type=None): - if self.func: - return self.__class__(self.func.__get__(obj, type)) - else: - return self.__get__ - - def __call__(self, func): - parts = func.__module__.split('.') - - con_namespace = parts[-1] - controller = parts[-2] - base = '.'.join(parts[:-2]) - - self.func = func - if not self.name: - self.name = self.func.__name__ - - if not self.output_handler: - log.debug("no output handler configured to generate output " + \ - "for %s" % self.name) - - log.debug("exposing namespaces['%s'].commands['%s'] from '%s'" % \ - (self.namespace, self.name, self.func.__module__)) - - # First for the template - if not self.name: - self.name = self.func.__name__ - - cmd = { - 'is_hidden' : self.is_hidden, - 'original_func' : func, - 'func' : self.name, - 'controller_namespace' : con_namespace, - } - - # Set the command info in the dest namespace - namespaces[self.namespace].commands[self.name] = cmd - self.func = render(self.output_handler, self.template)(self.func) - return self.func - diff --git a/src/cement/cement/core/exc.py b/src/cement/cement/core/exc.py deleted file mode 100644 index 9800d2bf..00000000 --- a/src/cement/cement/core/exc.py +++ /dev/null @@ -1,32 +0,0 @@ -"""Cement exception classes.""" - -class CementError(Exception): - """Generic errors.""" - def __init__(self, value, code=1): - Exception.__init__(self) - self.msg = value - self.code = code - - def __str__(self): - return self.msg - - def __unicode__(self): - return unicode(self.msg) - -class CementConfigError(CementError): - """Config parsing and setup errors.""" - def __init__(self, value): - code = 1010 - CementError.__init__(self, value, code) - -class CementRuntimeError(CementError): - """Runtime errors.""" - def __init__(self, value): - code = 1020 - CementError.__init__(self, value, code) - -class CementArgumentError(CementError): - """Argument errors.""" - def __init__(self, value): - code = 1030 - CementError.__init__(self, value, code) diff --git a/src/cement/cement/core/handler.py b/src/cement/cement/core/handler.py deleted file mode 100644 index 29792d4b..00000000 --- a/src/cement/cement/core/handler.py +++ /dev/null @@ -1,94 +0,0 @@ -"""Cement Handlers configuration.""" - -from cement import handlers -from cement.core.log import get_logger -from cement.core.exc import CementRuntimeError - -log = get_logger(__name__) - -def get_handler(handler_type, handler_name): - """ - Get a handler object. - - Required Arguments: - - handler_type - The type of handler (i.e. 'output') - - handler_name - The name of the handler (i.e. 'json') - - Usage: - - from cement.core.handler import get_handler - handler = get_handler('output', 'json')(dict(foo=bar)) - handler.render() - - """ - if handler_type in handlers: - if handler_name in handlers[handler_type]: - return handlers[handler_type][handler_name] - raise CementRuntimeError, "The handler handlers[%s][%s] does not exist!" \ - % (handler_type, handler_name) - -def define_handler(handler_type): - """ - Define a handler type that plugins can register handler objects under. - - Required arguments: - - handler_type - The type of the handler, stored as handlers['handler_type'] - - - Usage: - - .. code-block:: python - - from cement.core.handler import define_handler - - define_handler('database') - - """ - log.debug("defining handler type '%s'", handler_type) - if handlers.has_key(handler_type): - raise CementRuntimeError, "Handler type '%s' already defined!" % \ - handler_type - handlers[handler_type] = {} - - -def register_handler(handler_type, name, handler_object): - """ - Register a handler object to a handler. - - Required Options: - - handler_type - The type of the handler to register - - name - The name to register the handler object as - - handler_object - The handler object to register - - Usage: - - .. code-block:: python - - from cement.core.handler import register_handler - - my_handler_object = SomeTypeOfObject() - register_handler('database', 'my_database_handler', my_handler_object) - - """ - if handler_type not in handlers: - raise CementRuntimeError, "Handler type '%s' doesn't exist." % \ - handler_type - if handlers[handler_type].has_key(name): - raise CementRuntimeError, "Handler of type '%s' and name '%s' already exists" % \ - (handler_type, name) - log.debug("registering handler '%s' from %s into handlers['%s']" % \ - (name, handler_object.__module__, handler_type)) - handlers[handler_type][name] = handler_object - \ No newline at end of file diff --git a/src/cement/cement/core/hook.py b/src/cement/cement/core/hook.py deleted file mode 100644 index c3d2b155..00000000 --- a/src/cement/cement/core/hook.py +++ /dev/null @@ -1,115 +0,0 @@ -"""Methods and classes to handle Cement Hook support.""" - -from cement import hooks -from cement.core.exc import CementRuntimeError -from cement.core.log import get_logger - -log = get_logger(__name__) - -#def clear_hooks(): -# hooks = {} - -def define_hook(name): - """ - Define a hook namespace that plugins can register hooks in. - - Required arguments: - - name - The name of the hook, stored as hooks['name'] - - - Usage: - - .. code-block:: python - - from cement.core.hook import define_hook - - define_hook('myhookname_hook') - - """ - log.debug("defining hook '%s'", name) - if hooks.has_key(name): - raise CementRuntimeError, "Hook name '%s' already defined!" % name - hooks[name] = [] - - -class register_hook(object): - """ - Decorator function for plugins to register hooks. Used as: - - Optional keyword arguments: - - weight - The weight in which to order the hook function (default: 0) - - name - The name of the hook to register too. If not passed, the __name__ - of the decorated function will be used. - - Usage: - - .. code-block:: python - - from cement.core.hook import register_hook - - @register_hook() - def my_hook(*args, **kwargs): - # do something here - res = 'Something to return' - return res - - """ - def __init__(self, weight=0, name=None): - self.weight = weight - self.name = name - - def __call__(self, func): - if not self.name: - self.name = func.__name__ - log.debug("registering hook func '%s' from %s into hooks['%s']" % \ - (func.__name__, func.__module__, self.name)) - if not hooks.has_key(self.name): - log.warn("Hook name '%s' is not defined!" % self.name) - return func - # Hooks are as follows: (weight, name, func) - hooks[self.name].append( - (int(self.weight), func.__name__, func) - ) - - -def run_hooks(name, *args, **kwargs): - """ - Run all defined hooks in the namespace. Yields the result of each hook - function run. - - Optional arguments: - - name - The name of the hook function - args - Any additional args are passed to the hook function - kwargs - Any kwargs are passed to the hook function - - - Usage: - - .. code-block:: python - - from cement.core.hook import run_hook - - for result in run_hooks('hook_name'): - # do something with result from each hook function - ... - """ - if not hooks.has_key(name): - raise CementRuntimeError, "Hook name '%s' is not defined!" % name - hooks[name].sort() # Will order based on weight - for hook in hooks[name]: - log.debug("running hook '%s' from %s" % (name, hook[2].__module__)) - res = hook[2](*args, **kwargs) - - # Results are yielded, so you must fun a for loop on it, you can not - # simply call run_hooks(). - yield res \ No newline at end of file diff --git a/src/cement/cement/core/log.py b/src/cement/cement/core/log.py deleted file mode 100644 index 247de7c9..00000000 --- a/src/cement/cement/core/log.py +++ /dev/null @@ -1,178 +0,0 @@ -"""Cement methods to setup and configuring logging.""" - -import logging - -from cement import namespaces -from cement.core.exc import CementConfigError - -def setup_logging_for_plugin_provider(provider): - """ - Setup the logging handlers for a plugin providers module name space. - - Required Arguments: - - provider - The name of the application (module) providing the shared plugin. - - """ - provider_log = logging.getLogger(provider) - cement_log = logging.getLogger('cement') - - for handler in logging.getLogger('cement').handlers: - provider_log.addHandler(handler) - provider_log.level = cement_log.level - -def setup_logging(clear_loggers=True, level=None, to_console=True): - """ - Primary Cement method to setup logging. - - Keyword arguments: - - clear_loggers - Boolean, whether to clean exiting loggers (default: True) - - level - The log level (info, warn, error, debug, fatal), (default: None) - - to_console - Boolean, whether or not to log to console - - - Usage: - - .. code-block:: python - - from cement.core.log import setup_logging - setup_logging() - - """ - - config = namespaces['root'].config - if clear_loggers: - clear_previous_loggers() - - - if config['logging_config_file']: - setup_logging_per_config(config['logging_config_file']) - else: - setup_default_logging(level, to_console) - -def clear_previous_loggers(): - """ - Clear all previous loggers that have been setup (by this, or other - applications). - """ - config = namespaces['root'].config - - # Remove any previously setup handlers from other libraries - for i in logging.getLogger().handlers: - logging.getLogger().removeHandler(i) - for i in logging.getLogger(config['app_module']).handlers: - logging.getLogger(config['app_module']).removeHandler(i) - for i in logging.getLogger('cement').handlers: - logging.getLogger('cement').removeHandler(i) - -def setup_logging_per_config(config_file_path): - """ - Setup logging using a logging fileCondfig. See: - http://docs.python.org/library/logging.html#logging.fileConfig - """ - import logging.config - from ConfigParser import NoSectionError - try: - logging.config.fileConfig(config_file_path) - except NoSectionError, e: - raise CementConfigError, \ - "Invalid logging config file %s - %s" % \ - (config_file_path, e.args[0]) - -def setup_default_logging(level, to_console): - """ - Default logging config. - - Required Arguments: - - level - The log level to use (['INFO', 'WARN', 'ERROR', 'DEBUG', 'FATAL']) - - to_console - Whether to setup console logging or not. - - """ - config = namespaces['root'].config - all_levels = ['INFO', 'WARN', 'ERROR', 'DEBUG', 'FATAL'] - - # Log level - if config.has_key('debug') and config['debug']: - level = 'DEBUG' - elif level and level.upper() in all_levels: - level = level - elif config.has_key('log_level'): - level = config['log_level'] - else: - level = 'INFO' - - app_log = logging.getLogger(config['app_module']) - cement_log = logging.getLogger('cement') - - log_level = getattr(logging, level.upper()) - app_log.setLevel(log_level) - cement_log.setLevel(log_level) - - # Console formatter - if to_console: - console = logging.StreamHandler() - if log_level == logging.DEBUG: - console.setFormatter(logging.Formatter( - "%(asctime)s (%(levelname)s) %(name)s : %(message)s")) - else: - console.setFormatter( - logging.Formatter("%(levelname)s: %(message)s") - ) - console.setLevel(log_level) - app_log.addHandler(console) - cement_log.addHandler(console) - - # File formatter - if config.has_key('log_file'): - if config.has_key('log_max_bytes'): - from logging.handlers import RotatingFileHandler - - if not config.has_key('log_max_files'): - config['log_max_files'] = 4 - - file_handler = RotatingFileHandler( - config['log_file'], maxBytes=int(config['log_max_bytes']), - backupCount=int(config['log_max_files']) - ) - else: - from logging import FileHandler - file_handler = FileHandler(config['log_file']) - - file_handler.setFormatter( - logging.Formatter("%(asctime)s (%(levelname)s) %(name)s : %(message)s") - ) - file_handler.setLevel(log_level) - app_log.addHandler(file_handler) - cement_log.addHandler(file_handler) - -def get_logger(name): - """ - Used throughout the application to get a logger opject with a namespace - of 'name' (should be passed as __name__). - - Arguments: - - name - Name of the module calling get_logger (use __name__). - - Usage: - - .. code-block:: python - - from cement.core.log import get_logger - log = get_logger(__name__) - - """ - return logging.getLogger(name) - diff --git a/src/cement/cement/core/namespace.py b/src/cement/cement/core/namespace.py deleted file mode 100644 index 4dda7697..00000000 --- a/src/cement/cement/core/namespace.py +++ /dev/null @@ -1,176 +0,0 @@ -"""Methods and classes to handle Cement namespace support.""" - -import re - -from cement import namespaces -from cement.core.log import get_logger -from cement.core.exc import CementRuntimeError -from cement.core.configuration import get_default_namespace_config, \ - set_config_opts_per_file -from cement.core.opt import init_parser - -log = get_logger(__name__) - -def get_namespace(namespace): - """ - Return the namespace object whose label is 'namespace'. - - Required Arguments: - - namespace - The label of the namespace object to return - - """ - if namespaces.has_key(namespace): - return namespaces[namespace] - else: - raise CementRuntimeError, "the namespace '%s' doesn't exist" % \ - namespace - -def get_config(namespace='root'): - """ - Get a namespace's config. Returns a ConfigObj object. - - Optional Arguments: - - namespace - The namespace to pull the config object from. Default: 'root'. - - """ - if namespaces.has_key(namespace): - return namespaces[namespace].config - else: - raise CementRuntimeError, "the namespace '%s' doesn't exist" % \ - namespace - -class CementNamespace(object): - """ - Class that handles plugins and namespaces. - - Required Arguments: - - label - Namespace label. Class is stored in the global 'namespaces' - dict as namespaces['label']. - - version - The version of the application. - - Optional Keyword Arguments: - - description - Description of the plugin/namespace (default: '') - - commands - A dict of command functions (default: {}) - - is_hidden - Boolean, whether command should display in --help output - (default: False) - - config - A configobj object (default: None). A basic default config will - be created if none is passed. For advanced configurations such - as using a configspec or what have you can be done by passing in - the configobj object. - - banner - A version banner to display for --version (default: '') - - required_api - The required Cement API the application was built on. (Deprecated - as of 0.8.9) - - """ - def __init__(self, label, **kw): - if not label == 'root': - self.version = kw.get('version', namespaces['root'].version) - self.provider = kw.get('provider', - namespaces['root'].config['app_module']) - else: - self.version = kw.get('version', None) - self.provider = kw.get('provider', None) - - try: - assert self.version, "A namespace version is required!" - assert self.provider, "A namespace provider is required!" - except AssertionError, error: - raise CementRuntimeError, error.__str__() - - self.label = label - self.description = kw.get('description', '') - self.commands = kw.get('commands', {}) - self.controller = kw.get('controller', None) - self.is_hidden = kw.get('is_hidden', False) - self.config = get_default_namespace_config() - if kw.get('config', None): - self.config.update(kw['config']) - - if kw.get('banner', None): - self.banner = kw['banner'] - else: - self.banner = "%s %s version %s" % ( - get_config()['app_name'], self.label, self.version) - - self.options = kw.get('options', init_parser(banner=self.banner)) - -def define_namespace(namespace, namespace_obj): - """ - Define a namespace for commands, options, configuration, etc. - - Required Arguments: - - namespace - Label of the namespace - namespace_obj - CementNamespace object. Stored in global 'namespaces' dict as - namespaces['namespace'] - - """ - if namespaces.has_key(namespace): - raise CementRuntimeError, \ - "Namespace '%s' already defined!" % namespace - elif re.search('-', namespace): - raise CementRuntimeError, \ - "Namespaces can not have '-', use '_' instead." - - namespaces[namespace] = namespace_obj - log.debug("namespace '%s' initialized" % namespace) - -def register_namespace(namespace_obj): - """ - Wraps up defining a namespace, as well as revealing the actual controller - object (as it is passed as a string). - - Require Arguments: - - namespace_obj - Namespace object that is fully established (and ready to be - added to the global namespaces dictionary) - - Usage: - - .. code-block:: python - - from cement.core.namespace import CementNamespace, register_namespace - - example = CementNamespace('example', controller='ExampleController') - example.config['foo'] = 'bar' - example.options.add_option('-F', '--foo', action='store', - dest='foo', default=None, help='Example Foo Option') - register_namespace(example) - - """ - define_namespace(namespace_obj.label, namespace_obj) - - # Reveal the controller object. - base = namespace_obj.provider - - mymod = __import__('%s.controllers.%s' % (base, namespace_obj.label), - globals(), locals(), [namespace_obj.controller]) - cont = getattr(mymod, namespace_obj.controller) - namespaces[namespace_obj.label].controller = cont - for _file in namespaces['root'].config['config_files']: - set_config_opts_per_file(namespace_obj.label, namespace_obj.label, - _file) - diff --git a/src/cement/cement/core/opt.py b/src/cement/cement/core/opt.py deleted file mode 100644 index 69f5b599..00000000 --- a/src/cement/cement/core/opt.py +++ /dev/null @@ -1,146 +0,0 @@ -"""Cement methods and classes to handle cli option/arg parsing.""" - -import os -import sys -import re -import optparse - -from cement import namespaces -from cement.core.log import get_logger - -log = get_logger(__name__) - - -def init_parser(banner=None): - """ - Create an OptionParser object and returns its parser member. - - Keyword arguments: - - banner - Optional version banner to display for --version - - Returns: OptionParser object. - - """ - fmt = optparse.IndentedHelpFormatter( - indent_increment=4, max_help_position=32, width=77, short_first=1 - ) - parser = optparse.OptionParser(formatter=fmt, version=banner) - return parser - - -def parse_options(namespace='root', ignore_conflicts=False): - """ - The actual method that parses the command line options and args. Also - handles all the magic that happens when you pass --help to your app. It - also handles merging root options into plugins, if the plugins config - is set to do so (merge_root_options) - - Required Arguments: - - namespace - The namespace to parse options for (defaullt: 'root') - - Returns: tuple (options, args) - - """ - - # FIX ME: This method is very messy/confusing. - - log.debug("parsing command line opts/args for '%s' namespace" % namespace) - if namespace != 'root': - if namespaces[namespace].config.has_key('merge_root_options') and \ - namespaces[namespace].config['merge_root_options']: - for opt in namespaces['root'].options._get_all_options(): - if opt.get_opt_string() == '--help': - pass - elif opt.get_opt_string() == '--version': - pass - else: - try: - namespaces[namespace].options.add_option(opt) - except optparse.OptionConflictError, error: - if not ignore_conflicts: - raise optparse.OptionConflictError, error - - cmd_txt = '' - line = ' ' - if namespaces[namespace].commands: - for cmd in namespaces[namespace].commands: - cmd_with_dashes = re.sub('_', '-', cmd) - if namespaces[namespace].commands[cmd]['is_hidden']: - pass - else: - if line == ' ': - line += '%s' % cmd_with_dashes - elif len(line) + len(cmd_with_dashes) < 75: - line += ', %s' % cmd_with_dashes - else: - cmd_txt += "%s \n" % line - line = ' %s' % cmd_with_dashes - if line != ' ': - cmd_txt += "%s\n" % line - - # Do the same thing, but with namespaces (if applicable to each namespace) - nam_txt = '' - line = ' ' - script = os.path.basename(sys.argv[0]) - if namespace == 'root': - for nam in namespaces: - nam_with_dashes = re.sub('_', '-', nam) - if nam != 'root' and namespaces[nam].commands: - if namespaces[nam].is_hidden: - pass - else: - # dirty, but have to account for namespaces with only - # hidden commands... which we don't want to show - show_namespace = False - for cmd in namespaces[nam].commands: - if not namespaces[nam].commands[cmd]['is_hidden']: - show_namespace = True - break - - if show_namespace: - if line == ' ': - line += '%s' % nam_with_dashes - elif len(line) + len(nam_with_dashes) < 75: - line += ', %s' % nam_with_dashes - else: - nam_txt += "%s \n" % line - line = ' %s' % nam_with_dashes - - if line != ' ': - nam_txt += "%s\n" % line - - if nam_txt == "": - namespaces[namespace].options.usage = """ %s [ARGS] --(OPTIONS) - -Commands: -%s -Help? try '[COMMAND]-help' OR '[NAMESPACE] --help'""" % \ - (script, cmd_txt) - - else: - namespaces[namespace].options.usage = """ %s [ARGS] --(OPTIONS) - -Commands: -%s -Namespaces (Nested SubCommands): -%s -Help? try '[COMMAND]-help' OR '[NAMESPACE] --help'""" % \ - (script, cmd_txt, nam_txt) - - else: # namespace not root - namespaces[namespace].options.usage = """ %s %s [ARGS] --(OPTIONS) - -Sub-Commands: -%s -Help? try '[SUBCOMMAND]-help'""" % \ - (script, re.sub('_', '-', namespace), cmd_txt) - - - (opts, args) = namespaces[namespace].options.parse_args() - - return (opts, args) - diff --git a/src/cement/cement/core/plugin.py b/src/cement/cement/core/plugin.py deleted file mode 100644 index f30ea672..00000000 --- a/src/cement/cement/core/plugin.py +++ /dev/null @@ -1,151 +0,0 @@ -"""Methods and classes to handle Cement plugin support.""" - -import os -import re -from configobj import ConfigObj - -from cement import namespaces -from cement.core.exc import CementConfigError, CementRuntimeError -from cement.core.log import get_logger, setup_logging_for_plugin_provider -from cement.core.hook import run_hooks -from cement.core.configuration import set_config_opts_per_file, t_f_pass -from cement.core.namespace import CementNamespace, get_config - -log = get_logger(__name__) - -def get_enabled_plugins(): - """ - Open plugin config files from plugin_config_dir and determine if they are - enabled. If so, append them to 'enabled_plugins' in the root config. - Uses the namespaces['root'].config dictionary. - - """ - config = get_config() - if config.has_key('enabled_plugins'): - enabled_plugins = config['enabled_plugins'] - else: - enabled_plugins = [] - - # determine enabled plugins - - # first from config files - for _file in config['config_files']: - try: - cnf = ConfigObj(_file) - except IOError, error: - log.warning("Unable to open config '%s': %s" % \ - (_file, error.args[1])) - continue - - for sect in cnf.sections: - if sect != 'root' and cnf[sect].has_key('enable_plugin') \ - and t_f_pass(cnf[sect]['enable_plugin']) == True \ - and not sect in enabled_plugins: - if not cnf[sect].has_key('provider'): - provider = config['app_module'] - else: - provider = cnf[sect]['provider'] - setup_logging_for_plugin_provider(provider) - plugin = "%s.plugin.%s" % (provider, sect) - if plugin not in enabled_plugins: - enabled_plugins.append(plugin) - - # Then for plugin config files - for _file in os.listdir(config['plugin_config_dir']): - path = os.path.join(config['plugin_config_dir'], _file) - if not path.endswith('.conf'): - continue - - cnf = ConfigObj(path) - for sect in cnf.sections: - if sect != 'root' and cnf[sect].has_key('enable_plugin') \ - and t_f_pass(cnf[sect]['enable_plugin']) == True \ - and not sect in enabled_plugins: - if not cnf[sect].has_key('provider'): - provider = config['app_module'] - else: - provider = cnf[sect]['provider'] - setup_logging_for_plugin_provider(provider) - plugin = "%s.plugin.%s" % (provider, sect) - if plugin not in enabled_plugins: - enabled_plugins.append(plugin) - return enabled_plugins - -def load_plugin(plugin): - """ - Load a cement plugin. - - Required arguments: - - plugin - Name of the plugin to load. Should be accessible from the module - path of 'myapp.plugin.myplugin'. - - """ - config = namespaces['root'].config - match = re.match('(.*)\.plugin\.(.*)', plugin) - if match: - provider = match.group(1) - plugin = match.group(2) - else: - provider = config['app_module'] - - log.debug("loading plugin '%s'" % plugin) - if config.has_key('show_plugin_load') and config['show_plugin_load']: - print 'loading %s plugin' % plugin - - try: - __import__(provider) - except ImportError, error: - raise CementConfigError, 'unable to load plugin provider: %s' % error - - loaded = False - try: - plugin_module = __import__('%s.bootstrap' % provider, - globals(), locals(), [plugin]) - getattr(plugin_module, plugin) - if namespaces.has_key(plugin): - loaded = True - log.debug("loaded '%s' plugin" % plugin) - except AttributeError, error: - log.debug('AttributeError => %s' % error) - - if not loaded: - raise CementRuntimeError, \ - "Plugin '%s' is not installed or is broken. Try --debug?" % plugin - - plugin_config_file = os.path.join( - namespaces['root'].config['plugin_config_dir'], '%s.conf' % plugin - ) - - set_config_opts_per_file(plugin, plugin, plugin_config_file) - for _file in namespaces['root'].config['config_files']: - set_config_opts_per_file(plugin, plugin, _file) - - -def load_all_plugins(): - """ - Attempt to load all enabled plugins. Passes the existing config and - options object to each plugin and allows them to add/update each. - - """ - for res in run_hooks('pre_plugins_hook'): - pass # No result expected - - namespaces['root'].config['enabled_plugins'] = get_enabled_plugins() - - for plugin in namespaces['root'].config['enabled_plugins']: - load_plugin(plugin) - - for (namespace, res) in run_hooks('options_hook'): - for opt in res._get_all_options(): - if opt.get_opt_string() == '--help': - pass - else: - if namespaces.has_key(namespace): - namespaces[namespace].options.add_option(opt) - else: - log.warning("namespace '%s' doesn't exist!" % namespace) - - for res in run_hooks('post_plugins_hook'): - pass # No result expected diff --git a/src/cement/cement/core/testing.py b/src/cement/cement/core/testing.py deleted file mode 100644 index cbdee39f..00000000 --- a/src/cement/cement/core/testing.py +++ /dev/null @@ -1,36 +0,0 @@ -"""Helper functions for testing applications built on Cement.""" - -import sys -import re - -from cement.core.exc import CementRuntimeError -from cement.core.command import run_command - -def simulate(args): - """ - Simulate running a command at command line. Requires args to have - the exact args set to it as would be passed at command line. - - Required arguments: - - args - The args to pass to sys.argv - - Usage: - - .. code-block:: python - - import sys - from cement.core.testing import simulate - - args = ['helloworld', 'example', 'cmd1', '--test-option'] - res = simulate(args) - - """ - if not len(sys.argv) >= 1: - raise CementRuntimeError, "args must be set properly." - - sys.argv = args - cmd = re.sub('-', '_', sys.argv[1]) - (res_dict, output_txt) = run_command(cmd_name=cmd, ignore_conflicts=True) - return (res_dict, output_txt) diff --git a/src/cement/cement/core/view.py b/src/cement/cement/core/view.py deleted file mode 100644 index 23a07dae..00000000 --- a/src/cement/cement/core/view.py +++ /dev/null @@ -1,215 +0,0 @@ -"""Methods and classes that enable Cement templating support.""" - -from cement import namespaces, SAVED_STDOUT -from cement.core.handler import get_handler -from cement.core.exc import CementRuntimeError -from cement.core.log import get_logger - -log = get_logger(__name__) - -class CementOutputHandler(object): - """ - This is the standard class for output handling. All output handlers - should subclass from here. - - Required Arguments: - - data - The dictionary returned from a controller function. - - template - The template file in module form, such as: - (myapp.templates.namespace.file) where the path to the file - is actually myapp/templates/namespace/file.txt or similar. - - """ - def __init__(self, data, template=None): - self.data = data - self.template = template - self._verify_template() - self.tmpl_content = self._parse_template() - - def _verify_template(self): - """ - Perform any operations to verify that the handler can use the given - template. Should return True if verification is successful or - raise CementRuntimeError if not. - """ - pass - - def _parse_template(self): - """ - Parse a template file and return the contents of the file. - """ - pass - - def render(self): - """ - Using the contents of the template file, or from the data dictionary - directly, render output. Will raise NotImplementedError if not - subclassed. - """ - raise NotImplementedError, "CementOutputHandler.render() must be subclassed." - -class GenshiOutputHandler(CementOutputHandler): - def __init__(self, data, template=None): - """ - Render output from Genshi template text. In general, this function - should not be called directly, as it is called from render(). - - Required Arguments: - - data - The dictionary returned from a controller function. - - template - The template file in module form, such as: - (myapp.templates.namespace.file) where the path to the file - is actually myapp/templates/namespace/file.txt or similar. - - """ - self.tmpl_file = None - self.tmpl_module = None - CementOutputHandler.__init__(self, data, template) - - def _parse_template(self): - if self.template: - try: - from pkgutil import get_data - except ImportError: - # backported for < 2.6 compat - from cement.backports.pkgutil import get_data - # Mock up the template path - parts = self.template.split('.') - self.tmpl_file = "%s.txt" % parts.pop() # the last item is the file - self.tmpl_module = '.'.join(parts) # left over in between - self.tmpl_content = get_data(self.tmpl_module, self.tmpl_file) - return self.tmpl_content - - def render(self): - log.debug("rendering genshi output") - from genshi.template import NewTextTemplate - if self.tmpl_content: - tmpl = NewTextTemplate(self.tmpl_content) - res = tmpl.generate(**self.data).render() - return res - else: - log.debug('template content is empty.') - return '' - -class JsonOutputHandler(CementOutputHandler): - """ - Render output into JSON from the controller data dictionary. The - template param is ignored. - - Required Arguments: - - data - The dictionary returned from a controller function. - - template - Ignored by this handler - - Usage: - - .. code-block:: python - - from cement.core.handler import get_handler - - fake_dict = dict(foo='String', bar=100, list=[1,2,3,4,5]) - handler = get_handler('output', 'json')(fake_dict) - output = handler.render() - - """ - - def render(self): - log.debug("rendering json output") - import jsonpickle - from cement import buf_stdout, buf_stderr - - self.data['stdout'] = buf_stdout.buffer - self.data['stderr'] = buf_stderr.buffer - return jsonpickle.encode(self.data, unpicklable=False) - -class render(object): - """ - Class decorator to render data with the specified output handler. - Called when the function is decorated, sets up the engine and template for - later use. - - *Note: This is called from the cement.core.controller.expose() decorator - and likely shouldn't ever be needed to call directly.* - - *Note: If 'output_file' is passed in the return dictionary from func, then - the output is written to the specified file rather than STDOUT.* - - Keywork arguments: - - output_handler - The name of the output handler to use for rendering - - template - The module path to the template (default: None) - - - When called, a tuple is returned consisting of (dict, output), meaning - the first item is the result dictionary as returned by the original - function, and the second is the output as rendered by the output handler. - - """ - def __init__(self, output_handler, template=None): - self.func = None - self.template = template - self.tmpl_module = None - self.tmpl_file = None - self.config = namespaces['root'].config - self.handler = output_handler - - def __call__(self, func): - """ - Called when the command function is actually run. Expects a - dictionary in return from the function decorated in __init__. - - """ - self.func = func - - def wrapper(*args, **kw): - # honor output_handler_override - if self.config['output_handler_override']: - self.handler = self.config['output_handler_override'] - - log.debug("decorating '%s' with '%s:%s'" % \ - (func.__name__, self.handler, self.template)) - - res = self.func(*args, **kw) - - out = SAVED_STDOUT - tmpl_content = None - - if not res: - res = dict() - if type(res) != dict: - raise CementRuntimeError, \ - "Controller functions must return type dict()." - - if self.handler: - h = get_handler('output', self.handler)(res, self.template) - namespaces['root'].config['output_handler'] = self.handler - out_txt = h.render() - - if not out_txt: - out_txt = '' - - if res.has_key('output_file') and res['output_file']: - f = open(res['output_file'], 'w+') - f.write(out_txt) - f.close() - elif out and self.config['log_to_console']: - out.write(out_txt) - - # return res and out_txt, because we want it to be - # readable when called directly from - # run_controller_command() - return (res, out_txt) - - return wrapper diff --git a/src/cement/setup.py b/src/cement/setup.py deleted file mode 100644 index 69e63e58..00000000 --- a/src/cement/setup.py +++ /dev/null @@ -1,74 +0,0 @@ -from setuptools import setup, find_packages -import sys, os - -VERSION = '0.8.16' - -LONG = """ -Cement is an advanced CLI Application Framework for Python. This package -provides the core framework required to run an application built on top of -Cement. Note that this is only part of 'cement' as a whole. The entire -source is available from: - - http://builtoncement.org/cement/0.8/download/ - - -The Cement CLI Application Framework is Open Source and is distributed under -The MIT License. - - -MORE INFORMATION: - -All documentation is available from the official website: - - http://builtoncement.org - - -GETTING STARTED: - -Stable versions can be installed via the cheeze shop: -:: - $ easy_install cement - - -Development versions can be checked out of Git: -:: - $ git clone git://github.com/derks/cement.git - - $ cd cement/src/cement/ - - $ python setup.py install - - -For development, and actually building applications on Cement, please see the -cement.devtools package. - -""" - - -setup(name='cement', - version=VERSION, - description="CLI Application Framework for Python", - long_description=LONG, - classifiers=[], - keywords='cli framework', - author='BJ Dierkes', - author_email='wdierkes@5dollarwhitebox.org', - url='http://builtoncement.org', - license='MIT', - packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), - include_package_data=True, - zip_safe=False, - install_requires=[ - "ConfigObj", - "jsonpickle", - "Genshi", - # Required for documentation - #"Sphinx >= 1.0", - #"Pygments", - ], - setup_requires=[ - ], - entry_points=""" - """, - namespace_packages=[], - )