Commits

Thomas Lotze committed 0edeb21

simplified the example server configuration

have the development buildout create a separate config file for the example site

  • Participants
  • Parent commits 72d72b0
  • Branches wsgi-only

Comments (0)

Files changed (6)

 
 - Dropped the ``ophelia-dump`` script which has never been really useful.
 
+- Simplified the ``ophelia-wsgiref`` example server so that it no longer reads
+  a particular section of its configuration file; have Ophelia's development
+  buildout create a separate configuration file for the included example site.
+
 - Re-organised tests, added programmatic tests for the WSGI interface.
 
 - Use Python's own ``doctest`` module for tests, got rid of using
 [buildout]
 extends = versions/versions.cfg
 develop = .
-parts = ophelia test sphinx
+parts =
+    ophelia
+    test
+    sphinx
+    example-wsgiref-cfg
 unzip = true
 
 [ophelia]
 eggs = ophelia
        tl.eggdeps
 interpreter = py
-arguments = config_file="${buildout:directory}/.installed.cfg",
-            section="ophelia"
-template-root = ${buildout:directory}/example/ophelia_pages
-document-root = ${buildout:directory}/example/static
-site = http://${ophelia:host}:${ophelia:port}/
 
 [test]
 recipe = zc.recipe.testrunner
 scripts = sphinx-build
 arguments = argv=sys.argv+("-E -c doc/ -d build/sphinx/doctrees"
                            " . build/sphinx/html/").split()
+
+[example-config]
+example_dir = ${buildout:directory}/example
+host = localhost
+port = 2080
+
+[example-wsgiref-cfg]
+recipe = collective.recipe.template
+input = ${:example_dir}/wsgiref.cfg.in
+output = ${buildout:parts-directory}/example/wsgiref.cfg
+<= example-config

example/wsgiref.cfg.in

+[DEFAULT]
+host = ${host}
+port = ${port}
+template_root = ${example_dir}/ophelia_pages
+document_root = ${example_dir}/static
+site = http://${host}:${port}/

ophelia/CONFIGURATION.txt

 Example configuration for the included WSGI server
 ==================================================
 
-Create a configuration file, say, opheliasite.cfg::
+First of all, note that the wsgiref-based server may be usable for development
+but certainly not for production. Therefore, its configuration mechanism is
+rather simplistic. Create a configuration file, say, ``wsgiref.cfg``,
+containing one section named "DEFAULT" that holds all the settings::
 
     [DEFAULT]
     host = 127.0.0.1
     port = 8080
-    template_root = /var/example/opheliasite
+    template_root = /var/example/templates
     site = http://localhost:8080/
 
 and run the ophelia-wsgiref script on that file::
 
-    ophelia-wsgiref -c opheliasite.cfg
-
-You may want to wrap this call in a run-control script.
+    $ ophelia-wsgiref wsgiref.cfg
 
 
 .. Local Variables:
 this application.
 """
 
+import ConfigParser
 import ophelia.request
 import os.path
 import sys
+import wsgiref.simple_server
 import xsendfile
 import zope.exceptions.exceptionformatter
 
         """.replace(" ", "")
 
 
-def wsgiref_server(config_file="", section="DEFAULT"):
-    import optparse
-    import ConfigParser
-    import wsgiref.simple_server
 
-    oparser = optparse.OptionParser()
-    oparser.add_option("-c", dest="config_file", default=config_file)
-    oparser.add_option("-s", dest="section", default=section)
-    cmd_options, args = oparser.parse_args()
+def wsgiref_server():
+    config_file = sys.argv[1]
 
     config = ConfigParser.ConfigParser()
-    config.read(cmd_options.config_file)
+    config.read(config_file)
     options = dict((key.replace('-', '_'), value)
-                   for key, value in config.items(cmd_options.section))
+                   for key, value in config.items('DEFAULT'))
 
     app = Application()
 

versions/versions.cfg

 [versions]
 Sphinx = ${:sphinx}
 WebOb = 1.2.3
+collective.recipe.template = 1.9
 distribute = 0.6.32
 pkginfo = 0.9.1
 repoze.sphinx.autointerface = 0.7.1