Commit 95d7a661 authored by Hanno Schlichting's avatar Hanno Schlichting

Copy startup and zope.conf parsing logic to ZServer.

parent 519ca223
##############################################################################
#
# Copyright (c) 2003 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import os
import cStringIO
import sys
import tempfile
import unittest
import warnings
import ZConfig
import Zope2.Startup
import Products
TEMPNAME = tempfile.mktemp()
TEMPPRODUCTS = os.path.join(TEMPNAME, "Products")
def getSchema():
startup = os.path.dirname(os.path.realpath(Zope2.Startup.__file__))
schemafile = os.path.join(startup, 'wsgischema.xml')
return ZConfig.loadSchema(schemafile)
class TestSchemaWarning(Warning):
pass
class TestWarnFilter(unittest.TestCase):
schema = None
def setUp(self):
if self.schema is None:
TestWarnFilter.schema = getSchema()
# There is no official API to restore warning filters to a previous
# state. Here we cheat.
self.original_warning_filters = warnings.filters[:]
def tearDown(self):
warnings.filters[:] = self.original_warning_filters
Products.__path__ = [d for d in Products.__path__
if os.path.exists(d)]
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(TEMPPRODUCTS)
try:
conf, handler = ZConfig.loadConfigFile(schema, sio)
finally:
os.rmdir(TEMPPRODUCTS)
os.rmdir(TEMPNAME)
self.assertEqual(conf.instancehome, TEMPNAME)
return conf, handler
if sys.version_info < (2, 7):
def test_behavior(self):
conf, handler = self.load_config_text("""\
instancehome <<INSTANCE_HOME>>
<warnfilter>
action error
message .*test.*
category Zope2.Startup.tests.test_warnfilter.TestSchemaWarning
module .*test_warnfilter.*
lineno 0
</warnfilter>
<warnfilter>
action error
message .*test.*
</warnfilter>
""")
self.assertEqual(len(conf.warnfilters), 2)
self.assertRaises(TestSchemaWarning, self._dowarning1)
self.assertRaises(UserWarning, self._dowarning2)
def _dowarning1(self):
warnings.warn('This is only a test.', TestSchemaWarning)
def _dowarning2(self):
warnings.warn('This is another test.')
def test_warn_action(self):
self.assertRaises(ZConfig.ConfigurationSyntaxError,
self._badwarnaction)
def _badwarnaction(self):
conf, handler = self.load_config_text("""\
instancehome <<INSTANCE_HOME>>
<warnfilter>
action wontwork
category Zope2.Startup.tests.test_schema.TestSchemaWarning
</warnfilter>
""")
def test_warn_category(self):
self.assertRaises(ZConfig.ConfigurationSyntaxError,
self._badwarncategory)
def _badwarncategory(self):
conf, handler = self.load_config_text("""\
instancehome <<INSTANCE_HOME>>
<warnfilter>
action error
category A.Module.That.Doesnt.Exist
</warnfilter>
""")
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
_config = None _config = None
def getConfiguration(): def getConfiguration():
"""Return the global Zope configuration object. """Return the global Zope configuration object.
...@@ -25,6 +26,7 @@ def getConfiguration(): ...@@ -25,6 +26,7 @@ def getConfiguration():
setConfiguration(DefaultConfiguration()) setConfiguration(DefaultConfiguration())
return _config return _config
def setConfiguration(cfg): def setConfiguration(cfg):
"""Set the global configuration object. """Set the global configuration object.
...@@ -54,6 +56,7 @@ def setConfiguration(cfg): ...@@ -54,6 +56,7 @@ def setConfiguration(cfg):
Globals.DevelopmentMode = cfg.debug_mode Globals.DevelopmentMode = cfg.debug_mode
class DefaultConfiguration: class DefaultConfiguration:
""" """
This configuration should be used effectively only during unit tests This configuration should be used effectively only during unit tests
...@@ -64,12 +67,8 @@ class DefaultConfiguration: ...@@ -64,12 +67,8 @@ class DefaultConfiguration:
self.instancehome = FindHomes.INSTANCE_HOME self.instancehome = FindHomes.INSTANCE_HOME
self.dbtab = None self.dbtab = None
self.debug_mode = True self.debug_mode = True
self.enable_product_installation = False
self.locale = None self.locale = None
# ZServer.HTTPServer
self.http_header_max_length = 8196
# VerboseSecurity # VerboseSecurity
self.skip_ownership_checking = False self.skip_ownership_checking = False
self.skip_authentication_checking = False self.skip_authentication_checking = False
...@@ -21,9 +21,6 @@ import unittest ...@@ -21,9 +21,6 @@ import unittest
from Testing.makerequest import makerequest from Testing.makerequest import makerequest
import Zope2
Zope2.startup()
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl.class_init import InitializeClass from AccessControl.class_init import InitializeClass
...@@ -33,6 +30,9 @@ from AccessControl.Permissions import view_management_screens ...@@ -33,6 +30,9 @@ from AccessControl.Permissions import view_management_screens
from AccessControl.ImplPython import guarded_getattr as guarded_getattr_py from AccessControl.ImplPython import guarded_getattr as guarded_getattr_py
from AccessControl.ImplC import guarded_getattr as guarded_getattr_c from AccessControl.ImplC import guarded_getattr as guarded_getattr_c
import Zope2
Zope2.startup_wsgi()
class AllowedItem(SimpleItem): class AllowedItem(SimpleItem):
id = 'allowed' id = 'allowed'
......
...@@ -15,7 +15,7 @@ from OFS.SimpleItem import SimpleItem ...@@ -15,7 +15,7 @@ from OFS.SimpleItem import SimpleItem
from Testing.makerequest import makerequest from Testing.makerequest import makerequest
from Zope2.App import zcml from Zope2.App import zcml
Zope2.startup() Zope2.startup_wsgi()
class EventLogger(object): class EventLogger(object):
......
...@@ -16,7 +16,7 @@ from OFS.Folder import Folder ...@@ -16,7 +16,7 @@ from OFS.Folder import Folder
from Zope2.App import zcml from Zope2.App import zcml
Zope2.startup() Zope2.startup_wsgi()
class EventLogger(object): class EventLogger(object):
......
...@@ -35,7 +35,7 @@ except: ...@@ -35,7 +35,7 @@ except:
imagedata = os.path.join(here, 'test.gif') imagedata = os.path.join(here, 'test.gif')
filedata = os.path.join(here, 'test.gif') filedata = os.path.join(here, 'test.gif')
Zope2.startup() Zope2.startup_wsgi()
def makeConnection(): def makeConnection():
......
import unittest
import Zope2
Zope2.startup()
import os import os
import shutil import shutil
import time import time
import transaction
import tempfile import tempfile
import unittest
import transaction
import ZODB import ZODB
from ZODB.FileStorage import FileStorage
from OFS.Application import Application from OFS.Application import Application
from OFS.History import Historical from OFS.History import Historical
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from ZODB.FileStorage import FileStorage import Zope2
Zope2.startup_wsgi()
class HistoryItem(SimpleItem, Historical): class HistoryItem(SimpleItem, Historical):
......
...@@ -88,6 +88,7 @@ _configure_client_cache() ...@@ -88,6 +88,7 @@ _configure_client_cache()
_exec('import Zope2') _exec('import Zope2')
import Zope2 import Zope2
import Zope2.Startup.run
_exec('import ZODB') _exec('import ZODB')
import ZODB import ZODB
_write('.') _write('.')
...@@ -214,7 +215,7 @@ installProduct('OFSP', 1) ...@@ -214,7 +215,7 @@ installProduct('OFSP', 1)
app = Zope2.app app = Zope2.app
debug = Zope2.debug debug = Zope2.debug
DB = Zope2.DB DB = Zope2.DB
configure = Zope2.configure configure = Zope2.Startup.run.configure_wsgi
def startup(): pass def startup(): pass
Zope = Zope2 Zope = Zope2
active = _patched active = _patched
......
...@@ -5,7 +5,7 @@ from ZPublisher.BaseRequest import BaseRequest ...@@ -5,7 +5,7 @@ from ZPublisher.BaseRequest import BaseRequest
from ZPublisher.HTTPResponse import HTTPResponse from ZPublisher.HTTPResponse import HTTPResponse
import Zope2 import Zope2
Zope2.startup() Zope2.startup_wsgi()
pt_simple_was_run = 0 pt_simple_was_run = 0
......
...@@ -14,27 +14,18 @@ ...@@ -14,27 +14,18 @@
from __future__ import absolute_import from __future__ import absolute_import
import sys
from zope.deferredimport import deprecated from zope.deferredimport import deprecated
# BBB Zope 5.0 # BBB Zope 5.0
deprecated( deprecated(
'Please import from ZServer.Zope2.Startup.starter', 'Please import from ZServer.Zope2.Startup.starter',
get_starter='ZServer.Zope2.Startup.starter:get_starter',
UnixZopeStarter='ZServer.Zope2.Startup.starter:UnixZopeStarter', UnixZopeStarter='ZServer.Zope2.Startup.starter:UnixZopeStarter',
WindowsZopeStarter='ZServer.Zope2.Startup.starter:WindowsZopeStarter', WindowsZopeStarter='ZServer.Zope2.Startup.starter:WindowsZopeStarter',
ZopeStarter='ZServer.Zope2.Startup.starter:ZopeStarter', ZopeStarter='ZServer.Zope2.Startup.starter:ZopeStarter',
) )
def get_starter(wsgi=False): def get_wsgi_starter():
if wsgi: from Zope2.Startup.starter import WSGIStarter
from Zope2.Startup.starter import WSGIStarter return WSGIStarter()
return WSGIStarter()
else:
if sys.platform[:3].lower() == "win":
from ZServer.Zope2.Startup.starter import WindowsZopeStarter
return WindowsZopeStarter()
else:
from ZServer.Zope2.Startup.starter import UnixZopeStarter
return UnixZopeStarter()
...@@ -18,9 +18,23 @@ import os ...@@ -18,9 +18,23 @@ import os
from UserDict import UserDict from UserDict import UserDict
import traceback import traceback
from ZConfig.components.logger import logger
from ZODB.config import ZODBDatabase from ZODB.config import ZODBDatabase
from zope.deferredimport import deprecated
# BBB Zope 5.0
_prefix = 'ZServer.Zope2.Startup.datatypes:'
deprecated(
'Please import from ZServer.Zope2.Startup.datatypes.',
cgi_environment=_prefix + 'cgi_environment',
LoggerFactory=_prefix + 'LoggerFactory',
dns_resolver=_prefix + 'dns_resolver',
python_dotted_path=_prefix + 'python_dotted_path',
zdaemonEnvironDict=_prefix + 'zdaemonEnvironDict',
root_config=_prefix + 'root_config',
minimalClassFactory=_prefix + 'minimalClassFactory',
)
def security_policy_implementation(value): def security_policy_implementation(value):
value = value.upper() value = value.upper()
...@@ -39,31 +53,10 @@ def datetime_format(value): ...@@ -39,31 +53,10 @@ def datetime_format(value):
return value return value
def cgi_environment(section): def environment(section):
return section.environ return section.environ
class LoggerFactory(logger.LoggerFactory):
"""
A factory used to create loggers while delaying actual logger
instance construction. We need to do this because we may want to
reference a logger before actually instantiating it (for example,
to allow the app time to set an effective user). An instance of
this wrapper is a callable which, when called, returns a logger
object.
"""
def __init__(self, section):
section.name = section.getSectionName()
section.propagate = False
logger.LoggerFactory.__init__(self, section)
def dns_resolver(hostname):
# DNS resolver
from ZServer.medusa import resolver
return resolver.caching_resolver(hostname)
def mount_point(value): def mount_point(value):
# mount-point definition # mount-point definition
if not value: if not value:
...@@ -98,14 +91,7 @@ def importable_name(name): ...@@ -98,14 +91,7 @@ def importable_name(name):
name, IO.getvalue())) name, IO.getvalue()))
def python_dotted_path(name): class ZDaemonEnvironDict(UserDict):
# A datatype that ensures that a dotted path name can be resolved but
# returns the name instead of the object
ob = importable_name(name) # NOQA - will fail in course
return name
class zdaemonEnvironDict(UserDict):
# zdaemon 2 expects to use a 'mapping' attribute of the environ object. # zdaemon 2 expects to use a 'mapping' attribute of the environ object.
@property @property
...@@ -113,24 +99,14 @@ class zdaemonEnvironDict(UserDict): ...@@ -113,24 +99,14 @@ class zdaemonEnvironDict(UserDict):
return self.data return self.data
def root_config(section): def root_wsgi_config(section):
from ZConfig import ConfigurationError from ZConfig import ConfigurationError
from ZConfig.matcher import SectionValue from ZConfig.matcher import SectionValue
if section.environment is None: if section.environment is None:
section.environment = zdaemonEnvironDict() section.environment = ZDaemonEnvironDict()
if hasattr(section, 'cgi_environment'):
if section.cgi_environment is None:
section.cgi_environment = zdaemonEnvironDict()
if section.clienthome is None: if section.clienthome is None:
section.clienthome = os.path.join(section.instancehome, "var") section.clienthome = os.path.join(section.instancehome, "var")
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: if not section.databases:
section.databases = [] section.databases = []
...@@ -294,24 +270,8 @@ class DBTab: ...@@ -294,24 +270,8 @@ class DBTab:
return name return name
def minimalClassFactory(jar, module, name, def simpleClassFactory(jar, module, name, _silly=('__doc__',), _globals={}):
_silly=('__doc__',), _globals={}): """Class factory.
"""Minimal class factory.
If any class is not found, this class factory will propagate
the exception to the application, unlike the other class factories.
""" """
m = __import__(module, _globals, _globals, _silly) m = __import__(module, _globals, _globals, _silly)
return getattr(m, name) return getattr(m, name)
def simpleClassFactory(jar, module, name,
_silly=('__doc__',), _globals={}):
"""Class factory.
"""
import OFS.Uninstalled
try:
m = __import__(module, _globals, _globals, _silly)
return getattr(m, name)
except:
return OFS.Uninstalled.Broken(jar, None, (module, name))
...@@ -14,13 +14,29 @@ ...@@ -14,13 +14,29 @@
import os import os
import re import re
import sys
from socket import gethostbyaddr from socket import gethostbyaddr
try: from zope.deferredimport import deprecated
from ZServer.Zope2.Startup import config
except ImportError: # BBB Zope 5.0
config = None _prefix = 'ZServer.Zope2.Startup.handlers:'
deprecated(
'Please import from ZServer.Zope2.Startup.handlers.',
handleConfig=_prefix + 'handleConfig',
root_handler=_prefix + 'root_handler',
maximum_number_of_session_objects=(
_prefix + 'maximum_number_of_session_objects'),
session_add_notify_script_path=(
_prefix + 'session_add_notify_script_path'),
session_delete_notify_script_path=(
_prefix + 'session_delete_notify_script_path'),
session_timeout_minutes=_prefix + 'session_timeout_minutes',
large_file_threshold=_prefix + 'large_file_threshold',
max_listen_sockets=_prefix + 'max_listen_sockets',
cgi_maxlen=_prefix + 'cgi_maxlen',
http_header_max_length=_prefix + 'http_header_max_length',
enable_ms_public_header=_prefix + 'enable_ms_public_header',
)
def _setenv(name, value): def _setenv(name, value):
...@@ -51,108 +67,21 @@ def automatically_quote_dtml_request_data(value): ...@@ -51,108 +67,21 @@ def automatically_quote_dtml_request_data(value):
return value return value
def maximum_number_of_session_objects(value):
default = 1000
value not in (None, default) and _setenv('ZSESSION_OBJECT_LIMIT', value)
return value
def session_add_notify_script_path(value):
value is not None and _setenv('ZSESSION_ADD_NOTIFY', value)
return value
def session_delete_notify_script_path(value):
value is not None and _setenv('ZSESSION_DEL_NOTIFY', value)
return value
def session_timeout_minutes(value):
default = 20
value not in (None, default) and _setenv('ZSESSION_TIMEOUT_MINS', value)
return value
def large_file_threshold(value):
if config:
config.ZSERVER_LARGE_FILE_THRESHOLD = value
def http_realm(value): def http_realm(value):
value is not None and _setenv('Z_REALM', value) value is not None and _setenv('Z_REALM', value)
return value return value
def max_listen_sockets(value): def root_wsgi_handler(cfg):
if config:
config.ZSERVER_CONNECTION_LIMIT = value
def cgi_maxlen(value):
import cgi
cgi.maxlen = value
def http_header_max_length(value):
return value
def enable_ms_public_header(value):
if config:
config.ZSERVER_ENABLE_MS_PUBLIC_HEADER = value
def root_handler(cfg):
# Set environment variables # Set environment variables
for k, v in cfg.environment.items(): for k, v in cfg.environment.items():
os.environ[k] = v os.environ[k] = v
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 # set up trusted proxies
if cfg.trusted_proxies: if cfg.trusted_proxies:
mapped = [] mapped = []
for name in cfg.trusted_proxies: for name in cfg.trusted_proxies:
mapped.extend(_name_to_ips(name)) mapped.extend(_name_to_ips(name))
if config:
config.TRUSTED_PROXIES = tuple(mapped)
from ZPublisher import HTTPRequest from ZPublisher import HTTPRequest
HTTPRequest.trusted_proxies = tuple(mapped) HTTPRequest.trusted_proxies = tuple(mapped)
...@@ -163,14 +92,6 @@ def root_handler(cfg): ...@@ -163,14 +92,6 @@ def root_handler(cfg):
HTTPRequest.retry_max_count = cfg.max_conflict_retries HTTPRequest.retry_max_count = cfg.max_conflict_retries
def handleConfig(cfg, multihandler):
handlers = {}
for name, value in globals().items():
if not name.startswith('_'):
handlers[name] = value
return multihandler(handlers)
def _name_to_ips(host, _is_ip=re.compile(r'(\d+\.){3}').match): def _name_to_ips(host, _is_ip=re.compile(r'(\d+\.){3}').match):
"""Map a name *host* to the sequence of its ip addresses. """Map a name *host* to the sequence of its ip addresses.
...@@ -181,3 +102,11 @@ def _name_to_ips(host, _is_ip=re.compile(r'(\d+\.){3}').match): ...@@ -181,3 +102,11 @@ def _name_to_ips(host, _is_ip=re.compile(r'(\d+\.){3}').match):
if _is_ip(host): if _is_ip(host):
return [host] return [host]
return gethostbyaddr(host)[2] return gethostbyaddr(host)[2]
def handleWSGIConfig(cfg, multihandler):
handlers = {}
for name, value in globals().items():
if not name.startswith('_'):
handlers[name] = value
return multihandler(handlers)
...@@ -11,16 +11,6 @@ ...@@ -11,16 +11,6 @@
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""
The Zope run script.
Usage: runzope [-C URL][-h] [options]
Options:
-C/--configure URL -- configuration file or URL
-X -- overwrite config file settings, e.g. -X "debug-mode=on"
-h/--help -- print this usage message and exit
"""
import os import os
import xml.sax import xml.sax
...@@ -28,6 +18,14 @@ import xml.sax ...@@ -28,6 +18,14 @@ import xml.sax
from ZConfig.loader import SchemaLoader from ZConfig.loader import SchemaLoader
from ZConfig.schema import SchemaParser from ZConfig.schema import SchemaParser
from zdaemon.zdoptions import ZDOptions from zdaemon.zdoptions import ZDOptions
from zope.deferredimport import deprecated
# BBB Zope 5.0
_prefix = 'ZServer.Zope2.Startup.options:'
deprecated(
'Please import from ZServer.Zope2.Startup.options.',
ZopeOptions=_prefix + 'ZopeOptions',
)
class ConditionalSchemaParser(SchemaParser): class ConditionalSchemaParser(SchemaParser):
...@@ -50,13 +48,12 @@ class ConditionalSchemaParser(SchemaParser): ...@@ -50,13 +48,12 @@ class ConditionalSchemaParser(SchemaParser):
SchemaParser.start_import(self, attrs) SchemaParser.start_import(self, attrs)
class ZopeOptions(ZDOptions): class ZopeWSGIOptions(ZDOptions):
"""zdaemon based ZopeWSGIOptions to parse a ZConfig schema.
# Provide help message, without indentation. """
__doc__ = __doc__
schemadir = os.path.dirname(os.path.abspath(__file__)) schemadir = os.path.dirname(os.path.abspath(__file__))
schemafile = 'zopeschema.xml' schemafile = 'wsgischema.xml'
def load_schema(self): def load_schema(self):
if self.schema is None: if self.schema is None:
......
...@@ -17,36 +17,40 @@ from zope.deferredimport import deprecated ...@@ -17,36 +17,40 @@ from zope.deferredimport import deprecated
# BBB Zope 5.0 # BBB Zope 5.0
deprecated( deprecated(
'Please import from ZServer.Zope2.Startup.run', 'Please import from ZServer.Zope2.Startup.run',
_setconfig='ZServer.Zope2.Startup.run:_setconfig',
configure='ZServer.Zope2.Startup.run:configure',
run='ZServer.Zope2.Startup.run:run', run='ZServer.Zope2.Startup.run:run',
) )
def configure(configfile): def configure_wsgi(configfile):
""" Provide an API which allows scripts like zopectl to configure """ Provide an API which allows scripts to configure Zope
Zope before attempting to do 'app = Zope2.app(). Should be used as before attempting to do 'app = Zope2.app(). Should be used as
follows: from Zope2.Startup.run import configure; follows: from Zope2.Startup.run import configure_wsgi;
configure('/path/to/configfile'); import Zope2; app = Zope2.app() """ configure_wsgi('/path/to/configfile');
import Zope2; app = Zope2.app()
"""
import Zope2.Startup import Zope2.Startup
starter = Zope2.Startup.get_starter(wsgi=True) starter = Zope2.Startup.get_wsgi_starter()
opts = _setconfig(configfile) opts = _set_wsgi_config(configfile)
starter.setConfiguration(opts.configroot) starter.setConfiguration(opts.configroot)
starter.setupSecurityOptions() starter.setupSecurityOptions()
return starter return starter
def _setconfig(configfile=None): def _set_wsgi_config(configfile=None):
""" Configure a Zope instance based on ZopeOptions. Optionally """ Configure a Zope instance based on ZopeWSGIOptions.
accept a configfile argument (string path) in order to specify Optionally accept a configfile argument (string path) in order
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.ZopeOptions() opts = options.ZopeWSGIOptions()
if configfile: if configfile:
opts.configfile = configfile opts.configfile = configfile
opts.realize(raise_getopt_errs=0) opts.realize(raise_getopt_errs=0)
else: else:
opts.realize() opts.realize()
handlers.handleConfig(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)
return opts return opts
...@@ -54,17 +58,15 @@ def _setconfig(configfile=None): ...@@ -54,17 +58,15 @@ def _setconfig(configfile=None):
def make_wsgi_app(global_config, zope_conf): def make_wsgi_app(global_config, zope_conf):
from App.config import setConfiguration from App.config import setConfiguration
from Zope2.Startup import get_starter from Zope2.Startup import get_wsgi_starter
from Zope2.Startup.handlers import handleConfig from Zope2.Startup.handlers import handleWSGIConfig
from Zope2.Startup.options import ZopeOptions from Zope2.Startup.options import ZopeWSGIOptions
from ZPublisher.WSGIPublisher import publish_module from ZPublisher.WSGIPublisher import publish_module
starter = get_starter(wsgi=True) starter = get_wsgi_starter()
opts = ZopeOptions() opts = ZopeWSGIOptions()
opts.configfile = zope_conf opts.configfile = zope_conf
if opts.schemafile == 'zopeschema.xml':
opts.schemafile = 'wsgischema.xml'
opts.realize(args=(), progname='Zope2WSGI', raise_getopt_errs=False) opts.realize(args=(), progname='Zope2WSGI', raise_getopt_errs=False)
handleConfig(opts.configroot, opts.confighandlers) handleWSGIConfig(opts.configroot, opts.confighandlers)
setConfiguration(opts.configroot) setConfiguration(opts.configroot)
starter.setConfiguration(opts.configroot) starter.setConfiguration(opts.configroot)
starter.prepare() starter.prepare()
......
...@@ -99,7 +99,7 @@ class WSGIStarter(object): ...@@ -99,7 +99,7 @@ class WSGIStarter(object):
def startZope(self): def startZope(self):
# Import Zope # Import Zope
import Zope2 import Zope2
Zope2.startup() Zope2.startup_wsgi()
def _name_to_ips(host, _is_ip=re.compile(r'(\d+\.){3}').match): def _name_to_ips(host, _is_ip=re.compile(r'(\d+\.){3}').match):
......
...@@ -19,7 +19,7 @@ import unittest ...@@ -19,7 +19,7 @@ import unittest
import ZConfig import ZConfig
from Zope2.Startup.options import ZopeOptions from Zope2.Startup.options import ZopeWSGIOptions
_SCHEMA = {} _SCHEMA = {}
TEMPNAME = tempfile.mktemp() TEMPNAME = tempfile.mktemp()
...@@ -29,7 +29,7 @@ TEMPVAR = os.path.join(TEMPNAME, "var") ...@@ -29,7 +29,7 @@ TEMPVAR = os.path.join(TEMPNAME, "var")
def getSchema(schemafile): def getSchema(schemafile):
global _SCHEMA global _SCHEMA
if schemafile not in _SCHEMA: if schemafile not in _SCHEMA:
opts = ZopeOptions() opts = ZopeWSGIOptions()
opts.schemafile = schemafile opts.schemafile = schemafile
opts.load_schema() opts.load_schema()
_SCHEMA[schemafile] = opts.schema _SCHEMA[schemafile] = opts.schema
......
...@@ -21,8 +21,8 @@ import unittest ...@@ -21,8 +21,8 @@ import unittest
import ZConfig import ZConfig
from Zope2.Startup import get_starter from Zope2.Startup import get_wsgi_starter
from Zope2.Startup.options import ZopeOptions from Zope2.Startup.options import ZopeWSGIOptions
_SCHEMA = None _SCHEMA = None
...@@ -30,7 +30,7 @@ _SCHEMA = None ...@@ -30,7 +30,7 @@ _SCHEMA = None
def getSchema(schemafile): def getSchema(schemafile):
global _SCHEMA global _SCHEMA
if _SCHEMA is None: if _SCHEMA is None:
opts = ZopeOptions() opts = ZopeWSGIOptions()
opts.schemafile = schemafile opts.schemafile = schemafile
opts.load_schema() opts.load_schema()
_SCHEMA = opts.schema _SCHEMA = opts.schema
...@@ -50,7 +50,7 @@ class WSGIStarterTestCase(unittest.TestCase): ...@@ -50,7 +50,7 @@ class WSGIStarterTestCase(unittest.TestCase):
shutil.rmtree(self.TEMPNAME) shutil.rmtree(self.TEMPNAME)
def get_starter(self, conf): def get_starter(self, conf):
starter = get_starter(wsgi=True) starter = get_wsgi_starter()
starter.setConfiguration(conf) starter.setConfiguration(conf)
return starter return starter
......
<schema prefix="Zope2.Startup.datatypes" <schema prefix="Zope2.Startup.datatypes"
datatype=".root_config" datatype=".root_wsgi_config"
handler="root_handler"> handler="root_wsgi_handler">
<!-- type definitions --> <!-- type definitions -->
<import package="ZConfig.components.logger" file="handlers.xml"/>
<import package="ZConfig.components.logger" file="eventlog.xml"/>
<import package="ZODB"/> <import package="ZODB"/>
<sectiontype name="logger" datatype=".LoggerFactory">
<description>
This "logger" type only applies to access and request ("trace")
logging; event logging is handled by the "logging" package in
the Python standard library. The loghandler type used here is
provided by the "ZConfig.components.logger" package.
</description>
<key name="level"
datatype="ZConfig.components.logger.datatypes.logging_level"
default="info"/>
<multisection name="*"
type="ZConfig.logger.handler"
attribute="handlers"
required="yes"/>
</sectiontype>
<sectiontype name="environment" <sectiontype name="environment"
datatype=".cgi_environment" datatype=".environment"
keytype="identifier"> keytype="identifier">
<description> <description>
A section which allows you to define simple key-value pairs which A section which allows you to define simple key-value pairs which
...@@ -271,43 +253,6 @@ ...@@ -271,43 +253,6 @@
<metadefault>off</metadefault> <metadefault>off</metadefault>
</key> </key>
<section type="eventlog" name="*" attribute="eventlog">
<description>
Describes what level of log output is desired and where it
should be written.
</description>
</section>
<section type="logger" name="access">
<description>
Describes the logging performed to capture the 'access' log,
which typically captures per-request data in common or combined
log format.
</description>
</section>
<section type="logger" name="trace">
<description>
Describes the logging performed to capture the 'trace' log,
which typically captures detailed per-request data useful for
Zope debugging.
</description>
</section>
<key name="conflict-error-log-level"
datatype="ZConfig.components.logger.datatypes.logging_level"
default="info">
<description>
Specifies at which level conflict errors are logged. Conflict
errors, when occurring in small numbers, are a normal part of the
Zope optimistic transaction conflict resolution algorithms. They
are retried automatically a few times, and are therefore usually
not visible by the user. You can specify 'notset' if you don't
want them logged, or use any other logger level.
</description>
<metadefault>info</metadefault>
</key>
<multisection type="ZODB.Database" name="+" attribute="databases"> <multisection type="ZODB.Database" name="+" attribute="databases">
<description> <description>
Zope ZODB databases must have a name, and they are required to be Zope ZODB databases must have a name, and they are required to be
......
This diff is collapsed.
...@@ -15,42 +15,53 @@ ...@@ -15,42 +15,53 @@
import os import os
from Zope2.Startup.run import configure from zope.deferredimport import deprecated
# BBB Zope 5.0
deprecated(
'Please import from ZServer.Zope2.',
startup='ZServer.Zope2:startup',
_configure='ZServer.Zope2:_configure',
)
deprecated(
'Please import from ZServer.Zope2.Startup.run.',
configure='ZServer.Zope2.Startup.run:configure',
)
_began_startup = 0 _began_startup = 0
def startup(): def startup_wsgi():
"""Initialize the Zope Package and provide a published module""" """Initialize the Zope Package and provide a published module"""
global _began_startup global _began_startup
if _began_startup: if _began_startup:
# Already began (and maybe finished) startup, so don't run again # Already began (and maybe finished) startup, so don't run again
return return
_began_startup = 1 _began_startup = 1
_configure() _configure_wsgi()
from Zope2.App.startup import startup as _startup from Zope2.App.startup import startup as _startup
_startup() _startup()
def app(*args, **kw): def app(*args, **kw):
"""Utility for scripts to open a connection to the database""" """Utility for scripts to open a connection to the database"""
startup() startup_wsgi()
return bobo_application(*args, **kw) return bobo_application(*args, **kw)
def debug(*args, **kw): def debug(*args, **kw):
"""Utility to try a Zope request using the interactive interpreter""" """Utility to try a Zope request using the interactive interpreter"""
startup() startup_wsgi()
import ZPublisher import ZPublisher
return ZPublisher.test('Zope2', *args, **kw) return ZPublisher.test('Zope2', *args, **kw)
def _configure(): def _configure_wsgi():
# Load configuration file from (optional) environment variable from Zope2.Startup.run import configure_wsgi
# Also see http://zope.org/Collectors/Zope/1233
configfile = os.environ.get('ZOPE_CONFIG') configfile = os.environ.get('ZOPE_CONFIG')
if configfile is not None: if configfile is not None:
configure(configfile) configure_wsgi(configfile)
# Zope2.App.startup.startup() sets the following variables in this module. # Zope2.App.startup.startup() sets the following variables in this module.
......
...@@ -30,20 +30,20 @@ class ZopeFinder(object): ...@@ -30,20 +30,20 @@ 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.ZopeOptions() opts = options.ZopeWSGIOptions()
opts.configfile = config_file opts.configfile = config_file
opts.realize(args=[], doc="", raise_getopt_errs=0) opts.realize(args=[], doc="", raise_getopt_errs=0)
handlers.handleConfig(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()
return app return app
def get_zope_conf(self): def get_zope_conf(self):
# the default config file path is assumed to live in # the default config file path is assumed to live in
# $instance_home/etc/zope.conf, and the console scripts that use this # $instance_home/etc/wsgi.conf, and the console scripts that use this
# are assumed to live in $instance_home/bin; override if the # are assumed to live in $instance_home/bin; override if the
# environ contains "ZOPE_CONF". # environ contains "ZOPE_CONF".
ihome = os.path.dirname(os.path.abspath(os.path.dirname(self.cmd))) ihome = os.path.dirname(os.path.abspath(os.path.dirname(self.cmd)))
default_config_file = os.path.join(ihome, 'etc', 'zope.conf') default_config_file = os.path.join(ihome, 'etc', 'wsgi.conf')
zope_conf = os.environ.get('ZOPE_CONF', default_config_file) zope_conf = os.environ.get('ZOPE_CONF', default_config_file)
return zope_conf return zope_conf
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