Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 80b5d18

Browse files
committed
checkpoint info is a dict
two keys: checkpoint_id and last_modified
1 parent c8b6955 commit 80b5d18

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

IPython/frontend/html/notebook/filenbmanager.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,34 +273,54 @@ def get_checkpoint_path(self, notebook_id, checkpoint_id):
273273
name = self.get_name(notebook_id)
274274
return self.get_checkpoint_path_by_name(name, checkpoint_id)
275275

276+
def get_checkpoint_info(self, notebook_id, checkpoint_id):
277+
"""construct the info dict for a given checkpoint"""
278+
path = self.get_checkpoint_path(notebook_id, checkpoint_id)
279+
stats = os.stat(path)
280+
last_modified = datetime.datetime.utcfromtimestamp(stats.st_mtime)
281+
info = dict(
282+
checkpoint_id = checkpoint_id,
283+
last_modified = last_modified,
284+
)
285+
286+
return info
287+
276288
# public checkpoint API
277289

278290
def create_checkpoint(self, notebook_id):
279291
"""Create a checkpoint from the current state of a notebook"""
280292
nb_path = self.get_path(notebook_id)
281-
cp_path = self.get_checkpoint_path(notebook_id, "checkpoint")
293+
# only the one checkpoint ID:
294+
checkpoint_id = "checkpoint"
295+
cp_path = self.get_checkpoint_path(notebook_id, checkpoint_id)
282296
self.log.debug("creating checkpoint for notebook %s", notebook_id)
283297
if not os.path.exists(self.checkpoint_dir):
284298
os.mkdir(self.checkpoint_dir)
285299
shutil.copy2(nb_path, cp_path)
300+
301+
# return the checkpoint info
302+
return self.get_checkpoint_info(notebook_id, checkpoint_id)
286303

287304
def list_checkpoints(self, notebook_id):
288305
"""list the checkpoints for a given notebook
289306
290307
This notebook manager currently only supports one checkpoint per notebook.
291308
"""
292-
path = self.get_checkpoint_path(notebook_id, "checkpoint")
293-
if os.path.exists(path):
294-
return ["checkpoint"]
295-
else:
309+
checkpoint_id = "checkpoint"
310+
path = self.get_checkpoint_path(notebook_id, checkpoint_id)
311+
if not os.path.exists(path):
296312
return []
313+
else:
314+
return [self.get_checkpoint_info(notebook_id, checkpoint_id)]
315+
297316

298317
def restore_checkpoint(self, notebook_id, checkpoint_id):
299318
"""restore a notebook to a checkpointed state"""
300319
self.log.info("restoring Notebook %s from checkpoint %s", notebook_id, checkpoint_id)
301320
nb_path = self.get_path(notebook_id)
302321
cp_path = self.get_checkpoint_path(notebook_id, checkpoint_id)
303322
if not os.path.isfile(cp_path):
323+
self.log.debug("checkpoint file does not exist: %s", cp_path)
304324
raise web.HTTPError(404,
305325
u'Notebook checkpoint does not exist: %s-%s' % (notebook_id, checkpoint_id)
306326
)

0 commit comments

Comments
 (0)