From e35dc1a58a4e91977dc9819c80259f09800a0b58 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 18 Aug 2008 04:06:35 +0000 Subject: - Generated application differences: ``make_app`` entry point renamed to ``app`` in order to have a different name than the bfg function of the same name, to prevent confusion. - Add "options" processing to bfg's ``make_app`` to support runtime options. A new API function named ``get_options`` was added to the registry module. This function is typically used in an application's ``app`` entry point. The Paste config file section for the app can now supply the ``reload_templates`` option, which, if true, will prevent the need to restart the appserver in order for ``z3c.pt`` or XSLT template changes to be detected. - Use only the module name in generated project's "test_suite" (run all tests found in the package). - Default port for generated apps changed from 5432 to 6543 (Postgres default port is 6543). --- repoze/bfg/registry.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'repoze/bfg/registry.py') diff --git a/repoze/bfg/registry.py b/repoze/bfg/registry.py index e1887bbdd..e02e5124e 100644 --- a/repoze/bfg/registry.py +++ b/repoze/bfg/registry.py @@ -6,9 +6,12 @@ from zope.component.interfaces import ComponentLookupError from zope.component.interfaces import IComponentLookup from zope.component.registry import Components from zope.component import getSiteManager as original_getSiteManager - from zope.configuration import xmlconfig +from zope.interface import implements + +from repoze.bfg.interfaces import ISettings + class ThreadLocalRegistryManager(threading.local): registry = getGlobalSiteManager() def set(self, registry): @@ -28,7 +31,7 @@ def setRegistryManager(manager): # for unit tests registry_manager = manager return old_registry_manager -def makeRegistry(filename, package, lock=threading.Lock()): +def makeRegistry(filename, package, options=None, lock=threading.Lock()): # This is absurd and probably not worth it. We want to try to # push our ZCML-defined configuration into an app-local component # registry in order to allow more than one bfg app to live in the @@ -50,12 +53,21 @@ def makeRegistry(filename, package, lock=threading.Lock()): original_getSiteManager.sethook(getSiteManager) zope.component.getGlobalSiteManager = registry_manager.get xmlconfig.file(filename, package=package) + if options is None: + options = {} + settings = Settings(options) + registry.registerUtility(settings, ISettings) return registry finally: zope.component.getGlobalSiteManager = getGlobalSiteManager lock.release() registry_manager.clear() +class Settings(object): + implements(ISettings) + def __init__(self, options): + self.reload_templates = options.get('reload_templates', False) + def getSiteManager(context=None): if context is None: return registry_manager.get() @@ -65,6 +77,14 @@ def getSiteManager(context=None): except TypeError, error: raise ComponentLookupError(*error.args) +def asbool(s): + s = str(s).strip() + return s.lower() in ('t', 'true', 'y', 'yes', 'on', '1') + +def get_options(kw): + reload_templates = asbool(kw.get('reload_templates')) + return {'reload_templates':reload_templates} + from zope.testing.cleanup import addCleanUp try: addCleanUp(original_getSiteManager.reset) -- cgit v1.2.3