Commit f8c45562 authored by Stefan H. Holek's avatar Stefan H. Holek

ZopeLite now is careful not to apply monkey patches to an already running Zope.

parent aa0b42b0
...@@ -45,19 +45,30 @@ def _exec(cmd): ...@@ -45,19 +45,30 @@ def _exec(cmd):
_write('Loading Zope, please stand by ') _write('Loading Zope, please stand by ')
_start = time.time() _start = time.time()
# Configure logging def _configure_logging():
if not sys.modules.has_key('logging'): # Initialize the logging module
import logging if not sys.modules.has_key('logging'):
logging.basicConfig() import logging
logging.basicConfig()
# Debug mode is dog slow ...
import App.config def _configure_debug_mode():
config = App.config.getConfiguration() # Switch off debug mode
config.debug_mode = 0 import App.config
App.config.setConfiguration(config) config = App.config.getConfiguration()
config.debug_mode = 0
# Need to import Zope2 early on as the App.config.setConfiguration(config)
# ZTUtils package relies on it
def _configure_client_cache():
# Make sure we use a temporary client cache
import App.config
config = App.config.getConfiguration()
config.zeo_client_name = None
App.config.setConfiguration(config)
_configure_logging()
_configure_debug_mode()
_configure_client_cache()
_exec('import Zope2') _exec('import Zope2')
import Zope2 import Zope2
_exec('import ZODB') _exec('import ZODB')
...@@ -75,26 +86,31 @@ _write('.') ...@@ -75,26 +86,31 @@ _write('.')
_exec('import OFS.Application') _exec('import OFS.Application')
import OFS.Application import OFS.Application
import App.ProductContext import App.ProductContext
_write('.')
# Avoid expensive product import def _apply_patches():
def _null_import_products(): pass # Avoid expensive product import
OFS.Application.import_products = _null_import_products def null_import_products(): pass
OFS.Application.import_products = null_import_products
# Avoid expensive product installation
def _null_initialize(app): pass # Avoid expensive product installation
OFS.Application.initialize = _null_initialize def null_initialize(app): pass
OFS.Application.initialize = null_initialize
# Avoid expensive help registration
def _null_register_topic(self,id,topic): pass # Avoid expensive help registration
App.ProductContext.ProductContext.registerHelpTopic = _null_register_topic def null_register_topic(self,id,topic): pass
def _null_register_title(self,title): pass App.ProductContext.ProductContext.registerHelpTopic = null_register_topic
App.ProductContext.ProductContext.registerHelpTitle = _null_register_title def null_register_title(self,title): pass
def _null_register_help(self,directory='',clear=1,title_re=None): pass App.ProductContext.ProductContext.registerHelpTitle = null_register_title
App.ProductContext.ProductContext.registerHelp = _null_register_help def null_register_help(self,directory='',clear=1,title_re=None): pass
App.ProductContext.ProductContext.registerHelp = null_register_help
# Make sure to use a temporary client cache
if os.environ.get('ZEO_CLIENT'): del os.environ['ZEO_CLIENT'] # Do not patch a running Zope
if not Zope2._began_startup:
_apply_patches()
# Allow test authors to install Zope products into the test environment. Note
# that installProduct() must be called at module level - never from tests.
from OFS.Application import get_folder_permissions, get_products, install_product from OFS.Application import get_folder_permissions, get_products, install_product
from OFS.Folder import Folder from OFS.Folder import Folder
import Products import Products
...@@ -103,13 +119,12 @@ _theApp = Zope2.app() ...@@ -103,13 +119,12 @@ _theApp = Zope2.app()
_installedProducts = {} _installedProducts = {}
def hasProduct(name): def hasProduct(name):
'''Tests if a product can be found along Products.__path__''' '''Checks if a product can be found along Products.__path__'''
return name in [n[1] for n in get_products()] return name in [n[1] for n in get_products()]
def installProduct(name, quiet=0): def installProduct(name, quiet=0):
'''Installs a Zope product.''' '''Installs a Zope product.'''
start = time.time() start = time.time()
app = _theApp
meta_types = [] meta_types = []
if not _installedProducts.has_key(name): if not _installedProducts.has_key(name):
for priority, product_name, index, product_dir in get_products(): for priority, product_name, index, product_dir in get_products():
...@@ -117,7 +132,7 @@ def installProduct(name, quiet=0): ...@@ -117,7 +132,7 @@ def installProduct(name, quiet=0):
if not quiet: _print('Installing %s ... ' % product_name) if not quiet: _print('Installing %s ... ' % product_name)
# We want to fail immediately if a product throws an exception # We want to fail immediately if a product throws an exception
# during install, so we set the raise_exc flag. # during install, so we set the raise_exc flag.
install_product(app, product_dir, product_name, meta_types, install_product(_theApp, product_dir, product_name, meta_types,
get_folder_permissions(), raise_exc=1) get_folder_permissions(), raise_exc=1)
_installedProducts[product_name] = 1 _installedProducts[product_name] = 1
Products.meta_types = Products.meta_types + tuple(meta_types) Products.meta_types = Products.meta_types + tuple(meta_types)
...@@ -125,26 +140,30 @@ def installProduct(name, quiet=0): ...@@ -125,26 +140,30 @@ def installProduct(name, quiet=0):
if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) if not quiet: _print('done (%.3fs)\n' % (time.time() - start))
break break
else: else:
if name != 'SomeProduct': # Ignore the skeleton tests :-P if name != 'SomeProduct': # Ignore skeleton tests :-P
if not quiet: _print('Installing %s ... NOT FOUND\n' % name) if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
# Loading the Control_Panel of an existing ZODB may take def _load_control_panel():
# a while; print another dot if it does. # Loading the Control_Panel of an existing ZODB may take
_s = time.time(); _max = (_s - _start) / 4 # a while; print another dot if it does.
_exec('_theApp.Control_Panel') start = time.time()
_cp = _theApp.Control_Panel max = (start - _start) / 4
if hasattr(_cp, 'initialize_cache'): _exec('_theApp.Control_Panel')
_cp.initialize_cache() _theApp.Control_Panel
if (time.time() - _s) > _max: if (time.time() - start) > max:
_write('.') _write('.')
installProduct('PluginIndexes', 1) # Must install first def _install_products():
installProduct('OFSP', 1) installProduct('PluginIndexes', 1) # Must install first
#installProduct('ExternalMethod', 1) installProduct('OFSP', 1)
#installProduct('ZSQLMethods', 1) #installProduct('ExternalMethod', 1)
#installProduct('ZGadflyDA', 1) #installProduct('ZSQLMethods', 1)
#installProduct('MIMETools', 1) #installProduct('ZGadflyDA', 1)
#installProduct('MailHost', 1) #installProduct('MIMETools', 1)
#installProduct('MailHost', 1)
_load_control_panel()
_install_products()
# So people can use ZopeLite.app() # So people can use ZopeLite.app()
app = Zope2.app app = Zope2.app
...@@ -153,9 +172,11 @@ DB = Zope2.DB ...@@ -153,9 +172,11 @@ DB = Zope2.DB
configure = Zope2.configure configure = Zope2.configure
def startup(): pass def startup(): pass
# Provide a ZODB sandbox factory
from ZODB.DemoStorage import DemoStorage from ZODB.DemoStorage import DemoStorage
def sandbox(base=None): def sandbox(base=None):
'''Returns what amounts to a sandbox copy of the base ZODB.''' '''Returns a sandbox copy of the base ZODB.'''
if base is None: base = Zope2.DB if base is None: base = Zope2.DB
base_storage = base._storage base_storage = base._storage
quota = getattr(base_storage, '_quota', None) quota = getattr(base_storage, '_quota', None)
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
- Removed warnhook.py, we now use the one from ZODB.tests. - Removed warnhook.py, we now use the one from ZODB.tests.
- Removed doctest.py, we now use the one from zope.testing. - Removed doctest.py, we now use the one from zope.testing.
- Removed dochttp.py + test, we now use the one from zope.app.tests. - Removed dochttp.py + test, we now use the one from zope.app.tests.
- ZopeLite now takes care not to monkey patch an already running Zope.
0.9.6 0.9.6
- Dropped support for Zope 2.5 as it lacks the setSecurityManager() API. - Dropped support for Zope 2.5 as it lacks the setSecurityManager() API.
......
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