wsgi/wz.py
author Rémi Cardona <remi.cardona@logilab.fr>
Tue, 15 Sep 2015 16:56:57 +0200
changeset 10609 e2d8e81bfe68
parent 10105 a1e8816029af
permissions -rw-r--r--
[py3k] import range using six.moves
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9288
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     1
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     3
#
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     4
# This file is part of CubicWeb.
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     5
#
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     9
# any later version.
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    10
#
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    14
# details.
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    15
#
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    18
"""dummy wsgi server for CubicWeb web instances"""
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    19
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    20
__docformat__ = "restructuredtext en"
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    21
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    22
import socket
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    23
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    24
from cubicweb.wsgi.handler import CubicWebWSGIApplication
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    25
from cubicweb import ConfigurationError
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    26
from werkzeug.serving import run_simple
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    27
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    28
from logging import getLogger
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    29
LOGGER = getLogger('cubicweb')
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    30
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    31
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    32
def run(config):
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    33
    config.check_writeable_uid_directory(config.appdatahome)
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    34
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    35
    port = config['port'] or 8080
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    36
    interface = config['interface']
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    37
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    38
    app = CubicWebWSGIApplication(config)
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    39
    repo = app.appli.repo
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    40
    try:
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    41
        repo.start_looping_tasks()
10105
a1e8816029af [wsgi] add message about the active interface
Alain Leufroy <alain@leufroy.fr>
parents: 9288
diff changeset
    42
        LOGGER.info('starting http server on %s', config['base-url'])
9288
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    43
        run_simple(interface, port, app,
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    44
                   threaded=True,
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    45
                   use_debugger=True,
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    46
                   processes=1) # more processes yield weird errors
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    47
    finally:
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    48
        repo.shutdown()