Esempio n. 1
0
def start_reload(zope_layer_dotted_name, reload_paths=('src',),
                 preload_layer_dotted_name='plone.app.testing.PLONE_FIXTURE'):

    print WAIT("Starting Zope 2 server")

    zsl = Zope2Server()
    zsl.start_zope_server(preload_layer_dotted_name)

    forkloop = ForkLoop()
    Watcher(reload_paths, forkloop).start()
    forkloop.start()

    if forkloop.exit:
        print WAIT("Stopping Zope 2 server")
        zsl.stop_zope_server()
        print READY("Zope 2 server stopped")
        return

    # XXX: For unknown reason call to socket.gethostbyaddr may cause malloc
    # errors on OSX in forked child when called from medusa http_server, but
    # proper sleep seem to fix it:
    import time
    import socket
    import platform
    if 'Darwin' in platform.uname():
        gethostbyaddr = socket.gethostbyaddr
        socket.gethostbyaddr = lambda x: time.sleep(0.5) or (ZSERVER_HOST,)

    # Setting smaller asyncore poll timeout will speed up restart a bit
    import plone.testing.z2
    plone.testing.z2.ZServer.timeout = 0.5

    zsl.amend_zope_server(zope_layer_dotted_name)

    if 'Darwin' in platform.uname():
        socket.gethostbyaddr = gethostbyaddr

    print READY("Zope 2 server started")

    try:
        listener = SimpleXMLRPCServer((LISTENER_HOST, LISTENER_PORT),
                                      logRequests=False)
    except socket.error as e:
        print ERROR(str(e))
        print WAIT("Pruning Zope 2 server")
        zsl.prune_zope_server()
        return

    listener.timeout = 0.5
    listener.allow_none = True
    listener.register_function(zsl.zodb_setup, 'zodb_setup')
    listener.register_function(zsl.zodb_teardown, 'zodb_teardown')

    try:
        while not forkloop.exit:
            listener.handle_request()
    except select.error:  # Interrupted system call
        pass
    finally:
        print WAIT("Pruning Zope 2 server")
        zsl.prune_zope_server()
Esempio n. 2
0
def start_reload(zope_layer_dotted_name, reload_paths=('src',),
                 preload_layer_dotted_name='plone.app.testing.PLONE_FIXTURE',
                 extensions=None):

    print(WAIT("Starting Zope robot server"))

    zsl = Zope2Server()
    zsl.start_zope_server(preload_layer_dotted_name)

    forkloop = ForkLoop()
    watcher = Watcher(reload_paths, forkloop)
    if extensions:
        watcher.allowed_extensions = extensions
    elif HAS_DEBUG_MODE:
        watcher.allowed_extensions.remove('pt')
    watcher.start()
    forkloop.start()

    if forkloop.exit:
        print(WAIT("Stopping Zope robot server"))
        zsl.stop_zope_server()
        print(READY("Zope robot server stopped"))
        return

    # XXX: For unknown reason call to socket.gethostbyaddr may cause malloc
    # errors on OSX in forked child when called from medusa http_server, but
    # proper sleep seem to fix it:
    import time
    import socket
    import platform
    if 'Darwin' in platform.uname():
        gethostbyaddr = socket.gethostbyaddr
        socket.gethostbyaddr = lambda x: time.sleep(0.5) or (ZSERVER_HOST,)

    # Setting smaller asyncore poll timeout will speed up restart a bit
    import plone.testing.z2
    plone.testing.z2.ZServer.timeout = 0.5

    zsl.amend_zope_server(zope_layer_dotted_name)

    if HAS_DEBUG_MODE:
        import App.config
        config = App.config.getConfiguration()
        config.debug_mode = HAS_DEBUG_MODE
        App.config.setConfiguration(config)

    if 'Darwin' in platform.uname():
        socket.gethostbyaddr = gethostbyaddr

    print(READY("Zope robot server started"))

    try:
        listener = SimpleXMLRPCServer((LISTENER_HOST, LISTENER_PORT),
                                      logRequests=False)
    except socket.error as e:
        print(ERROR(str(e)))
        print(WAIT("Pruning Zope robot server"))
        zsl.prune_zope_server()
        return

    listener.timeout = 0.5
    listener.allow_none = True
    listener.register_function(zsl.zodb_setup, 'zodb_setup')
    listener.register_function(zsl.zodb_teardown, 'zodb_teardown')

    try:
        while not forkloop.exit:
            listener.handle_request()
    except select.error:  # Interrupted system call
        pass
    finally:
        print(WAIT("Pruning Zope robot server"))
        zsl.prune_zope_server()