# HG changeset patch # User Christophe de Vienne # Date 1420248966 -3600 # Node ID ceb1a5baca4fe54a0ffe9adf5c8c5180bdaea9cb # Parent 4ced3782b90fe406c802b3085cdf1dd9e1a30398 [config] Read pyramid settings in a 'pyramid.ini' file If a 'pyramid-debug.ini' file is present, it will be used instead when debugmode is on. Closes #4811298 diff -r 4ced3782b90f -r ceb1a5baca4f pyramid_cubicweb/__init__.py --- a/pyramid_cubicweb/__init__.py Sat Jan 03 01:24:38 2015 +0100 +++ b/pyramid_cubicweb/__init__.py Sat Jan 03 02:36:06 2015 +0100 @@ -3,6 +3,12 @@ from cubicweb.cwconfig import CubicWebConfiguration as cwcfg from pyramid.config import Configurator +from pyramid.settings import asbool, aslist + +try: + from configparser import SafeConfigParser +except ImportError: + from ConfigParser import SafeConfigParser def make_cubicweb_application(cwconfig): @@ -11,24 +17,44 @@ It is initialy meant to be used by the 'pyramid' command of cubicweb-ctl. """ - settings = { - 'session.secret': '11', # XXX - } + settings_filenames = [os.path.join(cwconfig.apphome, 'pyramid.ini')] + + settings = {} + if cwconfig.debugmode: + settings_filenames.insert( + 0, os.path.join(cwconfig.apphome, 'pyramid-debug.ini')) + settings.update({ 'pyramid.debug_authorization': True, 'pyramid.debug_notfound': True, 'pyramid.debug_routematch': True, }) + + for fname in settings_filenames: + if os.path.exists(fname): + cp = SafeConfigParser() + cp.read(fname) + settings.update(cp.items('main')) + break + config = Configurator(settings=settings) if cwconfig.debugmode: config.include('pyramid_debugtoolbar') config.registry['cubicweb.config'] = cwconfig config.registry['cubicweb.repository'] = repo = cwconfig.repository() config.registry['cubicweb.registry'] = repo.vreg - config.include('pyramid_cubicweb.defaults') + + if asbool(config.registry.settings.get('cubicweb.defaults', True)): + config.include('pyramid_cubicweb.defaults') + + for name in aslist(config.registry.settings.get('cubicweb.includes')): + config.include(name) + config.include('pyramid_cubicweb.core') - config.include('pyramid_cubicweb.bwcompat') + + if asbool(config.registry.settings.get('cubicweb.bwcompat', True)): + config.include('pyramid_cubicweb.bwcompat') return config