Skip to content

Instantly share code, notes, and snippets.

@bollwyvl
Created July 19, 2016 01:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bollwyvl/0173efba9e5cf78c55cade93dfbbe91e to your computer and use it in GitHub Desktop.
Save bollwyvl/0173efba9e5cf78c55cade93dfbbe91e to your computer and use it in GitHub Desktop.
A very simple read-only Jupyter Contents Manager for listing some distributed notebooks

Clone this.

Run jupyter notebook in the directory.

It will list everything in $PREFIX/share/ipynb.

import sys
import os
sys.path.append(os.path.dirname(__file__))
import jupyter_shelf
c.NotebookApp.contents_manager_class = jupyter_shelf.ShelfContentsManager
import sys
import os
from tornado.web import HTTPError
from notebook.services.contents.filemanager import FileContentsManager
from notebook.utils import (
to_os_path,
)
ROOT = os.path.join(sys.prefix, "share", "ipynb")
class ShelfContentsManager(FileContentsManager):
def _get_os_path(self, path):
root = os.path.abspath(ROOT)
os_path = to_os_path(path, root)
if not (os.path.abspath(os_path) + os.path.sep).startswith(root):
raise HTTPError(404,
"%s is outside root contents directory" % path)
return os_path
def _save_file(self, *args, **kwargs):
pass
def _save_directory(self, *args, **kwargs):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment