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

Simplify ZopeWSGIOptions and drop dependency on zdaemon.

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