changeset 3:05683af3240c

fix up main.py
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 13 Jun 2011 17:55:34 -0700
parents 70fa0bda7726
children 2b44d878d46f
files wsgintegrate/factory.py wsgintegrate/main.py
diffstat 2 files changed, 45 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/wsgintegrate/factory.py	Mon Jun 13 07:35:03 2011 -0700
+++ b/wsgintegrate/factory.py	Mon Jun 13 17:55:34 2011 -0700
@@ -8,4 +8,6 @@
 class WSGIfactory(IniFactory):
     def __call__(self, environ, start_response):
         """WSGI"""
-
+        app = self.load(self.main)
+        return app(environ, start_response)
+    
--- a/wsgintegrate/main.py	Mon Jun 13 07:35:03 2011 -0700
+++ b/wsgintegrate/main.py	Mon Jun 13 17:55:34 2011 -0700
@@ -1,60 +1,60 @@
 #!/usr/bin/env python
 
 """
-command line entry point for wsgiblob
-serves an application from a .ini file using the [server]
-section specified or wsgiref otherwise
+command line entry point for wsgintegrate
+serves an application from a .ini file 
 """
 
 import sys
-from pyloader.factory import IniFactory
+from factory import WSGIfactory
 from optparse import OptionParser
 from server import wsgiref
 
 def main(args=sys.argv[1:]):
 
-  # parse command line options
-  usage = '%prog [options] config-file'
-  parser = OptionParser(usage=usage, description=__doc__)
-  parser.add_option('-a', '--app', dest='app', default='',
-                    help='which app to serve from the configuration')
-  parser.add_option('-p', '--port', dest='port',
-                    type='int', default=80,
-                    help='which port to serve on, if server not specified in configuration')
-  parser.add_option('--list-apps', dest='list_apps',
-                    action='store_true', default=False,
-                    help='list the WSGI apps available in the configuration')
-  parser.add_option('--print-json', dest='print_json',
-                    action='store_true', default=False,
-                    help='print JSON format of the configuration')
-  parser.add_option('--print-ini', dest='print_ini',
-                    action='store_true', default=False,
-                    help='print .ini format of the configuration')
-  options, args = parser.parse_args(args)
+    # parse command line options
+    usage = '%prog [options] config-file'
+    parser = OptionParser(usage=usage, description=__doc__)
+    parser.add_option('-a', '--app', dest='app', default='',
+                      help='which app to serve from the configuration')
+    parser.add_option('-p', '--port', dest='port',
+                      type='int', default=80,
+                      help='which port to serve on, if server not specified in configuration')
+    parser.add_option('--list-apps', dest='list_apps',
+                      action='store_true', default=False,
+                      help='list the WSGI apps available in the configuration')
+    parser.add_option('--print-json', dest='print_json',
+                      action='store_true', default=False,
+                      help='print JSON format of the configuration')
+    parser.add_option('--print-ini', dest='print_ini',
+                      action='store_true', default=False,
+                      help='print .ini format of the configuration')
+    options, args = parser.parse_args(args)
 
-  # check for single configuration file
-  if len(args) != 1: # TODO: could munge multiple configs
-    parser.print_usage()
-    parser.exit()
-  config = args[0]
+    # check for single configuration file
+    if len(args) != 1: # TODO: could munge multiple configs
+        parser.print_usage()
+        parser.exit()
+    config = args[0]
 
-  # create a factory from configuration
-  # TODO: interpret if the configuration is .ini, JSON, etc
-  factory = IniFactory(config, main=options.app)
+    # create a factory from configuration
+    # TODO: interpret if the configuration is .ini, JSON, etc
+    factory = IniFactory(config, main=options.app)
 
-  # print configuration, if specified
-  if options.list_apps:
-    for app in sorted(factory.config.keys()):
-      print app
-    return
-  if options.print_json:
-    print factory.json_config()
-    return
-  if options.print_ini:
-    print factory.ini_config()
-    return
+    # print configuration, if specified
+    if options.list_apps:
+        for app in sorted(factory.config.keys()):
+            print app
+        return
+    if options.print_json:
+        print factory.json_config()
+        return
+    if options.print_ini:
+        print factory.ini_config()
+        return
 
-  wsgiref(app=factory.load(), port=options.port)
+    # serve it
+    wsgiref(app=factory.load(), port=options.port)
 
 if __name__ == '__main__':
   main()