author | Laurent Peuch <cortex@worlddomination.be> |
Tue, 08 Oct 2019 22:14:06 +0200 | |
changeset 12771 | 70597b447fb7 |
parent 12762 | f14dde905818 |
child 12782 | ea8801f10a72 |
permissions | -rw-r--r-- |
11967
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
1 |
# copyright 2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
2 |
# copyright 2014-2016 UNLISH S.A.S. (Montpellier, FRANCE), all rights reserved. |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
3 |
# |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
4 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
5 |
# |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
6 |
# This file is part of CubicWeb. |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
7 |
# |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
8 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
9 |
# terms of the GNU Lesser General Public License as published by the Free |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
10 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
11 |
# any later version. |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
12 |
# |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
13 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
14 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
15 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
16 |
# details. |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
17 |
# |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
18 |
# You should have received a copy of the GNU Lesser General Public License along |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
19 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
20 |
|
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
21 |
"""Pyramid interface to CubicWeb""" |
83739be20fab
[pyramid] Add a copyright and docstring to all modules
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11959
diff
changeset
|
22 |
|
12052
1a1d2f5faddb
[pyramid] Call repository's shutdown method atexit
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12025
diff
changeset
|
23 |
import atexit |
12587
6b08ba99b40e
DeprecationWarning: The SafeConfigParser class has been renamed to ConfigParser in Python 3.2. This alias will be removed in future versions. Use ConfigParser directly instead.
Laurent Peuch <cortex@worlddomination.be>
parents:
12567
diff
changeset
|
24 |
from configparser import ConfigParser |
11503
ddf61aa73384
Add a wsgi application factory suitable for wsgi servers.
Christophe de Vienne <christophe@unlish.com>
parents:
11501
diff
changeset
|
25 |
import os |
12186
36f1c7ab9010
[pyramid] Only expose 'cubicweb.bwcompat' setting for "all-in-one" configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12137
diff
changeset
|
26 |
import warnings |
12052
1a1d2f5faddb
[pyramid] Call repository's shutdown method atexit
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12025
diff
changeset
|
27 |
|
11511
13e0f569684c
Use 'wsgicors' for CORS handling.
Christophe de Vienne <christophe@unlish.com>
parents:
11503
diff
changeset
|
28 |
import wsgicors |
11503
ddf61aa73384
Add a wsgi application factory suitable for wsgi servers.
Christophe de Vienne <christophe@unlish.com>
parents:
11501
diff
changeset
|
29 |
|
ddf61aa73384
Add a wsgi application factory suitable for wsgi servers.
Christophe de Vienne <christophe@unlish.com>
parents:
11501
diff
changeset
|
30 |
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg |
12771
70597b447fb7
[debug-toolbar/display_source_code] add a pyramid view that display syntax highlighted python source file
Laurent Peuch <cortex@worlddomination.be>
parents:
12762
diff
changeset
|
31 |
from cubicweb.pyramid.debug_source_code import debug_display_source_code, DEBUG_DISPLAY_SOURCE_CODE_PATH |
70597b447fb7
[debug-toolbar/display_source_code] add a pyramid view that display syntax highlighted python source file
Laurent Peuch <cortex@worlddomination.be>
parents:
12762
diff
changeset
|
32 |
|
11501
fcf7f99fad4a
Add a make_cubicweb_application function
Christophe de Vienne <christophe@unlish.com>
parents:
11492
diff
changeset
|
33 |
from pyramid.config import Configurator |
11970
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
34 |
from pyramid.exceptions import ConfigurationError |
11534
ceb1a5baca4f
[config] Read pyramid settings in a 'pyramid.ini' file
Christophe de Vienne <christophe@unlish.com>
parents:
11532
diff
changeset
|
35 |
from pyramid.settings import asbool, aslist |
ceb1a5baca4f
[config] Read pyramid settings in a 'pyramid.ini' file
Christophe de Vienne <christophe@unlish.com>
parents:
11532
diff
changeset
|
36 |
|
11501
fcf7f99fad4a
Add a make_cubicweb_application function
Christophe de Vienne <christophe@unlish.com>
parents:
11492
diff
changeset
|
37 |
|
12751
30b205676182
[pyramid/ctl] add a new option to activate the debugtoolbar (-t)
Laurent Peuch <cortex@worlddomination.be>
parents:
12587
diff
changeset
|
38 |
def config_from_cwconfig(cwconfig, settings=None, debugtoolbar=False): |
11958
950ce7d9f642
[pyramid] Rename make_cubicweb_application function as config_from_cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11811
diff
changeset
|
39 |
"""Return a Pyramid Configurator instance built from a CubicWeb config and |
950ce7d9f642
[pyramid] Rename make_cubicweb_application function as config_from_cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11811
diff
changeset
|
40 |
Pyramid-specific configuration files (pyramid.ini). |
11537
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
41 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
42 |
:param cwconfig: A CubicWeb configuration |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
43 |
:returns: A Pyramid config object |
11501
fcf7f99fad4a
Add a make_cubicweb_application function
Christophe de Vienne <christophe@unlish.com>
parents:
11492
diff
changeset
|
44 |
""" |
11620
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
45 |
settings = dict(settings) if settings else {} |
12751
30b205676182
[pyramid/ctl] add a new option to activate the debugtoolbar (-t)
Laurent Peuch <cortex@worlddomination.be>
parents:
12587
diff
changeset
|
46 |
settings.update(settings_from_cwconfig(cwconfig, debugtoolbar=debugtoolbar)) |
11620
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
47 |
config = Configurator(settings=settings) |
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
48 |
config.registry['cubicweb.config'] = cwconfig |
11631
faf279e33298
Merge with pyramid-cubicweb
Yann Voté <yann.vote@logilab.fr>
parents:
11623
diff
changeset
|
49 |
config.include('cubicweb.pyramid') |
12751
30b205676182
[pyramid/ctl] add a new option to activate the debugtoolbar (-t)
Laurent Peuch <cortex@worlddomination.be>
parents:
12587
diff
changeset
|
50 |
|
30b205676182
[pyramid/ctl] add a new option to activate the debugtoolbar (-t)
Laurent Peuch <cortex@worlddomination.be>
parents:
12587
diff
changeset
|
51 |
if debugtoolbar: |
30b205676182
[pyramid/ctl] add a new option to activate the debugtoolbar (-t)
Laurent Peuch <cortex@worlddomination.be>
parents:
12587
diff
changeset
|
52 |
config.include("pyramid_debugtoolbar") |
30b205676182
[pyramid/ctl] add a new option to activate the debugtoolbar (-t)
Laurent Peuch <cortex@worlddomination.be>
parents:
12587
diff
changeset
|
53 |
|
11620
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
54 |
return config |
11534
ceb1a5baca4f
[config] Read pyramid settings in a 'pyramid.ini' file
Christophe de Vienne <christophe@unlish.com>
parents:
11532
diff
changeset
|
55 |
|
11811
f09efeead7f9
Fix broken flake8 configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11702
diff
changeset
|
56 |
|
12751
30b205676182
[pyramid/ctl] add a new option to activate the debugtoolbar (-t)
Laurent Peuch <cortex@worlddomination.be>
parents:
12587
diff
changeset
|
57 |
def settings_from_cwconfig(cwconfig, debugtoolbar=False): |
11620
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
58 |
''' |
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
59 |
Extract settings from pyramid.ini and pyramid-debug.ini (if in debug) |
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
60 |
|
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
61 |
Can be used to configure middleware WSGI with settings from pyramid.ini files |
11534
ceb1a5baca4f
[config] Read pyramid settings in a 'pyramid.ini' file
Christophe de Vienne <christophe@unlish.com>
parents:
11532
diff
changeset
|
62 |
|
11620
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
63 |
:param cwconfig: A CubicWeb configuration |
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
64 |
:returns: A settings dictionnary |
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
65 |
''' |
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
66 |
settings_filenames = [os.path.join(cwconfig.apphome, 'pyramid.ini')] |
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
67 |
settings = {} |
11501
fcf7f99fad4a
Add a make_cubicweb_application function
Christophe de Vienne <christophe@unlish.com>
parents:
11492
diff
changeset
|
68 |
if cwconfig.debugmode: |
11534
ceb1a5baca4f
[config] Read pyramid settings in a 'pyramid.ini' file
Christophe de Vienne <christophe@unlish.com>
parents:
11532
diff
changeset
|
69 |
settings_filenames.insert( |
ceb1a5baca4f
[config] Read pyramid settings in a 'pyramid.ini' file
Christophe de Vienne <christophe@unlish.com>
parents:
11532
diff
changeset
|
70 |
0, os.path.join(cwconfig.apphome, 'pyramid-debug.ini')) |
11811
f09efeead7f9
Fix broken flake8 configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11702
diff
changeset
|
71 |
|
11501
fcf7f99fad4a
Add a make_cubicweb_application function
Christophe de Vienne <christophe@unlish.com>
parents:
11492
diff
changeset
|
72 |
settings.update({ |
fcf7f99fad4a
Add a make_cubicweb_application function
Christophe de Vienne <christophe@unlish.com>
parents:
11492
diff
changeset
|
73 |
'pyramid.debug_authorization': True, |
fcf7f99fad4a
Add a make_cubicweb_application function
Christophe de Vienne <christophe@unlish.com>
parents:
11492
diff
changeset
|
74 |
'pyramid.debug_notfound': True, |
fcf7f99fad4a
Add a make_cubicweb_application function
Christophe de Vienne <christophe@unlish.com>
parents:
11492
diff
changeset
|
75 |
'pyramid.debug_routematch': True, |
11567
4f8aa5fcd5da
[debug] The debug mode now set pyramid.reload_templates
Christophe de Vienne <christophe@unlish.com>
parents:
11564
diff
changeset
|
76 |
'pyramid.reload_templates': True, |
11501
fcf7f99fad4a
Add a make_cubicweb_application function
Christophe de Vienne <christophe@unlish.com>
parents:
11492
diff
changeset
|
77 |
}) |
11811
f09efeead7f9
Fix broken flake8 configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11702
diff
changeset
|
78 |
|
12762
f14dde905818
[pyramid/ctl/debugtoolbar] automatically include custom panels on -t
Laurent Peuch <cortex@worlddomination.be>
parents:
12751
diff
changeset
|
79 |
if debugtoolbar: |
f14dde905818
[pyramid/ctl/debugtoolbar] automatically include custom panels on -t
Laurent Peuch <cortex@worlddomination.be>
parents:
12751
diff
changeset
|
80 |
settings["debugtoolbar.includes"] = ["cubicweb.pyramid.debugtoolbar_panels"] |
f14dde905818
[pyramid/ctl/debugtoolbar] automatically include custom panels on -t
Laurent Peuch <cortex@worlddomination.be>
parents:
12751
diff
changeset
|
81 |
|
11534
ceb1a5baca4f
[config] Read pyramid settings in a 'pyramid.ini' file
Christophe de Vienne <christophe@unlish.com>
parents:
11532
diff
changeset
|
82 |
for fname in settings_filenames: |
ceb1a5baca4f
[config] Read pyramid settings in a 'pyramid.ini' file
Christophe de Vienne <christophe@unlish.com>
parents:
11532
diff
changeset
|
83 |
if os.path.exists(fname): |
12587
6b08ba99b40e
DeprecationWarning: The SafeConfigParser class has been renamed to ConfigParser in Python 3.2. This alias will be removed in future versions. Use ConfigParser directly instead.
Laurent Peuch <cortex@worlddomination.be>
parents:
12567
diff
changeset
|
84 |
cp = ConfigParser() |
11534
ceb1a5baca4f
[config] Read pyramid settings in a 'pyramid.ini' file
Christophe de Vienne <christophe@unlish.com>
parents:
11532
diff
changeset
|
85 |
cp.read(fname) |
ceb1a5baca4f
[config] Read pyramid settings in a 'pyramid.ini' file
Christophe de Vienne <christophe@unlish.com>
parents:
11532
diff
changeset
|
86 |
settings.update(cp.items('main')) |
ceb1a5baca4f
[config] Read pyramid settings in a 'pyramid.ini' file
Christophe de Vienne <christophe@unlish.com>
parents:
11532
diff
changeset
|
87 |
break |
11811
f09efeead7f9
Fix broken flake8 configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11702
diff
changeset
|
88 |
|
11620
2497bcf18030
split collecting setting before using them, so the function can be reused when inserting WSGI middlewares
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
11601
diff
changeset
|
89 |
return settings |
11503
ddf61aa73384
Add a wsgi application factory suitable for wsgi servers.
Christophe de Vienne <christophe@unlish.com>
parents:
11501
diff
changeset
|
90 |
|
ddf61aa73384
Add a wsgi application factory suitable for wsgi servers.
Christophe de Vienne <christophe@unlish.com>
parents:
11501
diff
changeset
|
91 |
|
11535
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
92 |
def wsgi_application_from_cwconfig( |
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
93 |
cwconfig, |
12751
30b205676182
[pyramid/ctl] add a new option to activate the debugtoolbar (-t)
Laurent Peuch <cortex@worlddomination.be>
parents:
12587
diff
changeset
|
94 |
profile=False, profile_output=None, profile_dump_every=None, debugtoolbar=False): |
11537
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
95 |
""" Build a WSGI application from a cubicweb configuration |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
96 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
97 |
:param cwconfig: A CubicWeb configuration |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
98 |
:param profile: Enable profiling. See :ref:`profiling`. |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
99 |
:param profile_output: Profiling output filename. See :ref:`profiling`. |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
100 |
:param profile_dump_every: Profiling number of requests before dumping the |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
101 |
stats. See :ref:`profiling`. |
12751
30b205676182
[pyramid/ctl] add a new option to activate the debugtoolbar (-t)
Laurent Peuch <cortex@worlddomination.be>
parents:
12587
diff
changeset
|
102 |
:param debugtoolbar: Activate pyramid debugtoolbar when True. |
11537
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
103 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
104 |
:returns: A fully operationnal WSGI application |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
105 |
""" |
12751
30b205676182
[pyramid/ctl] add a new option to activate the debugtoolbar (-t)
Laurent Peuch <cortex@worlddomination.be>
parents:
12587
diff
changeset
|
106 |
config = config_from_cwconfig(cwconfig, debugtoolbar=debugtoolbar) |
30b205676182
[pyramid/ctl] add a new option to activate the debugtoolbar (-t)
Laurent Peuch <cortex@worlddomination.be>
parents:
12587
diff
changeset
|
107 |
|
11535
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
108 |
profile = profile or asbool(config.registry.settings.get( |
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
109 |
'cubicweb.profile.enable', False)) |
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
110 |
if profile: |
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
111 |
config.add_route('profile_ping', '_profile/ping') |
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
112 |
config.add_route('profile_cnx', '_profile/cnx') |
11631
faf279e33298
Merge with pyramid-cubicweb
Yann Voté <yann.vote@logilab.fr>
parents:
11623
diff
changeset
|
113 |
config.scan('cubicweb.pyramid.profile') |
12771
70597b447fb7
[debug-toolbar/display_source_code] add a pyramid view that display syntax highlighted python source file
Laurent Peuch <cortex@worlddomination.be>
parents:
12762
diff
changeset
|
114 |
|
70597b447fb7
[debug-toolbar/display_source_code] add a pyramid view that display syntax highlighted python source file
Laurent Peuch <cortex@worlddomination.be>
parents:
12762
diff
changeset
|
115 |
if debugtoolbar: |
70597b447fb7
[debug-toolbar/display_source_code] add a pyramid view that display syntax highlighted python source file
Laurent Peuch <cortex@worlddomination.be>
parents:
12762
diff
changeset
|
116 |
config.add_route('debug_display_source_code', DEBUG_DISPLAY_SOURCE_CODE_PATH) |
70597b447fb7
[debug-toolbar/display_source_code] add a pyramid view that display syntax highlighted python source file
Laurent Peuch <cortex@worlddomination.be>
parents:
12762
diff
changeset
|
117 |
config.add_view(debug_display_source_code, route_name='debug_display_source_code') |
70597b447fb7
[debug-toolbar/display_source_code] add a pyramid view that display syntax highlighted python source file
Laurent Peuch <cortex@worlddomination.be>
parents:
12762
diff
changeset
|
118 |
|
11511
13e0f569684c
Use 'wsgicors' for CORS handling.
Christophe de Vienne <christophe@unlish.com>
parents:
11503
diff
changeset
|
119 |
app = config.make_wsgi_app() |
13e0f569684c
Use 'wsgicors' for CORS handling.
Christophe de Vienne <christophe@unlish.com>
parents:
11503
diff
changeset
|
120 |
# This replaces completely web/cors.py, which is not used by |
11631
faf279e33298
Merge with pyramid-cubicweb
Yann Voté <yann.vote@logilab.fr>
parents:
11623
diff
changeset
|
121 |
# cubicweb.pyramid anymore |
11511
13e0f569684c
Use 'wsgicors' for CORS handling.
Christophe de Vienne <christophe@unlish.com>
parents:
11503
diff
changeset
|
122 |
app = wsgicors.CORS( |
13e0f569684c
Use 'wsgicors' for CORS handling.
Christophe de Vienne <christophe@unlish.com>
parents:
11503
diff
changeset
|
123 |
app, |
11532
6a1d0aa3ac85
Fix cors 'origin' parameter passing
Christophe de Vienne <christophe@unlish.com>
parents:
11522
diff
changeset
|
124 |
origin=' '.join(cwconfig['access-control-allow-origin']), |
11547
fd7d2033cd80
[cors] Fix 'headers' and 'methods' parameters
Christophe de Vienne <christophe@unlish.com>
parents:
11540
diff
changeset
|
125 |
headers=', '.join(cwconfig['access-control-allow-headers']), |
12198
be4824a72bf5
[cubicweb/pyramid] take into account two ignored CORS configuration items from all-in-one.conf
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
12186
diff
changeset
|
126 |
expose_headers=', '.join(cwconfig['access-control-expose-headers']), |
11547
fd7d2033cd80
[cors] Fix 'headers' and 'methods' parameters
Christophe de Vienne <christophe@unlish.com>
parents:
11540
diff
changeset
|
127 |
methods=', '.join(cwconfig['access-control-allow-methods']), |
12198
be4824a72bf5
[cubicweb/pyramid] take into account two ignored CORS configuration items from all-in-one.conf
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
12186
diff
changeset
|
128 |
maxage=cwconfig['access-control-max-age'], |
11511
13e0f569684c
Use 'wsgicors' for CORS handling.
Christophe de Vienne <christophe@unlish.com>
parents:
11503
diff
changeset
|
129 |
credentials='true') |
11535
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
130 |
|
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
131 |
if profile: |
11631
faf279e33298
Merge with pyramid-cubicweb
Yann Voté <yann.vote@logilab.fr>
parents:
11623
diff
changeset
|
132 |
from cubicweb.pyramid.profile import wsgi_profile |
11535
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
133 |
filename = profile_output or config.registry.settings.get( |
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
134 |
'cubicweb.profile.output', 'program.prof') |
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
135 |
dump_every = profile_dump_every or config.registry.settings.get( |
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
136 |
'cubicweb.profile.dump_every', 100) |
dd875009cc47
[profile] Add a profiling tool
Christophe de Vienne <christophe@unlish.com>
parents:
11534
diff
changeset
|
137 |
app = wsgi_profile(app, filename=filename, dump_every=dump_every) |
11511
13e0f569684c
Use 'wsgicors' for CORS handling.
Christophe de Vienne <christophe@unlish.com>
parents:
11503
diff
changeset
|
138 |
return app |
11522
568204930c85
Provides a full wsgi cubicweb application builder
Christophe de Vienne <christophe@unlish.com>
parents:
11511
diff
changeset
|
139 |
|
568204930c85
Provides a full wsgi cubicweb application builder
Christophe de Vienne <christophe@unlish.com>
parents:
11511
diff
changeset
|
140 |
|
568204930c85
Provides a full wsgi cubicweb application builder
Christophe de Vienne <christophe@unlish.com>
parents:
11511
diff
changeset
|
141 |
def wsgi_application(instance_name=None, debug=None): |
11537
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
142 |
""" Build a WSGI application from a cubicweb instance name |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
143 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
144 |
:param instance_name: Name of the cubicweb instance (optional). If not |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
145 |
provided, :envvar:`CW_INSTANCE` must exists. |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
146 |
:param debug: Enable/disable the debug mode. If defined to True or False, |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
147 |
overrides :envvar:`CW_DEBUG`. |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
148 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
149 |
The following environment variables are used if they exist: |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
150 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
151 |
.. envvar:: CW_INSTANCE |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
152 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
153 |
A CubicWeb instance name. |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
154 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
155 |
.. envvar:: CW_DEBUG |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
156 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
157 |
If defined, the debugmode is enabled. |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
158 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
159 |
The function can be used as an entry-point for third-party wsgi containers. |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
160 |
Below is a sample uswgi configuration file: |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
161 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
162 |
.. code-block:: ini |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
163 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
164 |
[uwsgi] |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
165 |
http = 127.0.1.1:8080 |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
166 |
env = CW_INSTANCE=myinstance |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
167 |
env = CW_DEBUG=1 |
11631
faf279e33298
Merge with pyramid-cubicweb
Yann Voté <yann.vote@logilab.fr>
parents:
11623
diff
changeset
|
168 |
module = cubicweb.pyramid:wsgi_application() |
11537
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
169 |
virtualenv = /home/user/.virtualenvs/myvirtualenv |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
170 |
processes = 1 |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
171 |
threads = 8 |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
172 |
stats = 127.0.0.1:9191 |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
173 |
plugins = http,python |
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
174 |
|
caf268942436
Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
11535
diff
changeset
|
175 |
""" |
11522
568204930c85
Provides a full wsgi cubicweb application builder
Christophe de Vienne <christophe@unlish.com>
parents:
11511
diff
changeset
|
176 |
if instance_name is None: |
11623
b6f6737d4823
wsgi: clearer exception when CW_INSTANCE is missing
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11620
diff
changeset
|
177 |
instance_name = os.environ['CW_INSTANCE'] |
11522
568204930c85
Provides a full wsgi cubicweb application builder
Christophe de Vienne <christophe@unlish.com>
parents:
11511
diff
changeset
|
178 |
if debug is None: |
568204930c85
Provides a full wsgi cubicweb application builder
Christophe de Vienne <christophe@unlish.com>
parents:
11511
diff
changeset
|
179 |
debug = 'CW_DEBUG' in os.environ |
568204930c85
Provides a full wsgi cubicweb application builder
Christophe de Vienne <christophe@unlish.com>
parents:
11511
diff
changeset
|
180 |
|
568204930c85
Provides a full wsgi cubicweb application builder
Christophe de Vienne <christophe@unlish.com>
parents:
11511
diff
changeset
|
181 |
cwconfig = cwcfg.config_for(instance_name, debugmode=debug) |
568204930c85
Provides a full wsgi cubicweb application builder
Christophe de Vienne <christophe@unlish.com>
parents:
11511
diff
changeset
|
182 |
|
568204930c85
Provides a full wsgi cubicweb application builder
Christophe de Vienne <christophe@unlish.com>
parents:
11511
diff
changeset
|
183 |
return wsgi_application_from_cwconfig(cwconfig) |
11586
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
184 |
|
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
185 |
|
11968
bb0dfc7d2d0e
[skeleton,pyramid] Move pyramid app definition in cubicweb.pyramid module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11967
diff
changeset
|
186 |
def pyramid_app(global_config, **settings): |
bb0dfc7d2d0e
[skeleton,pyramid] Move pyramid app definition in cubicweb.pyramid module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11967
diff
changeset
|
187 |
"""Return a Pyramid WSGI application bound to a CubicWeb repository.""" |
bb0dfc7d2d0e
[skeleton,pyramid] Move pyramid app definition in cubicweb.pyramid module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11967
diff
changeset
|
188 |
config = Configurator(settings=settings) |
bb0dfc7d2d0e
[skeleton,pyramid] Move pyramid app definition in cubicweb.pyramid module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11967
diff
changeset
|
189 |
config.include('cubicweb.pyramid') |
bb0dfc7d2d0e
[skeleton,pyramid] Move pyramid app definition in cubicweb.pyramid module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11967
diff
changeset
|
190 |
return config.make_wsgi_app() |
bb0dfc7d2d0e
[skeleton,pyramid] Move pyramid app definition in cubicweb.pyramid module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11967
diff
changeset
|
191 |
|
bb0dfc7d2d0e
[skeleton,pyramid] Move pyramid app definition in cubicweb.pyramid module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11967
diff
changeset
|
192 |
|
11586
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
193 |
def includeme(config): |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
194 |
"""Set-up a CubicWeb instance. |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
195 |
|
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
196 |
The CubicWeb instance can be set in several ways: |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
197 |
|
11970
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
198 |
- Provide an already loaded CubicWeb repository in the registry: |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
199 |
|
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
200 |
.. code-block:: python |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
201 |
|
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
202 |
config.registry['cubicweb.repository'] = your_repo_instance |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
203 |
|
11586
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
204 |
- Provide an already loaded CubicWeb config instance in the registry: |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
205 |
|
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
206 |
.. code-block:: python |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
207 |
|
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
208 |
config.registry['cubicweb.config'] = your_config_instance |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
209 |
|
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
210 |
- Provide an instance name in the pyramid settings with |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
211 |
:confval:`cubicweb.instance`. |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
212 |
|
11970
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
213 |
A CubicWeb repository is instantiated and attached in |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
214 |
'cubicweb.repository' registry key if not already present. |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
215 |
|
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
216 |
The CubicWeb instance registry is attached in 'cubicweb.registry' registry |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
217 |
key. |
11586
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
218 |
""" |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
219 |
cwconfig = config.registry.get('cubicweb.config') |
11970
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
220 |
repo = config.registry.get('cubicweb.repository') |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
221 |
|
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
222 |
if repo is not None: |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
223 |
if cwconfig is None: |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
224 |
config.registry['cubicweb.config'] = cwconfig = repo.config |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
225 |
elif cwconfig is not repo.config: |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
226 |
raise ConfigurationError( |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
227 |
'CubicWeb config instance (found in "cubicweb.config" ' |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
228 |
'registry key) mismatches with that of the repository ' |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
229 |
'(registry["cubicweb.repository"])' |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
230 |
) |
11586
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
231 |
|
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
232 |
if cwconfig is None: |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
233 |
debugmode = asbool( |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
234 |
config.registry.settings.get('cubicweb.debug', False)) |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
235 |
cwconfig = cwcfg.config_for( |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
236 |
config.registry.settings['cubicweb.instance'], debugmode=debugmode) |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
237 |
config.registry['cubicweb.config'] = cwconfig |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
238 |
|
11970
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
239 |
if repo is None: |
b282ef22b5ab
[pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11969
diff
changeset
|
240 |
repo = config.registry['cubicweb.repository'] = cwconfig.repository() |
11586
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
241 |
config.registry['cubicweb.registry'] = repo.vreg |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
242 |
|
12079
4870e5a60a52
[pyramid] Do not register repository.shutdown atexit in test mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12052
diff
changeset
|
243 |
if cwconfig.mode != 'test': |
12137
4db0f2251960
[pyramid] Avoid shutting down the repository at exit if it's already shutting down
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12101
diff
changeset
|
244 |
@atexit.register |
4db0f2251960
[pyramid] Avoid shutting down the repository at exit if it's already shutting down
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12101
diff
changeset
|
245 |
def shutdown_repo(): |
4db0f2251960
[pyramid] Avoid shutting down the repository at exit if it's already shutting down
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12101
diff
changeset
|
246 |
if repo.shutting_down: |
4db0f2251960
[pyramid] Avoid shutting down the repository at exit if it's already shutting down
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12101
diff
changeset
|
247 |
return |
4db0f2251960
[pyramid] Avoid shutting down the repository at exit if it's already shutting down
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12101
diff
changeset
|
248 |
repo.shutdown |
12052
1a1d2f5faddb
[pyramid] Call repository's shutdown method atexit
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12025
diff
changeset
|
249 |
|
11586
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
250 |
if asbool(config.registry.settings.get('cubicweb.defaults', True)): |
11631
faf279e33298
Merge with pyramid-cubicweb
Yann Voté <yann.vote@logilab.fr>
parents:
11623
diff
changeset
|
251 |
config.include('cubicweb.pyramid.defaults') |
11586
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
252 |
|
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
253 |
for name in aslist(config.registry.settings.get('cubicweb.includes', [])): |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
254 |
config.include(name) |
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
255 |
|
11631
faf279e33298
Merge with pyramid-cubicweb
Yann Voté <yann.vote@logilab.fr>
parents:
11623
diff
changeset
|
256 |
config.include('cubicweb.pyramid.core') |
11586
c7a25122af4d
[config] Move most config code to a includeme()
Christophe de Vienne <christophe@unlish.com>
parents:
11567
diff
changeset
|
257 |
|
12186
36f1c7ab9010
[pyramid] Only expose 'cubicweb.bwcompat' setting for "all-in-one" configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12137
diff
changeset
|
258 |
if asbool(config.registry.settings.get('cubicweb.bwcompat', |
36f1c7ab9010
[pyramid] Only expose 'cubicweb.bwcompat' setting for "all-in-one" configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12137
diff
changeset
|
259 |
cwconfig.name == 'all-in-one')): |
36f1c7ab9010
[pyramid] Only expose 'cubicweb.bwcompat' setting for "all-in-one" configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12137
diff
changeset
|
260 |
if cwconfig.name != 'all-in-one': |
36f1c7ab9010
[pyramid] Only expose 'cubicweb.bwcompat' setting for "all-in-one" configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12137
diff
changeset
|
261 |
warnings.warn('"cubicweb.bwcompat" setting only applies to ' |
36f1c7ab9010
[pyramid] Only expose 'cubicweb.bwcompat' setting for "all-in-one" configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12137
diff
changeset
|
262 |
'"all-in-one" instance configuration', |
36f1c7ab9010
[pyramid] Only expose 'cubicweb.bwcompat' setting for "all-in-one" configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12137
diff
changeset
|
263 |
UserWarning) |
36f1c7ab9010
[pyramid] Only expose 'cubicweb.bwcompat' setting for "all-in-one" configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12137
diff
changeset
|
264 |
else: |
36f1c7ab9010
[pyramid] Only expose 'cubicweb.bwcompat' setting for "all-in-one" configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12137
diff
changeset
|
265 |
config.include('cubicweb.pyramid.bwcompat') |