Commit 04ab51de authored by Hanno Schlichting's avatar Hanno Schlichting

Simplify ZopeWSGIOptions and drop dependency on zdaemon.

parent 95d7a661
......@@ -67,7 +67,6 @@ setup(
'setuptools',
'transaction',
'waitress',
'zdaemon',
'zExceptions >= 3.2',
'zope.browser',
'zope.browsermenu',
......
......@@ -15,9 +15,8 @@
import os
import xml.sax
from ZConfig.loader import SchemaLoader
from ZConfig.loader import ConfigLoader, SchemaLoader
from ZConfig.schema import SchemaParser
from zdaemon.zdoptions import ZDOptions
from zope.deferredimport import deprecated
# BBB Zope 5.0
......@@ -48,13 +47,19 @@ class ConditionalSchemaParser(SchemaParser):
SchemaParser.start_import(self, attrs)
class ZopeWSGIOptions(ZDOptions):
"""zdaemon based ZopeWSGIOptions to parse a ZConfig schema.
class ZopeWSGIOptions(object):
"""ZopeWSGIOptions parses a ZConfig schema and config file.
"""
configfile = None
confighandlers = None
configroot = None
schema = None
schemadir = os.path.dirname(os.path.abspath(__file__))
schemafile = 'wsgischema.xml'
def __init__(self, configfile=None):
self.configfile = configfile
def load_schema(self):
if self.schema is None:
# Load schema
......@@ -75,3 +80,13 @@ class ZopeWSGIOptions(ZDOptions):
self.schema = parser._schema
finally:
resource.close()
def load_configfile(self):
loader = ConfigLoader(self.schema)
self.configroot, self.confighandlers = loader.loadURL(
self.configfile)
def __call__(self):
self.load_schema()
self.load_configfile()
return self
......@@ -43,13 +43,7 @@ def _set_wsgi_config(configfile=None):
Optionally accept a configfile argument (string path) in order
to specify where the configuration file exists. """
from Zope2.Startup import options, handlers
opts = options.ZopeWSGIOptions()
if configfile:
opts.configfile = configfile
opts.realize(raise_getopt_errs=0)
else:
opts.realize()
opts = options.ZopeWSGIOptions(configfile=configfile)()
handlers.handleWSGIConfig(opts.configroot, opts.confighandlers)
import App.config
App.config.setConfiguration(opts.configroot)
......@@ -63,9 +57,7 @@ def make_wsgi_app(global_config, zope_conf):
from Zope2.Startup.options import ZopeWSGIOptions
from ZPublisher.WSGIPublisher import publish_module
starter = get_wsgi_starter()
opts = ZopeWSGIOptions()
opts.configfile = zope_conf
opts.realize(args=(), progname='Zope2WSGI', raise_getopt_errs=False)
opts = ZopeWSGIOptions(configfile=zope_conf)()
handleWSGIConfig(opts.configroot, opts.confighandlers)
setConfiguration(opts.configroot)
starter.setConfiguration(opts.configroot)
......
......@@ -21,38 +21,32 @@ import ZConfig
from Zope2.Startup.options import ZopeWSGIOptions
_SCHEMA = {}
_SCHEMA = None
TEMPNAME = tempfile.mktemp()
TEMPVAR = os.path.join(TEMPNAME, "var")
def getSchema(schemafile):
def getSchema():
global _SCHEMA
if schemafile not in _SCHEMA:
if _SCHEMA is None:
opts = ZopeWSGIOptions()
opts.schemafile = schemafile
opts.load_schema()
_SCHEMA[schemafile] = opts.schema
return _SCHEMA[schemafile]
_SCHEMA = opts.schema
return _SCHEMA
class WSGIStartupTestCase(unittest.TestCase):
@property
def schema(self):
return getSchema('wsgischema.xml')
def load_config_text(self, text):
# We have to create a directory of our own since the existence
# of the directory is checked. This handles this in a
# platform-independent way.
schema = self.schema
sio = cStringIO.StringIO(
text.replace("<<INSTANCE_HOME>>", TEMPNAME))
os.mkdir(TEMPNAME)
os.mkdir(TEMPVAR)
try:
conf, handler = ZConfig.loadConfigFile(schema, sio)
conf, handler = ZConfig.loadConfigFile(getSchema(), sio)
finally:
os.rmdir(TEMPVAR)
os.rmdir(TEMPNAME)
......
......@@ -27,11 +27,10 @@ from Zope2.Startup.options import ZopeWSGIOptions
_SCHEMA = None
def getSchema(schemafile):
def getSchema():
global _SCHEMA
if _SCHEMA is None:
opts = ZopeWSGIOptions()
opts.schemafile = schemafile
opts.load_schema()
_SCHEMA = opts.schema
return _SCHEMA
......@@ -39,10 +38,6 @@ def getSchema(schemafile):
class WSGIStarterTestCase(unittest.TestCase):
@property
def schema(self):
return getSchema('wsgischema.xml')
def setUp(self):
self.TEMPNAME = tempfile.mktemp()
......@@ -66,7 +61,7 @@ class WSGIStarterTestCase(unittest.TestCase):
if why == 17:
# already exists
pass
conf, self.handler = ZConfig.loadConfigFile(self.schema, sio)
conf, self.handler = ZConfig.loadConfigFile(getSchema(), sio)
self.assertEqual(conf.instancehome, self.TEMPNAME)
return conf
......
......@@ -30,9 +30,7 @@ class ZopeFinder(object):
from Zope2.Startup import options, handlers
import App.config
import Zope2
opts = options.ZopeWSGIOptions()
opts.configfile = config_file
opts.realize(args=[], doc="", raise_getopt_errs=0)
opts = options.ZopeWSGIOptions(configfile=config_file)()
handlers.handleWSGIConfig(opts.configroot, opts.confighandlers)
App.config.setConfiguration(opts.configroot)
app = Zope2.app()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment