14 def make_cubicweb_application(cwconfig): |
14 def make_cubicweb_application(cwconfig): |
15 """ |
15 """ |
16 Create a pyramid-based CubicWeb instance from a cubicweb configuration. |
16 Create a pyramid-based CubicWeb instance from a cubicweb configuration. |
17 |
17 |
18 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. |
|
19 |
|
20 :param cwconfig: A CubicWeb configuration |
|
21 :returns: A Pyramid config object |
19 """ |
22 """ |
20 settings_filenames = [os.path.join(cwconfig.apphome, 'pyramid.ini')] |
23 settings_filenames = [os.path.join(cwconfig.apphome, 'pyramid.ini')] |
21 |
24 |
22 settings = {} |
25 settings = {} |
23 |
26 |
59 |
62 |
60 |
63 |
61 def wsgi_application_from_cwconfig( |
64 def wsgi_application_from_cwconfig( |
62 cwconfig, |
65 cwconfig, |
63 profile=False, profile_output=None, profile_dump_every=None): |
66 profile=False, profile_output=None, profile_dump_every=None): |
|
67 """ Build a WSGI application from a cubicweb configuration |
|
68 |
|
69 :param cwconfig: A CubicWeb configuration |
|
70 :param profile: Enable profiling. See :ref:`profiling`. |
|
71 :param profile_output: Profiling output filename. See :ref:`profiling`. |
|
72 :param profile_dump_every: Profiling number of requests before dumping the |
|
73 stats. See :ref:`profiling`. |
|
74 |
|
75 :returns: A fully operationnal WSGI application |
|
76 """ |
64 config = make_cubicweb_application(cwconfig) |
77 config = make_cubicweb_application(cwconfig) |
65 profile = profile or asbool(config.registry.settings.get( |
78 profile = profile or asbool(config.registry.settings.get( |
66 'cubicweb.profile.enable', False)) |
79 'cubicweb.profile.enable', False)) |
67 if profile: |
80 if profile: |
68 config.add_route('profile_ping', '_profile/ping') |
81 config.add_route('profile_ping', '_profile/ping') |
87 app = wsgi_profile(app, filename=filename, dump_every=dump_every) |
100 app = wsgi_profile(app, filename=filename, dump_every=dump_every) |
88 return app |
101 return app |
89 |
102 |
90 |
103 |
91 def wsgi_application(instance_name=None, debug=None): |
104 def wsgi_application(instance_name=None, debug=None): |
|
105 """ Build a WSGI application from a cubicweb instance name |
|
106 |
|
107 :param instance_name: Name of the cubicweb instance (optional). If not |
|
108 provided, :envvar:`CW_INSTANCE` must exists. |
|
109 :param debug: Enable/disable the debug mode. If defined to True or False, |
|
110 overrides :envvar:`CW_DEBUG`. |
|
111 |
|
112 The following environment variables are used if they exist: |
|
113 |
|
114 .. envvar:: CW_INSTANCE |
|
115 |
|
116 A CubicWeb instance name. |
|
117 |
|
118 .. envvar:: CW_DEBUG |
|
119 |
|
120 If defined, the debugmode is enabled. |
|
121 |
|
122 The function can be used as an entry-point for third-party wsgi containers. |
|
123 Below is a sample uswgi configuration file: |
|
124 |
|
125 .. code-block:: ini |
|
126 |
|
127 [uwsgi] |
|
128 http = 127.0.1.1:8080 |
|
129 env = CW_INSTANCE=myinstance |
|
130 env = CW_DEBUG=1 |
|
131 module = pyramid_cubicweb:wsgi_application() |
|
132 virtualenv = /home/user/.virtualenvs/myvirtualenv |
|
133 processes = 1 |
|
134 threads = 8 |
|
135 stats = 127.0.0.1:9191 |
|
136 plugins = http,python |
|
137 |
|
138 """ |
92 if instance_name is None: |
139 if instance_name is None: |
93 instance_name = os.environ.get('CW_INSTANCE') |
140 instance_name = os.environ.get('CW_INSTANCE') |
94 if debug is None: |
141 if debug is None: |
95 debug = 'CW_DEBUG' in os.environ |
142 debug = 'CW_DEBUG' in os.environ |
96 |
143 |