##// END OF EJS Templates
checkpoint info is a dict...
MinRK -
Show More
@@ -273,27 +273,46 b' class FileNotebookManager(NotebookManager):'
273 273 name = self.get_name(notebook_id)
274 274 return self.get_checkpoint_path_by_name(name, checkpoint_id)
275 275
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
276 288 # public checkpoint API
277 289
278 290 def create_checkpoint(self, notebook_id):
279 291 """Create a checkpoint from the current state of a notebook"""
280 292 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)
282 296 self.log.debug("creating checkpoint for notebook %s", notebook_id)
283 297 if not os.path.exists(self.checkpoint_dir):
284 298 os.mkdir(self.checkpoint_dir)
285 299 shutil.copy2(nb_path, cp_path)
300
301 # return the checkpoint info
302 return self.get_checkpoint_info(notebook_id, checkpoint_id)
286 303
287 304 def list_checkpoints(self, notebook_id):
288 305 """list the checkpoints for a given notebook
289 306
290 307 This notebook manager currently only supports one checkpoint per notebook.
291 308 """
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):
296 312 return []
313 else:
314 return [self.get_checkpoint_info(notebook_id, checkpoint_id)]
315
297 316
298 317 def restore_checkpoint(self, notebook_id, checkpoint_id):
299 318 """restore a notebook to a checkpointed state"""
@@ -301,6 +320,7 b' class FileNotebookManager(NotebookManager):'
301 320 nb_path = self.get_path(notebook_id)
302 321 cp_path = self.get_checkpoint_path(notebook_id, checkpoint_id)
303 322 if not os.path.isfile(cp_path):
323 self.log.debug("checkpoint file does not exist: %s", cp_path)
304 324 raise web.HTTPError(404,
305 325 u'Notebook checkpoint does not exist: %s-%s' % (notebook_id, checkpoint_id)
306 326 )
General Comments 0
You need to be logged in to leave comments. Login now