etwist/twconfig.py
changeset 0 b97547f5f1fa
child 136 ff51a18c66a3
equal deleted inserted replaced
-1:000000000000 0:b97547f5f1fa
       
     1 """twisted server configurations:
       
     2 
       
     3 * the "twisted" configuration to get a web application running in a standalone
       
     4   twisted web server which talk to a repository server using Pyro
       
     5   
       
     6 * the "all-in-one" configuration to get a web application running in a twisted
       
     7   web server integrating a repository server in the same process (only available
       
     8   if the repository part of the software is installed
       
     9 
       
    10 :organization: Logilab
       
    11 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
    12 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
    13 """
       
    14 __docformat__ = "restructuredtext en"
       
    15 
       
    16 from os.path import join
       
    17 
       
    18 from cubicweb.web.webconfig import WebConfiguration, merge_options, Method
       
    19 
       
    20 class TwistedConfiguration(WebConfiguration):
       
    21     """web application (in a twisted web server) client of a RQL server"""
       
    22     name = 'twisted'
       
    23 
       
    24     options = merge_options((
       
    25         # ctl configuration
       
    26         ('host',
       
    27          {'type' : 'string',
       
    28           'default': None,
       
    29           'help': 'host name if not correctly detectable through gethostname',
       
    30           'group': 'main', 'inputlevel': 1,
       
    31           }),
       
    32         ('port',
       
    33          {'type' : 'int',
       
    34           'default': None,
       
    35           'help': 'http server port number (default to 8080)',
       
    36           'group': 'main', 'inputlevel': 0,
       
    37           }),
       
    38         ('pid-file',
       
    39          {'type' : 'string',
       
    40           'default': Method('default_pid_file'),
       
    41           'help': 'repository\'s pid file',
       
    42           'group': 'main', 'inputlevel': 2,
       
    43           }),
       
    44         ('uid',
       
    45          {'type' : 'string',
       
    46           'default': None,
       
    47           'help': 'if this option is set, use the specified user to start \
       
    48 the repository rather than the user running the command',
       
    49           'group': 'main', 'inputlevel': 0,
       
    50           }),
       
    51         ('session-time',
       
    52          {'type' : 'int',
       
    53           'default': 30*60,
       
    54           'help': 'session expiration time, default to 30 minutes',
       
    55           'group': 'main', 'inputlevel': 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': 'main', 'inputlevel': 2,
       
    62           }),
       
    63         ('pyro-server',
       
    64          {'type' : 'yn',
       
    65           # pyro is only a recommends by default, so don't activate it here
       
    66           'default': False, 
       
    67           'help': 'run a pyro server',
       
    68           'group': 'main', 'inputlevel': 1,
       
    69           }),
       
    70         ) + WebConfiguration.options)
       
    71     
       
    72     def server_file(self):
       
    73         return join(self.apphome, '%s-%s.py' % (self.appid, self.name))
       
    74 
       
    75     def default_base_url(self):
       
    76         from socket import gethostname
       
    77         return 'http://%s:%s/' % (self['host'] or gethostname(), self['port'] or 8080)
       
    78 
       
    79 try:
       
    80     from cubicweb.server.serverconfig import ServerConfiguration
       
    81 
       
    82     class AllInOneConfiguration(TwistedConfiguration, ServerConfiguration):
       
    83         """repository and web application in the same twisted process"""
       
    84         name = 'all-in-one'
       
    85         repo_method = 'inmemory'
       
    86         options = merge_options(TwistedConfiguration.options
       
    87                                 + ServerConfiguration.options)
       
    88 
       
    89         cubicweb_vobject_path = TwistedConfiguration.cubicweb_vobject_path | ServerConfiguration.cubicweb_vobject_path
       
    90         cube_vobject_path = TwistedConfiguration.cube_vobject_path | ServerConfiguration.cube_vobject_path
       
    91         def pyro_enabled(self):
       
    92             """tell if pyro is activated for the in memory repository"""
       
    93             return self['pyro-server']
       
    94         
       
    95 except ImportError:
       
    96     pass