Beispiel #1
0
def launch_context_sensitive_shell(request, extra_script="", extra_greeting=""):
    """Launch a IPython Notebook.

    :param extra_script: Extra script executed on the launch of this notebook
    :param extra_greeting: Extra text in the greeting Markdown for this launch
    """
    nb = {}

    # Pass around the Pyramid configuration we used to start this application
    global_config = request.registry.settings["websauna.global_config"]

    # Get the reference to our Pyramid app config file and generate Notebook
    # bootstrap startup.py script for this application
    config_file = global_config["__file__"]
    startup.make_startup(nb, config_file)
    startup.add_script(nb, SCRIPT)
    startup.add_greeting(nb, GREETING)

    #: Include all our SQLAlchemy models in the notebook variables
    startup.include_sqlalchemy_models(nb, Base)

    startup.add_script(nb, extra_script)
    startup.add_greeting(nb, extra_greeting)

    return launch_notebook(request, request.user.username, notebook_context=nb)
Beispiel #2
0
def launch_context_sensitive_shell(request,
                                   extra_script="",
                                   extra_greeting=""):
    """Launch a IPython Notebook.

    :param extra_script: Extra script executed on the launch of this notebook
    :param extra_greeting: Extra text in the greeting Markdown for this launch
    """
    nb = {}

    # Pass around the Pyramid configuration we used to start this application
    global_config = request.registry.settings["websauna.global_config"]

    # Get the reference to our Pyramid app config file and generate Notebook
    # bootstrap startup.py script for this application
    config_file = global_config["__file__"]
    startup.make_startup(nb,
                         config_file,
                         bootstrap_py=WEBSAUNA_BOOSTRAP,
                         cwd=os.getcwd())
    startup.add_script(nb, SCRIPT)
    startup.add_greeting(nb, GREETING)

    #: Include all our SQLAlchemy models in the notebook variables
    startup.include_sqlalchemy_models(nb, Base)

    startup.add_script(nb, extra_script)
    startup.add_greeting(nb, extra_greeting)

    return launch_notebook(request, request.user.username, notebook_context=nb)
Beispiel #3
0
def shell1(request):
    # Make sure we have a logged in user
    auth = request.registry.queryUtility(IAuthenticationPolicy)
    username = auth.authenticated_userid(request)

    if not username:
        # This will trigger HTTP Basic Auth dialog, as per basic_challenge handler below
        raise httpexceptions.HTTPForbidden(
            "You need to be logged in. Hint: user / password")

    notebook_context = {"greeting": "**Executing shell1 context**\n"}
    config_file = request.registry.settings["global_config"]["__file__"]
    startup.make_startup(notebook_context, config_file)

    return launch_notebook(request,
                           username,
                           notebook_context=notebook_context)