Commit 70f7997f authored by Hanno Schlichting's avatar Hanno Schlichting

Split a WSGI part out of `zopeschema.xml`.

This reduces the supported `zope.conf` directives when run under WSGI.
In particular directives related to ZServer and zopectl and those
changing sys.path are not supported.
parent e0dd5f5e
......@@ -25,6 +25,9 @@ Features Added
Restructuring
+++++++++++++
- Split a WSGI part out of `zopeschema.xml`. This reduces the supported
`zope.conf` directives when run under WSGI.
- Remove temp_folder mount point from default configuration.
- Split a WSGI part out of `Zope2.Startup.ZopeStarter`.
......
......@@ -114,10 +114,6 @@ class WSGIStarter(object):
def setupConfiguredLoggers(self):
# Must happen after ZopeStarter.setupInitialLogging()
self.event_logger.removeHandler(self.startup_handler)
if self.cfg.zserver_read_only_mode:
# no log files written in read only mode
return
if self.cfg.eventlog is not None:
self.cfg.eventlog()
if self.cfg.access is not None:
......
......@@ -114,22 +114,22 @@ class zdaemonEnvironDict(UserDict):
def root_config(section):
# Datatype for the root configuration object
# (default values for some computed paths, configures the dbtab)
from ZConfig import ConfigurationError
from ZConfig.matcher import SectionValue
if section.environment is None:
section.environment = zdaemonEnvironDict()
if section.cgi_environment is None:
section.cgi_environment = zdaemonEnvironDict()
if hasattr(section, 'cgi_environment'):
if section.cgi_environment is None:
section.cgi_environment = zdaemonEnvironDict()
if section.clienthome is None:
section.clienthome = os.path.join(section.instancehome, "var")
# set up defaults for pid_filename and lock_filename if they're
# not in the config
if section.pid_filename is None:
section.pid_filename = os.path.join(section.clienthome, 'Z2.pid')
if section.lock_filename is None:
section.lock_filename = os.path.join(section.clienthome, 'Z2.lock')
if hasattr(section, 'pid_filename'):
if section.pid_filename is None:
section.pid_filename = os.path.join(section.clienthome, 'Z2.pid')
if hasattr(section, 'lock_filename'):
if section.lock_filename is None:
section.lock_filename = os.path.join(section.clienthome, 'Z2.lock')
if not section.databases:
section.databases = []
......
......@@ -83,51 +83,48 @@ def enable_ms_public_header(value):
def root_handler(cfg):
""" Mutate the configuration with defaults and perform
fixups of values that require knowledge about configuration
values outside of their context.
"""
# Set environment variables
for k, v in cfg.environment.items():
os.environ[k] = v
# Add directories to the pythonpath
instancelib = os.path.join(cfg.instancehome, 'lib', 'python')
if instancelib not in cfg.path:
if os.path.isdir(instancelib):
cfg.path.append(instancelib)
path = cfg.path[:]
path.reverse()
for dir in path:
sys.path.insert(0, dir)
# Add any product directories not already in Products.__path__.
# Directories are added in the order they are mentioned
instanceprod = os.path.join(cfg.instancehome, 'Products')
if instanceprod not in cfg.products:
if os.path.isdir(instanceprod):
cfg.products.append(instanceprod)
import Products
L = []
for d in cfg.products + Products.__path__:
if d not in L:
L.append(d)
Products.__path__[:] = L
# if no servers are defined, create default http server and ftp server
if not cfg.servers:
cfg.servers = []
# prepare servers:
for factory in cfg.servers:
factory.prepare(cfg.ip_address or '',
cfg.dns_resolver,
"Zope2",
cfg.cgi_environment,
cfg.port_base)
if hasattr(cfg, 'path'):
# Add directories to the pythonpath
instancelib = os.path.join(cfg.instancehome, 'lib', 'python')
if instancelib not in cfg.path:
if os.path.isdir(instancelib):
cfg.path.append(instancelib)
path = cfg.path[:]
path.reverse()
for dir in path:
sys.path.insert(0, dir)
if hasattr(cfg, 'products'):
# Add any product directories not already in Products.__path__.
# Directories are added in the order they are mentioned
instanceprod = os.path.join(cfg.instancehome, 'Products')
if instanceprod not in cfg.products:
if os.path.isdir(instanceprod):
cfg.products.append(instanceprod)
import Products
L = []
for d in cfg.products + Products.__path__:
if d not in L:
L.append(d)
Products.__path__[:] = L
if hasattr(cfg, 'servers'):
# if no servers are defined, create default servers
if not cfg.servers:
cfg.servers = []
# prepare servers:
for factory in cfg.servers:
factory.prepare(cfg.ip_address or '',
cfg.dns_resolver,
"Zope2",
cfg.cgi_environment,
cfg.port_base)
# set up trusted proxies
if cfg.trusted_proxies:
......
......@@ -23,14 +23,58 @@ Options:
"""
import os
import xml.sax
import zdaemon.zdoptions
from ZConfig.loader import SchemaLoader
from ZConfig.schema import SchemaParser
from zdaemon.zdoptions import ZDOptions
class ZopeOptions(zdaemon.zdoptions.ZDOptions):
class ConditionalSchemaParser(SchemaParser):
"""
A SchemaParser with support for conditionally executing import
directives based on a Python import condition. This is similar to
ZCML's condition="installed foo" support, shortened to condition="foo".
"""
def start_import(self, attrs):
load_import = True
condition = attrs.get('condition', '').strip()
if condition:
try:
__import__(condition)
except ImportError:
load_import = False
if load_import:
SchemaParser.start_import(self, attrs)
class ZopeOptions(ZDOptions):
# Provide help message, without indentation.
__doc__ = __doc__
schemadir = os.path.dirname(os.path.abspath(__file__))
schemafile = "zopeschema.xml"
schemafile = 'zopeschema.xml'
def load_schema(self):
if self.schema is None:
# Load schema
if self.schemadir is None:
self.schemadir = os.path.dirname(__file__)
self.schemafile = os.path.join(self.schemadir, self.schemafile)
self._conditional_load()
def _conditional_load(self):
loader = SchemaLoader()
# loadURL
url = loader.normalizeURL(self.schemafile)
resource = loader.openResource(url)
try:
# load / parseResource without caching
parser = ConditionalSchemaParser(loader, resource.url)
xml.sax.parse(resource.file, parser)
self.schema = parser._schema
finally:
resource.close()
......@@ -67,6 +67,8 @@ def make_wsgi_app(global_config, zope_conf):
starter = get_starter(wsgi=True)
opts = ZopeOptions()
opts.configfile = zope_conf
if opts.schemafile == 'zopeschema.xml':
opts.schemafile = 'wsgischema.xml'
opts.realize(args=(), progname='Zope2WSGI', raise_getopt_errs=False)
handleConfig(opts.configroot, opts.confighandlers)
setConfiguration(opts.configroot)
......
This diff is collapsed.
......@@ -99,6 +99,7 @@ class ZopeCtlOptions(ZopeOptions, ZDCtlOptions):
logsectionname = None
def __init__(self):
ZopeOptions.__init__(self)
ZDCtlOptions.__init__(self)
self.add("interactive", None, "i", "interactive", flag=1)
self.add("default_to_interactive", "runner.default_to_interactive",
......
This diff is collapsed.
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