diff --git a/omegaml/notebook/checkpoints.py b/omegaml/notebook/checkpoints.py index dd8f5446..8ecdfda2 100644 --- a/omegaml/notebook/checkpoints.py +++ b/omegaml/notebook/checkpoints.py @@ -1,22 +1,42 @@ +from IPython.utils.tz import utcnow from jupyter_server.services.contents.checkpoints import GenericCheckpointsMixin, Checkpoints + class NoOpCheckpoints(GenericCheckpointsMixin, Checkpoints): - """requires the following methods:""" # source: https://jupyter-server.readthedocs.io/en/latest/developers/contents.html + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.log.info("**** NoOpCheckpoints initialized") + + def checkpoint_model(self): + info = { + "id": "", + "last_modified": utcnow() + } + return info + def create_file_checkpoint(self, content, format, path): """ -> checkpoint model""" + return self.checkpoint_model() + def create_notebook_checkpoint(self, nb, path): """ -> checkpoint model""" + return self.checkpoint_model() + def get_file_checkpoint(self, checkpoint_id, path): """ -> {'type': 'file', 'content': , 'format': {'text', 'base64'}}""" + def get_notebook_checkpoint(self, checkpoint_id, path): """ -> {'type': 'notebook', 'content': }""" + def delete_checkpoint(self, checkpoint_id, path): """deletes a checkpoint for a file""" + def list_checkpoints(self, path): """returns a list of checkpoint models for a given file, default just does one per file """ return [] + def rename_checkpoint(self, checkpoint_id, old_path, new_path): """renames checkpoint from old path to new path""" diff --git a/omegaml/notebook/omegacontentsmgr.py b/omegaml/notebook/omegacontentsmgr.py index 502c35f3..ca839153 100644 --- a/omegaml/notebook/omegacontentsmgr.py +++ b/omegaml/notebook/omegacontentsmgr.py @@ -1,9 +1,8 @@ -import mimetypes -from base64 import encodebytes, decodebytes - import json +import mimetypes import nbformat import os +from base64 import encodebytes, decodebytes from datetime import datetime from io import BytesIO from jupyter_server.services.contents.manager import ContentsManager @@ -21,17 +20,16 @@ class OmegaStoreContentsManager(ContentsManager): Adopted from notebook/services/contents/filemanager.py This requires a properly configured omegaml instance. - see http://jupyter-notebook.readthedocs.io/en/stable/extending/contents.html + see https://jupyter-server.readthedocs.io/en/latest/developers/contents.html """ + checkpoints_class = NoOpCheckpoints + def __init__(self, **kwargs): # pass omega= for testing purpose self._omega = kwargs.pop('omega', None) super(OmegaStoreContentsManager, self).__init__(**kwargs) - def _checkpoints_class_default(self): - return NoOpCheckpoints - @property def omega(self): """