Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding missing files

  • Loading branch information...
commit d1af4b61d16cf7d4cbd7be0cb9e1372ca2efb69d 1 parent cfc4f4e
authored January 06, 2010
5  .gitignore
... ...
@@ -1,6 +1,9 @@
1 1
 *.pyc
2  
-*egg-info
  2
+*egg*
3 3
 env/
  4
+var/
  5
+log/
  6
+tmp/
4 7
 examples/CementExample/cement_example.log
5 8
 examples/CementExample/var
6 9
 build
1  cement/paste/templates/cementapp/+package+/plugins/+package+_core/__init__.py
... ...
@@ -0,0 +1 @@
  1
+__import__('pkg_resources').declare_namespace(__name__)
32  cement/paste/templates/cementapp/+package+/plugins/+package+_core/pluginmain.py_tmpl
... ...
@@ -0,0 +1,32 @@
  1
+"""This is the core plugin for {{package}}."""
  2
+
  3
+import sys, os
  4
+
  5
+from cement import namespaces
  6
+from cement.core.log import get_logger
  7
+from cement.core.opt import init_parser
  8
+from cement.core.hook import define_hook, register_hook
  9
+from cement.core.command import CementCommand, register_command
  10
+from cement.core.plugin import CementPlugin, register_plugin
  11
+
  12
+log = get_logger(__name__)
  13
+
  14
+VERSION = '0.1'
  15
+REQUIRED_CEMENT_ABI = '{{cement_abi}}'
  16
+
  17
+# Optional: Allows you to customize the output of --version
  18
+BANNER = """
  19
+{{package}}.plugins.{{package}}_core v%s 
  20
+""" % (VERSION)
  21
+        
  22
+@register_plugin() 
  23
+class {{package}}Plugin(CementPlugin):
  24
+    def __init__(self):
  25
+        CementPlugin.__init__(self,
  26
+            label = '{{package}}',
  27
+            version = VERSION,
  28
+            description = 'Core plugin for {{package}}',
  29
+            required_abi = REQUIRED_CEMENT_ABI,
  30
+            version_banner = BANNER,
  31
+            )
  32
+
1  cement/paste/templates/cementapp/+package+/plugins/example/__init__.py
... ...
@@ -0,0 +1 @@
  1
+__import__('pkg_resources').declare_namespace(__name__)
167  cement/paste/templates/cementapp/+package+/plugins/example/example.py_tmpl
... ...
@@ -0,0 +1,167 @@
  1
+"""This is an example plugin for {{package}}."""
  2
+
  3
+"""
  4
+This is a simple plugin to add some basic functionality.
  5
+"""
  6
+
  7
+import sys, os
  8
+from pkg_resources import get_distribution
  9
+import logging
  10
+
  11
+from cement import namespaces
  12
+from cement.core.log import get_logger
  13
+from cement.core.opt import init_parser
  14
+from cement.core.hook import define_hook, register_hook
  15
+from cement.core.command import CementCommand, register_command
  16
+from cement.core.plugin import CementPlugin, register_plugin
  17
+
  18
+log = get_logger(__name__)
  19
+
  20
+VERSION = '0.1'
  21
+REQUIRED_CEMENT_ABI = '{{cement_abi}}'
  22
+
  23
+# Optional: Allows you to customize the output of --version
  24
+BANNER = """
  25
+{{package}}.plugins.example v%s 
  26
+""" % (VERSION)
  27
+ 
  28
+        
  29
+@register_plugin() 
  30
+class ExamplePlugin(CementPlugin):
  31
+    def __init__(self):
  32
+        CementPlugin.__init__(self,
  33
+            label = 'example',
  34
+            version = VERSION,
  35
+            description = 'Example plugin for {{package}}',
  36
+            required_abi = REQUIRED_CEMENT_ABI,
  37
+            version_banner=BANNER,
  38
+            )
  39
+        
  40
+        # plugin configurations can be setup this way
  41
+        self.config['example_option'] = False
  42
+        
  43
+        # plugin cli options can be setup this way.  Generally, cli options
  44
+        # are used to set config options... so if you probably want to
  45
+        # add your options to both.
  46
+        self.options.add_option('-E', '--example', action='store',
  47
+            dest='example_option', default=None, help='Example Plugin Option'
  48
+            )
  49
+            
  50
+        
  51
+@register_hook()
  52
+def options_hook(*args, **kwargs):
  53
+    """
  54
+    Use this hook to add options to other namespaces.  An OptParse object is 
  55
+    expected on return, and any options will be merged into the global options.  
  56
+    Global options can also be used as local options by setting the config 
  57
+    option 'merge_global_options = true' in the plugin config.
  58
+    """
  59
+    global_options = init_parser()
  60
+    global_options.add_option('-G', '--global-option', action ='store_true', 
  61
+        dest='global_option', default=None, help='Example Global option'
  62
+    ) 
  63
+    
  64
+    # return the namespace and the global options to add.
  65
+    return ('global', global_options)
  66
+
  67
+@register_hook()
  68
+def options_hook(*args, **kwargs):
  69
+    """
  70
+    We can also use the options hook to tie into other plugins, or even our
  71
+    own.  This is an alternateway of adding options for your [or other] 
  72
+    plugins.
  73
+    """
  74
+    my_options = init_parser()
  75
+    my_options.add_option('--new-local', action ='store', 
  76
+        dest='newlocal_option', default=None, help='Example Local option'
  77
+    ) 
  78
+    
  79
+    # return the namespace and the global options to add.
  80
+    return ('example', my_options)
  81
+
  82
+
  83
+@register_hook()
  84
+def post_options_hook(*args, **kwargs):
  85
+    """
  86
+    Use this hook if any operations need to be performed if a global
  87
+    option is passed.  Notice that we set a global option of -G in our
  88
+    global_options_hook above.  Here we can access that value from the 
  89
+    global namespace configuration.
  90
+    """
  91
+    cnf = namespaces['global'].config 
  92
+    if cnf.has_key('global_option'):
  93
+        print "global_option => %s", cnf['global_option']  
  94
+        # then do something with it  
  95
+        
  96
+
  97
+@register_command(name='ex1', namespace='example')
  98
+class ex1Command(CementCommand):
  99
+    """
  100
+    This is how to add a local/plugin subcommand because it will be  
  101
+    under the 'example' namespace.  You would access this subcommand as:
  102
+    
  103
+        $ myapp example ex1
  104
+        
  105
+    """
  106
+    def run(self):
  107
+        print "This is Example1Command.run()"
  108
+        
  109
+    def help(self):
  110
+        print "This is Example1Command.help()"        
  111
+                
  112
+        
  113
+@register_command(name='ex2', namespace='global')
  114
+class ex2Command(CementCommand):
  115
+    def run(self):
  116
+        """
  117
+        This is an example global command.  See --help.  When commands are
  118
+        called, they are passed the cli options and args passed after it.
  119
+        These are then forwarded onto the command class where they can be 
  120
+        called as self.cli_args, and self.cli_opts.
  121
+        
  122
+        Notice that you can specify the namespace via the decorator parameters.
  123
+        If a plugin has any non-global commands they are grouped under a 
  124
+        single command to the base cli application.  For example, you will 
  125
+        see global commands and namespaces* when you execute:
  126
+        
  127
+            myapp --help
  128
+            
  129
+            
  130
+        For example, if 'myplugin' has local commands, you will
  131
+        see 'myplugin*' show up in the global commands list, and then the 
  132
+        plugin subcommands will be seen under:
  133
+        
  134
+            myapp myplugin --help
  135
+            
  136
+        
  137
+        This is done to give different options in how your application works.
  138
+        """
  139
+        print "This is Example2Command.run()."
  140
+        
  141
+        # you can then see if options where passed:
  142
+        if self.cli_opts.global_option:
  143
+            print "You passed --global-options!"
  144
+            
  145
+    def help(self):
  146
+        """
  147
+        All commands have a hidden -help option as well.  Here you can 
  148
+        provide examples or other helpful information.
  149
+        """
  150
+        print "This is Example2Command.help()"
  151
+
  152
+
  153
+@register_command(name='ex3', namespace='{{package}}_core')
  154
+class ex3Command(CementCommand):
  155
+    """
  156
+    This is how to add a local/plugin subcommand to another namespace.  It
  157
+    is possible to use this in conjunction with the options_hook() to add 
  158
+    additional functionality to a completely other namespace:
  159
+    
  160
+        $ myapp {{package}} ex3
  161
+        
  162
+    """
  163
+    def run(self):
  164
+        print "This is Example3Command.run()"
  165
+        
  166
+    def help(self):
  167
+        print "This is Example3Command.help()"        
1  cement/paste/templates/cementplugin/+project+/plugins/+plugin+/__init__.py
... ...
@@ -0,0 +1 @@
  1
+__import__('pkg_resources').declare_namespace(__name__)
70  cement/paste/templates/cementplugin/+project+/plugins/+plugin+/pluginmain.py_tmpl
... ...
@@ -0,0 +1,70 @@
  1
+"""
  2
+{{plugin}} for the {{project}} application.
  3
+"""
  4
+
  5
+import os
  6
+
  7
+from cement import namespaces
  8
+from cement.core.log import get_logger
  9
+from cement.core.opt import init_parser
  10
+from cement.core.hook import define_hook, register_hook
  11
+from cement.core.command import CementCommand, register_command
  12
+from cement.core.plugin import CementPlugin, register_plugin
  13
+
  14
+log = get_logger(__name__)
  15
+
  16
+VERSION = '0.1'
  17
+REQUIRED_CEMENT_ABI = '{{cement_abi}}'
  18
+BANNER = """
  19
+{{plugin}} v%s (abi:%s)
  20
+""" % (VERSION, REQUIRED_CEMENT_ABI)
  21
+ 
  22
+@register_plugin() 
  23
+class {{plugin}}Plugin(CementPlugin):
  24
+    def __init__(self):
  25
+        CementPlugin.__init__(self,
  26
+            label = '{{plugin}}',
  27
+            version = VERSION,
  28
+            description = '{{plugin}} plugin for {{project}}',
  29
+            required_abi = REQUIRED_CEMENT_ABI,
  30
+            version_banner=BANNER
  31
+            )
  32
+      
  33
+@register_hook()
  34
+def options_hook(*args, **kwargs):
  35
+    """
  36
+    Register global options.
  37
+    """
  38
+    global_options = init_parser()
  39
+    global_options.add_option('--{{plugin}}-global-option', action ='store_true', 
  40
+        dest='{{plugin}}_global_option', default=None, help='example global option'
  41
+    ) 
  42
+    return ('global', global_options)
  43
+          
  44
+@register_hook()
  45
+def post_options_hook(cli_opts, cli_args, **kwargs):
  46
+    """Handle global options here."""
  47
+    pass
  48
+          
  49
+@register_command(name='{{plugin}}-command', namespace='global')              
  50
+class {{plugin}}Command(CementCommand):
  51
+    """
  52
+    Register global commands.
  53
+    """
  54
+    def run(self):
  55
+        print "{{plugin}} global command run() method."
  56
+                
  57
+    def help(self):
  58
+        print "{{plugin}} global command help() method."
  59
+
  60
+
  61
+@register_command(name='{{plugin}}-sub-command', namespace='{{plugin}}')              
  62
+class {{plugin}}LocalCommand(CementCommand):
  63
+    """
  64
+    Register local commands.
  65
+    """
  66
+    def run(self):
  67
+        print "{{plugin}} local command run() method."
  68
+                
  69
+    def help(self):
  70
+        print "{{plugin}} local command help() method."

0 notes on commit d1af4b6

Please sign in to comment.
Something went wrong with that request. Please try again.