changeset 20:caf763fc1c7d

front end more servers
author Jeff Hammel <k0scist@gmail.com>
date Thu, 06 Mar 2014 22:52:25 -0800
parents 4d9a2a2fb8c0
children 3621afe99a72
files setup.py wsgintegrate/factory.py wsgintegrate/main.py wsgintegrate/server.py
diffstat 4 files changed, 30 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Sat Mar 09 23:03:48 2013 -0800
+++ b/setup.py	Thu Mar 06 22:52:25 2014 -0800
@@ -1,7 +1,7 @@
-from setuptools import setup, find_packages
+from setuptools import setup
 import os
 
-version = '0.1.1'
+version = '0.1.2'
 
 # description
 try:
@@ -10,12 +10,7 @@
 except:
   description = ''
 
-# dependencies
 dependencies = ['webob']
-try:
-  import json
-except ImportError:
-  dependencies.append('simplejson')
 
 setup(name='wsgintegrate',
       version=version,
@@ -24,7 +19,7 @@
       classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
       keywords='',
       author='Jeff Hammel',
-      author_email='jhammel@mozilla.com',
+      author_email='k0scist@gmail.com',
       url='http://k0s.org/',
       license='GPL',
       packages=['wsgintegrate'],
--- a/wsgintegrate/factory.py	Sat Mar 09 23:03:48 2013 -0800
+++ b/wsgintegrate/factory.py	Thu Mar 06 22:52:25 2014 -0800
@@ -25,7 +25,6 @@
             except Exception, e:
                 print >> sys.stderr, "Error reading '%s': %s" % (self.inifile, e)
             self.mtime = mtime
-        
+
         app = self.load(self.main)
         return app(environ, start_response)
-    
--- a/wsgintegrate/main.py	Sat Mar 09 23:03:48 2013 -0800
+++ b/wsgintegrate/main.py	Thu Mar 06 22:52:25 2014 -0800
@@ -1,20 +1,18 @@
 #!/usr/bin/env python
 
 """
-command line entry point for wsgintegrate
+command line interface for wsgintegrate.
 serves an application from a .ini file
 (really, a DAG)
-
-uses wsgiref, though could in theory make use of
-other WSGI servers, if available (TODO)
 """
 
 import sys
 from factory import WSGIfactory
 from optparse import OptionParser
-from server import wsgiref
+from server import servers
 
 def main(args=sys.argv[1:]):
+    """CLI"""
 
     # parse command line options
     usage = '%prog [options] config-file'
@@ -33,6 +31,10 @@
     parser.add_option('--print-ini', dest='print_ini',
                       action='store_true', default=False,
                       help='print .ini format of the configuration')
+    if len(servers) > 1:
+        parser.add_option('-s', '--server', dest='server',
+                          choices=servers.keys(), default='wsgiref',
+                          help="which WSGI server to use [Choices: {}]".format(', '.join(servers.keys())))
     options, args = parser.parse_args(args)
 
     # check for single configuration file
@@ -58,8 +60,11 @@
         return
 
     # serve it
-    print 'http://localhost:%d/' % options.port
-    wsgiref(app=factory.load(), port=options.port)
+    server_name = getattr(options, 'server', 'wsgiref')
+    print ("Serving with {}".format(server_name))
+    server = servers[server_name]
+    print ('http://localhost:%d/' % options.port)
+    server(app=factory.load(), port=options.port)
 
 if __name__ == '__main__':
   main()
--- a/wsgintegrate/server.py	Sat Mar 09 23:03:48 2013 -0800
+++ b/wsgintegrate/server.py	Thu Mar 06 22:52:25 2014 -0800
@@ -4,10 +4,24 @@
 
 from factory import WSGIfactory
 
+__all__ = ['wsgiref', 'servers', 'paster']
+
 def wsgiref(app, host='0.0.0.0', port=80):
   from wsgiref import simple_server
   server = simple_server.make_server(host=host, port=int(port), app=app)
   server.serve_forever()
 
+servers = {'wsgiref': wsgiref}
+
+try:
+  from paste import httpserver
+  def paste_server(app, host='0.0.0.0', port=80):
+    httpserver.serve(app, host=host, port=port)
+  servers['paste'] = paste_server
+except ImportError:
+  print ("Not adding paste.httpserver; not installed")
+
 def paster(global_conf, **kw):
+  """factory for paster"""
   return WSGIfactory(**kw)
+