1 import os |
1 import os |
2 import wsgicors |
2 import wsgicors |
3 |
3 |
4 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg |
4 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg |
5 from pyramid.config import Configurator |
5 from pyramid.config import Configurator |
|
6 from pyramid.settings import asbool, aslist |
|
7 |
|
8 try: |
|
9 from configparser import SafeConfigParser |
|
10 except ImportError: |
|
11 from ConfigParser import SafeConfigParser |
6 |
12 |
7 |
13 |
8 def make_cubicweb_application(cwconfig): |
14 def make_cubicweb_application(cwconfig): |
9 """ |
15 """ |
10 Create a pyramid-based CubicWeb instance from a cubicweb configuration. |
16 Create a pyramid-based CubicWeb instance from a cubicweb configuration. |
11 |
17 |
12 It is initialy meant to be used by the 'pyramid' command of cubicweb-ctl. |
18 It is initialy meant to be used by the 'pyramid' command of cubicweb-ctl. |
13 """ |
19 """ |
14 settings = { |
20 settings_filenames = [os.path.join(cwconfig.apphome, 'pyramid.ini')] |
15 'session.secret': '11', # XXX |
21 |
16 } |
22 settings = {} |
|
23 |
17 if cwconfig.debugmode: |
24 if cwconfig.debugmode: |
|
25 settings_filenames.insert( |
|
26 0, os.path.join(cwconfig.apphome, 'pyramid-debug.ini')) |
|
27 |
18 settings.update({ |
28 settings.update({ |
19 'pyramid.debug_authorization': True, |
29 'pyramid.debug_authorization': True, |
20 'pyramid.debug_notfound': True, |
30 'pyramid.debug_notfound': True, |
21 'pyramid.debug_routematch': True, |
31 'pyramid.debug_routematch': True, |
22 }) |
32 }) |
|
33 |
|
34 for fname in settings_filenames: |
|
35 if os.path.exists(fname): |
|
36 cp = SafeConfigParser() |
|
37 cp.read(fname) |
|
38 settings.update(cp.items('main')) |
|
39 break |
|
40 |
23 config = Configurator(settings=settings) |
41 config = Configurator(settings=settings) |
24 if cwconfig.debugmode: |
42 if cwconfig.debugmode: |
25 config.include('pyramid_debugtoolbar') |
43 config.include('pyramid_debugtoolbar') |
26 config.registry['cubicweb.config'] = cwconfig |
44 config.registry['cubicweb.config'] = cwconfig |
27 config.registry['cubicweb.repository'] = repo = cwconfig.repository() |
45 config.registry['cubicweb.repository'] = repo = cwconfig.repository() |
28 config.registry['cubicweb.registry'] = repo.vreg |
46 config.registry['cubicweb.registry'] = repo.vreg |
29 config.include('pyramid_cubicweb.defaults') |
47 |
|
48 if asbool(config.registry.settings.get('cubicweb.defaults', True)): |
|
49 config.include('pyramid_cubicweb.defaults') |
|
50 |
|
51 for name in aslist(config.registry.settings.get('cubicweb.includes')): |
|
52 config.include(name) |
|
53 |
30 config.include('pyramid_cubicweb.core') |
54 config.include('pyramid_cubicweb.core') |
31 config.include('pyramid_cubicweb.bwcompat') |
55 |
|
56 if asbool(config.registry.settings.get('cubicweb.bwcompat', True)): |
|
57 config.include('pyramid_cubicweb.bwcompat') |
32 return config |
58 return config |
33 |
59 |
34 |
60 |
35 def wsgi_application_from_cwconfig(cwconfig): |
61 def wsgi_application_from_cwconfig(cwconfig): |
36 config = make_cubicweb_application(cwconfig) |
62 config = make_cubicweb_application(cwconfig) |