author | Rémi Cardona <remi.cardona@logilab.fr> |
Wed, 28 Jan 2015 11:51:16 +0100 | |
changeset 10164 | 2094262d6553 |
parent 9287 | e70c8c70e344 |
permissions | -rw-r--r-- |
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
1 |
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
3 |
# |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
4 |
# This file is part of CubicWeb. |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
5 |
# |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
9 |
# any later version. |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
10 |
# |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
14 |
# details. |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
15 |
# |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
18 |
"""dummy wsgi server for CubicWeb web instances""" |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
19 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
20 |
__docformat__ = "restructuredtext en" |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
21 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
22 |
from cubicweb.wsgi.handler import CubicWebWSGIApplication |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
23 |
from cubicweb import ConfigurationError |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
24 |
from wsgiref import simple_server |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
25 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
26 |
from logging import getLogger |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
27 |
LOGGER = getLogger('cubicweb') |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
28 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
29 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
30 |
def run(config): |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
31 |
config.check_writeable_uid_directory(config.appdatahome) |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
32 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
33 |
port = config['port'] or 8080 |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
34 |
interface = config['interface'] |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
35 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
36 |
app = CubicWebWSGIApplication(config) |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
37 |
handler_cls = simple_server.WSGIRequestHandler |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
38 |
httpd = simple_server.WSGIServer((interface, port), handler_cls) |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
39 |
httpd.set_app(app) |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
40 |
repo = app.appli.repo |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
41 |
try: |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
42 |
repo.start_looping_tasks() |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
43 |
LOGGER.info('starting http server on %s', config['base-url']) |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
44 |
httpd.serve_forever() |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
45 |
finally: |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff
changeset
|
46 |
repo.shutdown() |