Skip to content
Snippets Groups Projects
Commit e830fc42 authored by Swen Vermeul's avatar Swen Vermeul
Browse files

refactor: use server.py instead of main.py due to incompatibilities with newer jupyter lab versions

parent 9b2cb13c
No related branches found
No related tags found
No related merge requests found
...@@ -18,14 +18,14 @@ If you need to install or upgrade the server extension alone, you can do so by: ...@@ -18,14 +18,14 @@ If you need to install or upgrade the server extension alone, you can do so by:
$ pip install --upgrade jupyter-openbis-server $ pip install --upgrade jupyter-openbis-server
``` ```
Make sure your extension is recognised by Jupyter and enabled (your output may vary, but ensure you see the line: `jupyter-openbis-server.main OK`) Make sure your extension is recognised by Jupyter and enabled (your output may vary, but ensure you see the line: `jupyter-openbis-server.server OK`)
``` ```
$ jupyter serverextension list $ jupyter serverextension list
config dir: /Users/your_username/.pyenv/versions/3.6.9/etc/jupyter config dir: /Users/your_username/.pyenv/versions/3.6.9/etc/jupyter
jupyter-openbis-server.main enabled jupyter-openbis-server.server enabled
- Validating... - Validating...
jupyter-openbis-server.main OK jupyter-openbis-server.server OK
``` ```
## Create a connection configuration file ## Create a connection configuration file
...@@ -52,7 +52,7 @@ Options: ...@@ -52,7 +52,7 @@ Options:
You can start the utility as-is to get prompted for every parameter. Username and password are optional. You can start the utility as-is to get prompted for every parameter. Username and password are optional.
```` ```
$ jupyter-openbis-conn $ jupyter-openbis-conn
``` ```
...@@ -60,7 +60,8 @@ $ jupyter-openbis-conn ...@@ -60,7 +60,8 @@ $ jupyter-openbis-conn
In most cases, a simple `pip install --upgrade jupyter-openbis-server` will install the server extension. However, in some cases (e.g. when installing via `pip install -e .`) you need to issue the following command to register the extension: In most cases, a simple `pip install --upgrade jupyter-openbis-server` will install the server extension. However, in some cases (e.g. when installing via `pip install -e .`) you need to issue the following command to register the extension:
**In the library path, e.g. etc/jupyter/ **In the library path, e.g. `/etc/jupyter/`**
``` ```
$ jupyter serverextension enable --py jupyter-openbis-server --sys-prefix $ jupyter serverextension enable --py jupyter-openbis-server --sys-prefix
``` ```
...@@ -71,7 +72,7 @@ This will create a file `~/.jupyter/jupyter_notebook_config.json` with the follo ...@@ -71,7 +72,7 @@ This will create a file `~/.jupyter/jupyter_notebook_config.json` with the follo
{ {
"NotebookApp": { "NotebookApp": {
"nbserver_extensions": { "nbserver_extensions": {
"jupyter-openbis-server.main": true "jupyter-openbis-server.server": true
} }
} }
} }
...@@ -98,6 +99,7 @@ For all **POST**, **PUT** and **DELETE** requests, the following **http headers* ...@@ -98,6 +99,7 @@ For all **POST**, **PUT** and **DELETE** requests, the following **http headers*
"X-XSRFToken": xsrf_token, "X-XSRFToken": xsrf_token,
"credentials": "same-origin" "credentials": "same-origin"
``` ```
The value of the `xsrf_token` is the value of the `_xsrf` cookie which is stored in the users' browser. Without this http header information, the request will fail. All **GET** requests can be established without a special header. The value of the `xsrf_token` is the value of the `_xsrf` cookie which is stored in the users' browser. Without this http header information, the request will fail. All **GET** requests can be established without a special header.
The underlying Tornado-Webserver which handles all requests to the Jupyter serverextension will throw an error if the X-XSRF Token is not present. The underlying Tornado-Webserver which handles all requests to the Jupyter serverextension will throw an error if the X-XSRF Token is not present.
...@@ -112,7 +114,6 @@ Errors caused by a `POST`, `PUT` and `DELETE` request will result in a HTTP Stat ...@@ -112,7 +114,6 @@ Errors caused by a `POST`, `PUT` and `DELETE` request will result in a HTTP Stat
} }
``` ```
### get openBIS connections ### get openBIS connections
**GET `/openbis/conns`** **GET `/openbis/conns`**
...@@ -136,13 +137,14 @@ Returns an array of JSON objects: ...@@ -136,13 +137,14 @@ Returns an array of JSON objects:
"notebook_dir": "/home/user_name/project_dir" "notebook_dir": "/home/user_name/project_dir"
} }
``` ```
* the **`name`** is the name of the connection being used when downloading or uploading dataSets (see below)
* the **`url`** of the openBIS instance - the **`name`** is the name of the connection being used when downloading or uploading dataSets (see below)
* the values of `status` can be either **connected** or **not connected** - the **`url`** of the openBIS instance
* the **`username`** being used in openBIS - the values of `status` can be either **connected** or **not connected**
* the **`password`** really only consists of a number of asteriks **\***. If they are passed as such to re-connect to openBIS, the server tries to use the internally saved password instead. The password only lives in memory of the singleuser notebook-server and is not saved persistently. - the **`username`** being used in openBIS
* **`isMounted`** is either **true** or **false**, depending whether there is a current FUSE/SSHFS mountpoint available which connects to the openBIS dataStore - the **`password`** really only consists of a number of asteriks **\***. If they are passed as such to re-connect to openBIS, the server tries to use the internally saved password instead. The password only lives in memory of the singleuser notebook-server and is not saved persistently.
* `mountpoint` is the path to the mounted openBIS dataStore. It defaults to `$HOME/<openbis hostname>` - **`isMounted`** is either **true** or **false**, depending whether there is a current FUSE/SSHFS mountpoint available which connects to the openBIS dataStore
- `mountpoint` is the path to the mounted openBIS dataStore. It defaults to `$HOME/<openbis hostname>`
### login to an openBIS connection ### login to an openBIS connection
...@@ -159,6 +161,7 @@ Body: ...@@ -159,6 +161,7 @@ Body:
"action": "login", "action": "login",
} }
``` ```
The `action` attribute defaults to `login`. Returns: The `action` attribute defaults to `login`. Returns:
``` ```
...@@ -189,6 +192,7 @@ Body: ...@@ -189,6 +192,7 @@ Body:
"action": "logout", "action": "logout",
} }
``` ```
Returns: Returns:
``` ```
...@@ -209,6 +213,7 @@ Returns: ...@@ -209,6 +213,7 @@ Returns:
### Mount to an openBIS dataStore ### Mount to an openBIS dataStore
#### Prerequisites #### Prerequisites
On the Jupyter Server, FUSE/SSHFS must be installed beforehand (requires root privileges). For the actual mount to the openBIS dataStore, no special privileges are required. On the Jupyter Server, FUSE/SSHFS must be installed beforehand (requires root privileges). For the actual mount to the openBIS dataStore, no special privileges are required.
For **Mac OS X**, follow the installation instructions on [https://osxfuse.github.io](https://osxfuse.github.io) For **Mac OS X**, follow the installation instructions on [https://osxfuse.github.io](https://osxfuse.github.io)
...@@ -237,6 +242,7 @@ Body: ...@@ -237,6 +242,7 @@ Body:
"action" : "mount" "action" : "mount"
} }
``` ```
Returns: Returns:
``` ```
...@@ -265,6 +271,7 @@ Body: ...@@ -265,6 +271,7 @@ Body:
"action" : "mount" "action" : "mount"
} }
``` ```
Returns: Returns:
``` ```
...@@ -305,19 +312,17 @@ For the lifetime (runtime) of the Jupyter server, this will drop an existing ope ...@@ -305,19 +312,17 @@ For the lifetime (runtime) of the Jupyter server, this will drop an existing ope
**DELETE `/openbis/conn/<connection name>`** **DELETE `/openbis/conn/<connection name>`**
### Upload a dataSet ### Upload a dataSet
**POST `/openbis/dataset/<connection_name>/<permId>/<downloadPath>`** **POST `/openbis/dataset/<connection_name>/<permId>/<downloadPath>`**
### Download a dataSet ### Download a dataSet
**GET `/openbis/dataset/<connection_name>/<permId>/<downloadPath>`** **GET `/openbis/dataset/<connection_name>/<permId>/<downloadPath>`**
* the `connection_name` is the name of the connection given in the connections dialog. - the `connection_name` is the name of the connection given in the connections dialog.
* the `permId` is the identifer of the dataSet that needs to be downloaded. - the `permId` is the identifer of the dataSet that needs to be downloaded.
* the `downloadPath` is the absolute path on the host system where the dataSet files should be downloaded to. The `downloadPath` must be URL-encoded to not to be confused with the URL itself. - the `downloadPath` is the absolute path on the host system where the dataSet files should be downloaded to. The `downloadPath` must be URL-encoded to not to be confused with the URL itself.
In case of a **successful download**, the API returns a JSON like this In case of a **successful download**, the API returns a JSON like this
......
{ {
"NotebookApp": { "NotebookApp": {
"nbserver_extensions": { "nbserver_extensions": {
"jupyter-openbis-server.main": true "jupyter-openbis-server.server": true
} }
} }
} }
{ {
"ServerApp": { "ServerApp": {
"jpserver_extensions": { "jpserver_extensions": {
"jupyter-openbis-server": true "jupyter-openbis-server.server": true
} }
} }
} }
name = 'jupyter-openbis-server.server' name = "jupyter-openbis-server.server"
__author__ = 'Swen Vermeul' __author__ = "Swen Vermeul"
__email__ = 'swen@ethz.ch' __email__ = "swen@ethz.ch"
__version__ = '0.4.1' __version__ = "0.4.2"
def _jupyter_server_extension_paths(): def _jupyter_server_extension_paths():
return [{ return [{"module": "jupyter-openbis-server.server"}]
"module": "jupyter-openbis-server.main"
}]
def load_jupyter_server_extension(nbapp): def load_jupyter_server_extension(nbapp):
nbapp.log.info("jupyter-openbis-server module enabled!") nbapp.log.info("jupyter-openbis-server module enabled!")
...@@ -4,22 +4,26 @@ from urllib.parse import urlparse ...@@ -4,22 +4,26 @@ from urllib.parse import urlparse
import yaml import yaml
from notebook.utils import url_path_join from notebook.utils import url_path_join
from .connection import OpenBISConnections, OpenBISConnectionHandler, register_connection from .connection import (
OpenBISConnections,
OpenBISConnectionHandler,
register_connection,
)
from .dataset import DataSetTypesHandler, DataSetDownloadHandler, DataSetUploadHandler from .dataset import DataSetTypesHandler, DataSetDownloadHandler, DataSetUploadHandler
from .sample import SampleHandler from .sample import SampleHandler
from .requirements import Requirements from .requirements import Requirements
def _jupyter_server_extension_paths(): def _jupyter_server_extension_paths():
return [{'module': 'jupyter-openbis-server.server'}] return [{"module": "jupyter-openbis-server.server"}]
def _load_configuration(paths, filename='openbis-connections.yaml'): def _load_configuration(paths, filename="openbis-connections.yaml"):
if paths is None: if paths is None:
paths = [] paths = []
home = os.path.expanduser("~") home = os.path.expanduser("~")
paths.append(os.path.join(home, '.jupyter')) paths.append(os.path.join(home, ".jupyter"))
# look in all config file paths of jupyter # look in all config file paths of jupyter
# for openbis connection files and load them # for openbis connection files and load them
...@@ -27,10 +31,10 @@ def _load_configuration(paths, filename='openbis-connections.yaml'): ...@@ -27,10 +31,10 @@ def _load_configuration(paths, filename='openbis-connections.yaml'):
for path in paths: for path in paths:
abs_filename = os.path.join(path, filename) abs_filename = os.path.join(path, filename)
if os.path.isfile(abs_filename): if os.path.isfile(abs_filename):
with open(abs_filename, 'r') as stream: with open(abs_filename, "r") as stream:
try: try:
config = yaml.safe_load(stream) config = yaml.safe_load(stream)
for connection in config['connections']: for connection in config["connections"]:
connections.append(connection) connections.append(connection)
except yaml.YAMLexception as err: except yaml.YAMLexception as err:
print(err) print(err)
...@@ -48,8 +52,7 @@ def load_jupyter_server_extension(nb_server_app): ...@@ -48,8 +52,7 @@ def load_jupyter_server_extension(nb_server_app):
# and register the openBIS connections. # and register the openBIS connections.
# If username and password is available, try to connect to the server # If username and password is available, try to connect to the server
connections = _load_configuration( connections = _load_configuration(
paths = nb_server_app.config_file_paths, paths=nb_server_app.config_file_paths, filename="openbis-connections.yaml"
filename = 'openbis-connections.yaml'
) )
for connection_info in connections: for connection_info in connections:
...@@ -66,97 +69,95 @@ def load_jupyter_server_extension(nb_server_app): ...@@ -66,97 +69,95 @@ def load_jupyter_server_extension(nb_server_app):
if "OPENBIS_URL" in os.environ and "OPENBIS_TOKEN" in os.environ: if "OPENBIS_URL" in os.environ and "OPENBIS_TOKEN" in os.environ:
up = urlparse(os.environ["OPENBIS_URL"]) up = urlparse(os.environ["OPENBIS_URL"])
match = re.search(r'(?P<username>.*)-.*', os.environ["OPENBIS_TOKEN"]) match = re.search(r"(?P<username>.*)-.*", os.environ["OPENBIS_TOKEN"])
username = match.groupdict()['username'] username = match.groupdict()["username"]
connection_info = { connection_info = {
"name": up.hostname, "name": up.hostname,
"url": os.environ["OPENBIS_URL"], "url": os.environ["OPENBIS_URL"],
"verify_certificates" : False, "verify_certificates": False,
"username" : username, "username": username,
} }
conn = register_connection(connection_info) conn = register_connection(connection_info)
conn.token = os.environ["OPENBIS_TOKEN"] conn.token = os.environ["OPENBIS_TOKEN"]
# Add URL handlers to our web_app # Add URL handlers to our web_app
# see Tornado documentation: https://www.tornadoweb.org # see Tornado documentation: https://www.tornadoweb.org
web_app = nb_server_app.web_app web_app = nb_server_app.web_app
host_pattern = '.*$' host_pattern = ".*$"
base_url = web_app.settings['base_url'] base_url = web_app.settings["base_url"]
# DataSet download # DataSet download
web_app.add_handlers( web_app.add_handlers(
host_pattern, [( host_pattern,
url_path_join( [
base_url, (
'/openbis/dataset/(?P<connection_name>.*)?/(?P<permId>.*)?/(?P<downloadPath>.*)' url_path_join(
), base_url,
DataSetDownloadHandler "/openbis/dataset/(?P<connection_name>.*)?/(?P<permId>.*)?/(?P<downloadPath>.*)",
)] ),
DataSetDownloadHandler,
)
],
) )
# DataSet upload # DataSet upload
web_app.add_handlers( web_app.add_handlers(
host_pattern, [( host_pattern,
url_path_join( [
base_url, '/openbis/dataset/(?P<connection_name>.*)' (
), url_path_join(base_url, "/openbis/dataset/(?P<connection_name>.*)"),
DataSetUploadHandler DataSetUploadHandler,
)] )
],
) )
# DataSet-Types # DataSet-Types
web_app.add_handlers( web_app.add_handlers(
host_pattern, [( host_pattern,
url_path_join( [
base_url, '/openbis/datasetTypes/(?P<connection_name>.*)' (
), url_path_join(
DataSetTypesHandler base_url, "/openbis/datasetTypes/(?P<connection_name>.*)"
)] ),
DataSetTypesHandler,
)
],
) )
# DataSets for Sample identifier/permId # DataSets for Sample identifier/permId
web_app.add_handlers( web_app.add_handlers(
host_pattern, [( host_pattern,
url_path_join( [
base_url, (
'/openbis/sample/(?P<connection_name>.*)?/(?P<identifier>.*)' url_path_join(
), base_url,
SampleHandler "/openbis/sample/(?P<connection_name>.*)?/(?P<identifier>.*)",
)] ),
SampleHandler,
)
],
) )
# OpenBIS connections # OpenBIS connections
web_app.add_handlers( web_app.add_handlers(
host_pattern, [( host_pattern, [(url_path_join(base_url, "/openbis/conns"), OpenBISConnections)]
url_path_join(
base_url,
'/openbis/conns'
),
OpenBISConnections
)]
) )
# Modify / reconnect to a connection # Modify / reconnect to a connection
web_app.add_handlers( web_app.add_handlers(
host_pattern, [( host_pattern,
url_path_join( [
base_url, (
'/openbis/conn/(?P<connection_name>.*)' url_path_join(base_url, "/openbis/conn/(?P<connection_name>.*)"),
), OpenBISConnectionHandler,
OpenBISConnectionHandler )
)] ],
) )
# OpenBIS connections # OpenBIS connections
web_app.add_handlers( web_app.add_handlers(
host_pattern, [( host_pattern, [(url_path_join(base_url, "/requirements"), Requirements)]
url_path_join(
base_url,
'/requirements'
),
Requirements
)]
) )
_load_jupyter_server_extension = load_jupyter_server_extension
_load_jupyter_server_extension = load_jupyter_server_extension
import sys import sys
if sys.version_info < (3, 3): if sys.version_info < (3, 7):
sys.exit("Sorry, Python < 3.3 is not supported") sys.exit("Sorry, Python < 3.7 is not supported")
from setuptools import setup, find_packages from setuptools import setup, find_packages
...@@ -11,7 +11,7 @@ with open("README.md", "r", encoding="utf-8") as fh: ...@@ -11,7 +11,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
setup( setup(
name="jupyter-openbis-server", name="jupyter-openbis-server",
version="0.4.1", version="0.4.2",
author="Swen Vermeul | ID SIS | ETH Zürich", author="Swen Vermeul | ID SIS | ETH Zürich",
author_email="swen@ethz.ch", author_email="swen@ethz.ch",
description="Server Extension for Jupyter notebooks to connect to openBIS and download/upload datasets, inluding the notebook itself", description="Server Extension for Jupyter notebooks to connect to openBIS and download/upload datasets, inluding the notebook itself",
...@@ -31,7 +31,7 @@ setup( ...@@ -31,7 +31,7 @@ setup(
], ],
python_requires=">=3.3", python_requires=">=3.3",
classifiers=[ classifiers=[
"Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.7",
"Programming Language :: JavaScript", "Programming Language :: JavaScript",
"License :: OSI Approved :: Apache Software License", "License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent", "Operating System :: OS Independent",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment