diff --git a/pgcontents/pgmanager.py b/pgcontents/pgmanager.py index f887f72..dfb28f1 100644 --- a/pgcontents/pgmanager.py +++ b/pgcontents/pgmanager.py @@ -18,7 +18,12 @@ from __future__ import unicode_literals from itertools import chain from tornado import web -from traitlets import default +from traitlets import ( + Unicode, + default, +) + +from jupyter_server.transutils import _i18n from .api_utils import ( base_directory_model, @@ -65,10 +70,22 @@ class PostgresContentsManager(PostgresManagerMixin, ContentsManager): ContentsManager that persists to a postgres database rather than to the local filesystem. """ + + create_directory_on_startup = Bool( config=True, help="Create a root directory automatically?", ) + + root_dir = Unicode("/", config=True) + + preferred_dir = Unicode( + "", + config=True, + help=_i18n( + "Preferred starting directory to use for notebooks. This is an API path (`/` separated, relative to root dir)" + ), + ) @default('checkpoints_class') def _default_checkpoints_class(self): @@ -102,7 +119,7 @@ def __init__(self, *args, **kwargs): def ensure_root_directory(self): with self.engine.begin() as db: - ensure_directory(db, self.user_id, '') + ensure_directory(db, self.user_id, self.root_dir) def purge_db(self): """ diff --git a/pgcontents/utils/ipycompat.py b/pgcontents/utils/ipycompat.py index 5f84939..0c98146 100644 --- a/pgcontents/utils/ipycompat.py +++ b/pgcontents/utils/ipycompat.py @@ -2,16 +2,17 @@ Utilities for managing compat between notebook versions. """ from traitlets.config import Config -from notebook.services.contents.checkpoints import ( + +from jupyter_server.services.contents.checkpoints import ( Checkpoints, GenericCheckpointsMixin, ) -from notebook.services.contents.filemanager import FileContentsManager -from notebook.services.contents.filecheckpoints import ( +from jupyter_server.services.contents.filemanager import FileContentsManager +from jupyter_server.services.contents.filecheckpoints import ( GenericFileCheckpoints ) -from notebook.services.contents.manager import ContentsManager -from notebook.utils import to_os_path +from jupyter_server.services.contents.manager import ContentsManager +from jupyter_server.utils import to_os_path from nbformat import from_dict, reads, writes from nbformat.v4.nbbase import ( new_code_cell,