コード例 #1
0
ファイル: server.py プロジェクト: FollonSaxBass/kolibri
def configure_http_server(port):
    # Mount the application
    from kolibri.deployment.default.wsgi import application

    cherrypy.tree.graft(application, "/")

    # Mount static files
    cherrypy.tree.mount(
        cherrypy.tools.staticdir.handler(section="/",
                                         dir=settings.STATIC_ROOT),
        settings.STATIC_URL,
        config={
            "/": {
                "tools.gzip.on": True,
                "tools.gzip.mime_types": ["text/*", "application/javascript"],
            }
        },
    )

    # Mount media files
    cherrypy.tree.mount(
        cherrypy.tools.staticdir.handler(section="/", dir=settings.MEDIA_ROOT),
        settings.MEDIA_URL,
    )

    # Mount content files
    CONTENT_ROOT = "/" + paths.get_content_url(
        conf.OPTIONS["Deployment"]["URL_PATH_PREFIX"]).lstrip("/")
    content_dirs = [paths.get_content_dir_path()
                    ] + paths.get_content_fallback_paths()
    dispatcher = MultiStaticDispatcher(content_dirs)
    cherrypy.tree.mount(
        None,
        CONTENT_ROOT,
        config={
            "/": {
                "tools.caching.on": False,
                "request.dispatch": dispatcher
            }
        },
    )

    # Configure the server
    cherrypy.config.update({
        "server.socket_host":
        LISTEN_ADDRESS,
        "server.socket_port":
        port,
        "server.thread_pool":
        conf.OPTIONS["Server"]["CHERRYPY_THREAD_POOL"],
        "server.socket_timeout":
        conf.OPTIONS["Server"]["CHERRYPY_SOCKET_TIMEOUT"],
        "server.accepted_queue_size":
        conf.OPTIONS["Server"]["CHERRYPY_QUEUE_SIZE"],
        "server.accepted_queue_timeout":
        conf.OPTIONS["Server"]["CHERRYPY_QUEUE_TIMEOUT"],
    })
    # Subscribe this server
    cherrypy.server.subscribe()
コード例 #2
0
def configure_http_server(port):
    # Mount the application
    from kolibri.deployment.default.wsgi import application

    cherrypy.tree.graft(application, "/")

    # Mount static files
    cherrypy.tree.mount(
        cherrypy.tools.staticdir.handler(section="/",
                                         dir=settings.STATIC_ROOT),
        settings.STATIC_URL,
        config={
            "/": {
                "tools.gzip.on": True,
                "tools.gzip.mime_types": ["text/*", "application/javascript"],
            }
        },
    )

    # Mount media files
    cherrypy.tree.mount(
        cherrypy.tools.staticdir.handler(section="/", dir=settings.MEDIA_ROOT),
        settings.MEDIA_URL,
    )

    # Mount content files
    content_files_handler = cherrypy.tools.staticdir.handler(
        section="/", dir=paths.get_content_dir_path())

    url_path_prefix = conf.OPTIONS["Deployment"]["URL_PATH_PREFIX"]

    cherrypy.tree.mount(
        content_files_handler,
        "/{}".format(paths.get_content_url(url_path_prefix).lstrip("/")),
        config={"/": {
            "tools.caching.on": False
        }},
    )

    # Instantiate a new server object
    server = cherrypy._cpserver.Server()

    # Configure the server
    server.socket_host = LISTEN_ADDRESS
    server.socket_port = port
    server.thread_pool = conf.OPTIONS["Server"]["CHERRYPY_THREAD_POOL"]
    server.socket_timeout = conf.OPTIONS["Server"]["CHERRYPY_SOCKET_TIMEOUT"]
    server.accepted_queue_size = conf.OPTIONS["Server"]["CHERRYPY_QUEUE_SIZE"]
    server.accepted_queue_timeout = conf.OPTIONS["Server"][
        "CHERRYPY_QUEUE_TIMEOUT"]

    # Subscribe this server
    server.subscribe()
コード例 #3
0
def generate_wsgi_application():
    django_application = get_wsgi_application()
    base_content_path = "/" + paths.get_content_url(
        conf.OPTIONS["Deployment"]["URL_PATH_PREFIX"]).lstrip("/")
    content_dirs = [paths.get_content_dir_path()
                    ] + paths.get_content_fallback_paths()

    # Mount static files
    return DjangoWhiteNoise(
        django_application,
        static_prefix=settings.STATIC_URL,
        dynamic_locations=[(base_content_path, content_dir)
                           for content_dir in content_dirs] +
        [(settings.MEDIA_URL, settings.MEDIA_ROOT)],
    )
コード例 #4
0
def generate_alt_wsgi_application():
    alt_content_path = "/" + paths.get_content_url(
        paths.zip_content_path_prefix()).lstrip("/")

    content_dirs = [paths.get_content_dir_path()
                    ] + paths.get_content_fallback_paths()

    content_static_path = os.path.join(
        os.path.dirname(kolibri.core.content.__file__), "static")

    # Mount static files
    return DynamicWhiteNoise(
        get_application(),
        dynamic_locations=[(alt_content_path, content_dir)
                           for content_dir in content_dirs] +
        [(paths.zip_content_static_root(), content_static_path)],
    )
コード例 #5
0
ファイル: urls.py プロジェクト: MikiasEphrem/cls
# Patterns that we want to prefix because they need access to the current language
lang_prefixed_patterns = [
    url(r"^i18n/setlang/$", set_language, name="set_language"),
    url(r"^logout/$", logout_view, name="logout"),
    url(r"^redirectuser/$",
        RootURLRedirectView.as_view(),
        name="redirect_user"),
    url(r"^guestaccess/$", GuestRedirectView.as_view(), name="guest"),
    url(r"^unsupported/$",
        UnsupportedBrowserView.as_view(),
        name="unsupported"),
    url(r"^$", RootURLRedirectView.as_view(), name="root_redirect"),
]

core_urlpatterns = [
    url(r"^api/", include("kolibri.core.api_urls")),
    url(r"", include(i18n_patterns(lang_prefixed_patterns))),
    url(r"", include("kolibri.core.content.urls")),
    url(r"^status/", StatusCheckView.as_view(), name="status_check"),
]

urlpatterns = [url(r"", include(core_urlpatterns, namespace="core"))]

urlpatterns += plugin_urls()

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += static(paths.get_content_url("/"),
                      document_root=paths.get_content_dir_path())
コード例 #6
0
ファイル: server.py プロジェクト: chrislun16/kolibri
def configure_http_server(port):
    # Mount the application
    from kolibri.deployment.default.wsgi import application

    whitenoise_settings = {
        "static_root": settings.STATIC_ROOT,
        "static_prefix": settings.STATIC_URL,
        # Use 1 day as the default cache time for static assets
        "max_age": 24 * 60 * 60,
        # Add a test for any file name that contains a semantic version number
        # or a 32 digit number (assumed to be a file hash)
        # these files will be cached indefinitely
        "immutable_file_test":
        r"((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)|[a-f0-9]{32})",
        "autorefresh": getattr(settings, "DEVELOPER_MODE", False),
    }

    # Mount static files
    application = DjangoWhiteNoise(application, **whitenoise_settings)

    cherrypy.tree.graft(application, "/")

    # Mount media files
    cherrypy.tree.mount(
        cherrypy.tools.staticdir.handler(section="/", dir=settings.MEDIA_ROOT),
        settings.MEDIA_URL,
    )

    # Mount content files
    CONTENT_ROOT = "/" + paths.get_content_url(
        conf.OPTIONS["Deployment"]["URL_PATH_PREFIX"]).lstrip("/")
    content_dirs = [paths.get_content_dir_path()
                    ] + paths.get_content_fallback_paths()
    dispatcher = MultiStaticDispatcher(content_dirs)
    content_handler = cherrypy.tree.mount(
        None,
        CONTENT_ROOT,
        config={
            "/": {
                "tools.caching.on": False,
                "request.dispatch": dispatcher
            }
        },
    )

    cherrypy_server_config = {
        "server.socket_host":
        LISTEN_ADDRESS,
        "server.socket_port":
        port,
        "server.thread_pool":
        conf.OPTIONS["Server"]["CHERRYPY_THREAD_POOL"],
        "server.socket_timeout":
        conf.OPTIONS["Server"]["CHERRYPY_SOCKET_TIMEOUT"],
        "server.accepted_queue_size":
        conf.OPTIONS["Server"]["CHERRYPY_QUEUE_SIZE"],
        "server.accepted_queue_timeout":
        conf.OPTIONS["Server"]["CHERRYPY_QUEUE_TIMEOUT"],
    }

    # Configure the server
    cherrypy.config.update(cherrypy_server_config)

    alt_port_addr = (
        LISTEN_ADDRESS,
        conf.OPTIONS["Deployment"]["ZIP_CONTENT_PORT"],
    )

    # Mount static files
    alt_port_app = wsgi.PathInfoDispatcher({
        "/": get_application(),
        CONTENT_ROOT: content_handler
    })
    alt_port_app = DjangoWhiteNoise(alt_port_app, **whitenoise_settings)

    alt_port_server = ServerAdapter(
        cherrypy.engine,
        wsgi.Server(
            alt_port_addr,
            alt_port_app,
            numthreads=conf.OPTIONS["Server"]["CHERRYPY_THREAD_POOL"],
            request_queue_size=conf.OPTIONS["Server"]["CHERRYPY_QUEUE_SIZE"],
            timeout=conf.OPTIONS["Server"]["CHERRYPY_SOCKET_TIMEOUT"],
            accepted_queue_size=conf.OPTIONS["Server"]["CHERRYPY_QUEUE_SIZE"],
            accepted_queue_timeout=conf.OPTIONS["Server"]
            ["CHERRYPY_QUEUE_TIMEOUT"],
        ),
        alt_port_addr,
    )
    # Subscribe these servers
    cherrypy.server.subscribe()
    alt_port_server.subscribe()
コード例 #7
0
ファイル: server.py プロジェクト: lateofrederick/kolibri
def run_server(port):

    # Mount the application
    from kolibri.deployment.default.wsgi import application

    cherrypy.tree.graft(application, "/")

    cherrypy.config.update({
        "environment": "production",
        "tools.expires.on": True,
        "tools.expires.secs": 31536000,
        "tools.caching.on": True,
        "tools.caching.maxobj_size": 2000000,
        "tools.caching.maxsize": calculate_cache_size(),
        "log.screen": False,
        "log.access_file": "",
        "log.error_file": "",
    })
    cherrypy.engine.unsubscribe("graceful", cherrypy.log.reopen_files)

    # Mount static files
    cherrypy.tree.mount(
        cherrypy.tools.staticdir.handler(section="/",
                                         dir=settings.STATIC_ROOT),
        settings.STATIC_URL,
        config={
            "/": {
                "tools.gzip.on": True,
                "tools.gzip.mime_types": ["text/*", "application/javascript"],
            }
        },
    )

    # Mount media files
    cherrypy.tree.mount(
        cherrypy.tools.staticdir.handler(section="/", dir=settings.MEDIA_ROOT),
        settings.MEDIA_URL,
    )

    # Mount content files
    content_files_handler = cherrypy.tools.staticdir.handler(
        section="/", dir=paths.get_content_dir_path())

    url_path_prefix = conf.OPTIONS["Deployment"]["URL_PATH_PREFIX"]

    cherrypy.tree.mount(
        content_files_handler,
        "/{}".format(paths.get_content_url(url_path_prefix).lstrip("/")),
        config={"/": {
            "tools.caching.on": False
        }},
    )

    # Unsubscribe the default server
    cherrypy.server.unsubscribe()

    # Instantiate a new server object
    server = cherrypy._cpserver.Server()

    # Configure the server
    server.socket_host = LISTEN_ADDRESS
    server.socket_port = port
    server.thread_pool = conf.OPTIONS["Server"]["CHERRYPY_THREAD_POOL"]
    server.socket_timeout = conf.OPTIONS["Server"]["CHERRYPY_SOCKET_TIMEOUT"]
    server.accepted_queue_size = conf.OPTIONS["Server"]["CHERRYPY_QUEUE_SIZE"]
    server.accepted_queue_timeout = conf.OPTIONS["Server"][
        "CHERRYPY_QUEUE_TIMEOUT"]

    # Subscribe this server
    server.subscribe()

    # Start the server engine (Option 1 *and* 2)
    unlock_after_vacuum()  # don't start the server until vacuum finishes
    cherrypy.engine.start()
    cherrypy.engine.block()