split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
authorArthur Lutz <arthur.lutz@logilab.fr>
Fri, 17 Jun 2016 17:57:11 +0200
changeset 11620 2497bcf18030
parent 11619 be13b3ea71de
child 11621 5747d4c2e083
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
pyramid_cubicweb/__init__.py
--- a/pyramid_cubicweb/__init__.py	Thu Jun 02 12:11:07 2016 +0200
+++ b/pyramid_cubicweb/__init__.py	Fri Jun 17 17:57:11 2016 +0200
@@ -21,33 +21,43 @@
     :param cwconfig: A CubicWeb configuration
     :returns: A Pyramid config object
     """
-    settings_filenames = [os.path.join(cwconfig.apphome, 'pyramid.ini')]
+    settings = dict(settings) if settings else {}
+    settings.update(settings_from_cwconfig(cwconfig))
+    config = Configurator(settings=settings)
+    config.registry['cubicweb.config'] = cwconfig
+    config.include('pyramid_cubicweb')
+    return config
 
-    settings = dict(settings) if settings else {}
+def settings_from_cwconfig(cwconfig):
+    '''
+    Extract settings from pyramid.ini and pyramid-debug.ini (if in debug)
+
+    Can be used to configure middleware WSGI with settings from pyramid.ini files
 
+    :param cwconfig: A CubicWeb configuration
+    :returns: A settings dictionnary
+    '''
+    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,
             'pyramid.reload_templates': 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)
-    config.registry['cubicweb.config'] = cwconfig
-    config.include('pyramid_cubicweb')
-
-    return config
+    
+    return settings
 
 
 def wsgi_application_from_cwconfig(