cubicweb/wsgi/server.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Thu, 21 Mar 2019 14:33:54 +0100
changeset 12530 9d88e1177c35
parent 12001 89611a994572
permissions -rw-r--r--
Remove Twisted web server Twisted web server is not used anymore and has been superseded by pyramid many years ago. Furthermore, our usage is not compatible with Python 3. So we drop the "etwist" sub-package. As a consequence, "all-in-one" configuration type gets dropped as it was Twisted-specific. We resurrect it in cubicweb/pyramid/config.py by only keeping options used by the "pyramid". Similarly, we introduce a AllInOneCreateHandler in cubicweb/pyramid/pyramidctl.py that is basically the one that lived in cubicweb/etwist/twctl.py and is used to create the "all-in-one" instance. Added a TODO here about "pyramid.ini" that could be generated at the end of bootstrap() method. In cubicweb/devtools/httptest.py, CubicWebServerTC is now equivalent to CubicWebWsgiTC and the latter is dropped.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
11767
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
    20
9287
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
        LOGGER.info('starting http server on %s', config['base-url'])
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    43
        httpd.serve_forever()
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    44
    finally:
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    45
        repo.shutdown()