18 # You should have received a copy of the GNU Lesser General Public License along |
18 # You should have received a copy of the GNU Lesser General Public License along |
19 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
19 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
20 |
20 |
21 """Pyramid interface to CubicWeb""" |
21 """Pyramid interface to CubicWeb""" |
22 |
22 |
|
23 import sys |
23 import atexit |
24 import atexit |
|
25 import logging |
24 from configparser import ConfigParser |
26 from configparser import ConfigParser |
25 import os |
27 import os |
26 import warnings |
28 import warnings |
27 |
29 |
28 import wsgicors |
30 import wsgicors |
29 |
31 |
30 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg |
32 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg |
31 from cubicweb.pyramid.debug_source_code import ( |
|
32 debug_display_source_code, |
|
33 DEBUG_DISPLAY_SOURCE_CODE_PATH, |
|
34 ) |
|
35 |
33 |
36 from pyramid.config import Configurator |
34 from pyramid.config import Configurator |
37 from pyramid.exceptions import ConfigurationError |
35 from pyramid.exceptions import ConfigurationError |
38 from pyramid.settings import asbool, aslist |
36 from pyramid.settings import asbool, aslist |
39 |
37 |
114 config.add_route('profile_ping', '_profile/ping') |
112 config.add_route('profile_ping', '_profile/ping') |
115 config.add_route('profile_cnx', '_profile/cnx') |
113 config.add_route('profile_cnx', '_profile/cnx') |
116 config.scan('cubicweb.pyramid.profile') |
114 config.scan('cubicweb.pyramid.profile') |
117 |
115 |
118 if debugtoolbar: |
116 if debugtoolbar: |
119 config.add_route('debug_display_source_code', DEBUG_DISPLAY_SOURCE_CODE_PATH) |
117 try: |
120 config.add_view(debug_display_source_code, route_name='debug_display_source_code') |
118 from cubicweb.pyramid.debug_source_code import ( |
|
119 debug_display_source_code, |
|
120 DEBUG_DISPLAY_SOURCE_CODE_PATH, |
|
121 ) |
|
122 except ImportError as e: |
|
123 logging.exception("Error: you tried to activate the debug toolbar but you have missing " |
|
124 "dependencies: %s" % e) |
|
125 |
|
126 sys.exit(1) |
|
127 else: |
|
128 config.add_route('debug_display_source_code', DEBUG_DISPLAY_SOURCE_CODE_PATH) |
|
129 config.add_view(debug_display_source_code, route_name='debug_display_source_code') |
121 |
130 |
122 app = config.make_wsgi_app() |
131 app = config.make_wsgi_app() |
123 # This replaces completely web/cors.py, which is not used by |
132 # This replaces completely web/cors.py, which is not used by |
124 # cubicweb.pyramid anymore |
133 # cubicweb.pyramid anymore |
125 app = wsgicors.CORS( |
134 app = wsgicors.CORS( |