etwist/twconfig.py
changeset 11057 0b59724cb3f2
parent 11052 058bb3dc685f
child 11058 23eb30449fe5
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
     1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 """twisted server configurations:
       
    19 
       
    20 * the "all-in-one" configuration to get a web instance running in a twisted
       
    21   web server integrating a repository server in the same process (only available
       
    22   if the repository part of the software is installed
       
    23 """
       
    24 __docformat__ = "restructuredtext en"
       
    25 
       
    26 from os.path import join
       
    27 
       
    28 from logilab.common.configuration import Method, merge_options
       
    29 
       
    30 from cubicweb.cwconfig import CONFIGURATIONS
       
    31 from cubicweb.web.webconfig import WebConfiguration
       
    32 
       
    33 
       
    34 class WebConfigurationBase(WebConfiguration):
       
    35     """web instance (in a twisted web server) client of a RQL server"""
       
    36 
       
    37     options = merge_options((
       
    38         # ctl configuration
       
    39         ('port',
       
    40          {'type' : 'int',
       
    41           'default': None,
       
    42           'help': 'http server port number (default to 8080)',
       
    43           'group': 'web', 'level': 0,
       
    44           }),
       
    45         ('interface',
       
    46          {'type' : 'string',
       
    47           'default': "",
       
    48           'help': 'http server address on which to listen (default to everywhere)',
       
    49           'group': 'web', 'level': 1,
       
    50           }),
       
    51         ('max-post-length',
       
    52          {'type' : 'bytes',
       
    53           'default': '100MB',
       
    54           'help': 'maximum length of HTTP request. Default to 100 MB.',
       
    55           'group': 'web', 'level': 1,
       
    56           }),
       
    57         ('profile',
       
    58          {'type' : 'string',
       
    59           'default': None,
       
    60           'help': 'profile code and use the specified file to store stats if this option is set',
       
    61           'group': 'web', 'level': 3,
       
    62           }),
       
    63         ('host',
       
    64          {'type' : 'string',
       
    65           'default': None,
       
    66           'help': 'host name if not correctly detectable through gethostname',
       
    67           'group': 'main', 'level': 1,
       
    68           }),
       
    69         ('pid-file',
       
    70          {'type' : 'string',
       
    71           'default': Method('default_pid_file'),
       
    72           'help': 'repository\'s pid file',
       
    73           'group': 'main', 'level': 2,
       
    74           }),
       
    75         ('uid',
       
    76          {'type' : 'string',
       
    77           'default': None,
       
    78           'help': 'if this option is set, use the specified user to start \
       
    79 the repository rather than the user running the command',
       
    80           'group': 'main', 'level': WebConfiguration.mode == 'system'
       
    81           }),
       
    82         ('webserver-threadpool-size',
       
    83          {'type': 'int',
       
    84           'default': 4,
       
    85           'help': "size of twisted's reactor threadpool. It should probably be not too \
       
    86 much greater than connection-poolsize",
       
    87           'group': 'web', 'level': 3,
       
    88           }),
       
    89         ) + WebConfiguration.options)
       
    90 
       
    91     def server_file(self):
       
    92         return join(self.apphome, '%s-%s.py' % (self.appid, self.name))
       
    93 
       
    94     def default_base_url(self):
       
    95         from socket import getfqdn
       
    96         return 'http://%s:%s/' % (self['host'] or getfqdn().lower(), self['port'] or 8080)
       
    97 
       
    98 
       
    99 try:
       
   100     from cubicweb.server.serverconfig import ServerConfiguration
       
   101 
       
   102     class AllInOneConfiguration(WebConfigurationBase, ServerConfiguration):
       
   103         """repository and web instance in the same twisted process"""
       
   104         name = 'all-in-one'
       
   105         options = merge_options(WebConfigurationBase.options
       
   106                                 + ServerConfiguration.options)
       
   107 
       
   108         cubicweb_appobject_path = WebConfigurationBase.cubicweb_appobject_path | ServerConfiguration.cubicweb_appobject_path
       
   109         cube_appobject_path = WebConfigurationBase.cube_appobject_path | ServerConfiguration.cube_appobject_path
       
   110 
       
   111 
       
   112     CONFIGURATIONS.append(AllInOneConfiguration)
       
   113 
       
   114 except ImportError:
       
   115     pass