etwist/server.py
changeset 4252 6c4f109c2b03
parent 4204 60256056bda6
parent 4221 da84ca26896d
child 4436 294e084f1263
equal deleted inserted replaced
4251:3c6569be1f86 4252:6c4f109c2b03
     1 """twisted server for CubicWeb web instances
     1 """twisted server for CubicWeb web instances
     2 
     2 
     3 :organization: Logilab
     3 :organization: Logilab
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     4 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     7 """
     7 """
     8 __docformat__ = "restructuredtext en"
     8 __docformat__ = "restructuredtext en"
     9 
     9 
    13 import hotshot
    13 import hotshot
    14 from time import mktime
    14 from time import mktime
    15 from datetime import date, timedelta
    15 from datetime import date, timedelta
    16 from urlparse import urlsplit, urlunsplit
    16 from urlparse import urlsplit, urlunsplit
    17 
    17 
    18 from twisted.application import strports
       
    19 from twisted.internet import reactor, task, threads
    18 from twisted.internet import reactor, task, threads
    20 from twisted.internet.defer import maybeDeferred
    19 from twisted.internet.defer import maybeDeferred
    21 from twisted.web2 import channel, http, server, iweb
    20 from twisted.web2 import channel, http, server, iweb
    22 from twisted.web2 import static, resource, responsecode
    21 from twisted.web2 import static, resource, responsecode
    23 
    22 
    24 from cubicweb import ObjectNotFound, CW_EVENT_MANAGER
    23 from cubicweb import ConfigurationError, CW_EVENT_MANAGER
    25 from cubicweb.web import (AuthenticationError, NotFound, Redirect,
    24 from cubicweb.web import (AuthenticationError, NotFound, Redirect,
    26                           RemoteCallFailed, DirectResponse, StatusResponse,
    25                           RemoteCallFailed, DirectResponse, StatusResponse,
    27                           ExplicitLogin)
    26                           ExplicitLogin)
    28 from cubicweb.web.application import CubicWebPublisher
    27 from cubicweb.web.application import CubicWebPublisher
    29 
    28 
   294             content = self.appli.loggedout_content(req)
   293             content = self.appli.loggedout_content(req)
   295         else:
   294         else:
   296             content = self.appli.need_login_content(req)
   295             content = self.appli.need_login_content(req)
   297         return http.Response(code, req.headers_out, content)
   296         return http.Response(code, req.headers_out, content)
   298 
   297 
   299 from twisted.python import failure
       
   300 from twisted.internet import defer
   298 from twisted.internet import defer
   301 from twisted.web2 import fileupload
   299 from twisted.web2 import fileupload
   302 
   300 
   303 # XXX set max file size to 100Mo: put max upload size in the configuration
   301 # XXX set max file size to 100Mo: put max upload size in the configuration
   304 # line below for twisted >= 8.0, default param value for earlier version
   302 # line below for twisted >= 8.0, default param value for earlier version
   385     # serve it via standard HTTP on port set in the configuration
   383     # serve it via standard HTTP on port set in the configuration
   386     port = config['port'] or 8080
   384     port = config['port'] or 8080
   387     reactor.listenTCP(port, channel.HTTPFactory(website))
   385     reactor.listenTCP(port, channel.HTTPFactory(website))
   388     logger = getLogger('cubicweb.twisted')
   386     logger = getLogger('cubicweb.twisted')
   389     if not debug:
   387     if not debug:
       
   388         if sys.platform == 'win32':
       
   389             raise ConfigurationError("Under windows, you must use the service management "
       
   390                                      "commands (e.g : 'net start my_instance)'")
   390         print 'instance starting in the background'
   391         print 'instance starting in the background'
   391         if daemonize():
   392         if daemonize():
   392             return # child process
   393             return # child process
   393         if config['pid-file']:
   394         if config['pid-file']:
   394             # ensure the directory where the pid-file should be set exists (for
   395             # ensure the directory where the pid-file should be set exists (for