Commits

Anonymous committed 0d000af Draft Merge

v0.1.1

Comments (0)

Files changed (5)

 import cmd
 import optparse
 import bucho
+import pkg_resources
 
 description = '''
 Actions are commands like "show", "latest_status" and "all_status".
                 help='prompt string',
                 dest='prompt',
                 action='store', default=(programname+">"))
+        parser.add_option('--plugin',
+                help='command plugin',
+                dest='plugin',
+                action='store')
 
         self.options, self.args = parser.parse_args()
 
     def __init__(self, options):
         self.options = options
         self.prompt = self.options.prompt + ' '
+        if getattr(self.options, 'plugin'):
+            cls = self.__class__
+            dist = self.options.plugin
+            for name, entry_point in pkg_resources.get_entry_map(dist, 'bucho.commands').iteritems():
+                setattr(cls, "do_" + name, makeplugincmd(name, entry_point.load()))
+                
+
         cmd.Cmd.__init__(self)
 
     def do_quit(self, arg):
         return 1
 
+def makeplugincmd(n, func):
+    def f(self, arg):
+        t = func()
+        t = t.encode(bucho_encoding, 'replace')
+        t = t.decode(bucho_encoding, 'replace')
+        print(t)
+        return 0
+    return f
+def makecmd(n):
+    def f(self, arg):
+        t = getattr(bucho, n)()
+        t = t.encode(bucho_encoding, 'replace')
+        t = t.decode(bucho_encoding, 'replace')
+        print(t)
+        return 0
+    return f
+
 for name in ['show', 'latest_status', 'all_status', 'torumemo']:
-    def makecmd(n):
-        def f(self, arg):
-            t = getattr(bucho, n)()
-            t = t.encode(bucho_encoding, 'replace')
-            t = t.decode(bucho_encoding, 'replace')
-            print(t)
-            return 0
-        return f
     setattr(BuchoCmd, "do_" + name, makecmd(name))
 
 
+def sample():
+    """ sample plugin command
+    """
+    return "sample"
+import unittest
+
+class TestIt(unittest.TestCase):
+    def _getAUT(self):
+        from bucho.wsgi import application
+        return application
+
+    def test_show(self):
+        app = self._getAUT()
+        response = {}
+        def start_response(status, headers):
+            response['status'] = status
+            response['headers'] = headers
+            
+        environ = {'PATH_INFO': '/show'}
+        info = app(environ, start_response)
+        self.assertEqual(response['status'], '200 OK')
+
+    def test_not_found(self):
+        app = self._getAUT()
+        response = {}
+        def start_response(status, headers):
+            response['status'] = status
+            response['headers'] = headers
+            
+        environ = {'PATH_INFO': '/nothing'}
+        info = app(environ, start_response)
+        self.assertEqual(response['status'], '404 Not Found')
 import setuptools
 import sys
 
-version = '0.1.0'
+version = '0.1.1'
 name = 'bucho'
 short_description = '`bucho` is a package for exercises.'
 long_description = """\
 
   $ easy_install bucho
 
+Plugin
+~~~~~~~
+
+pugin entry point is ``bucho.commands``.
+
+
 History
 -------
 
+0.1.1 (2011-06-17)
+~~~~~~~~~~~~~~~~~~
+
+- bucho becomes pluggable
+
 0.1.0 (2011-05-01)
 ~~~~~~~~~~~~~~~~~~
 
         'paste.app_factory': [
             'main=bucho.wsgi:app_factory',
         ],
+        'bucho.commands': [
+            'sample=bucho.plugins:sample',
+        ],
     },
+    test_suite="bucho",
     **extra
     )
 
+[tox]
+envlist = py26,py27,py32
+
+[testenv]
+commands=
+   python setup.py test