##// END OF EJS Templates
deleting a notebook deletes its checkpoints...
MinRK -
Show More
@@ -176,11 +176,11 b' class FileNotebookManager(NotebookManager):'
176
176
177 path = self.get_path_by_name(new_name)
177 path = self.get_path_by_name(new_name)
178 try:
178 try:
179 self.log.debug("Writing notebook %s", path)
179 self.log.debug("Autosaving notebook %s", path)
180 with open(path,'w') as f:
180 with open(path,'w') as f:
181 current.write(nb, f, u'json')
181 current.write(nb, f, u'json')
182 except Exception as e:
182 except Exception as e:
183 raise web.HTTPError(400, u'Unexpected error while saving notebook: %s' % e)
183 raise web.HTTPError(400, u'Unexpected error while autosaving notebook: %s' % e)
184
184
185 # save .py script as well
185 # save .py script as well
186 if self.save_script:
186 if self.save_script:
@@ -202,41 +202,44 b' class FileNotebookManager(NotebookManager):'
202 # remove renamed original, if it exists
202 # remove renamed original, if it exists
203 old_path = self.get_path_by_name(old_name)
203 old_path = self.get_path_by_name(old_name)
204 if os.path.isfile(old_path):
204 if os.path.isfile(old_path):
205 self.log.debug("unlinking %s", old_path)
205 self.log.debug("unlinking notebook %s", old_path)
206 os.unlink(old_path)
206 os.unlink(old_path)
207
207
208 # cleanup old script, if it exists
208 # cleanup old script, if it exists
209 if self.save_script:
209 if self.save_script:
210 old_pypath = os.path.splitext(old_path)[0] + '.py'
210 old_pypath = os.path.splitext(old_path)[0] + '.py'
211 if os.path.isfile(old_pypath):
211 if os.path.isfile(old_pypath):
212 self.log.debug("unlinking %s", old_pypath)
212 self.log.debug("unlinking script %s", old_pypath)
213 os.unlink(old_pypath)
213 os.unlink(old_pypath)
214
214
215 # rename checkpoints to follow file
215 # rename checkpoints to follow file
216 self.log.debug("%s", old_checkpoints)
217 for cp in old_checkpoints:
216 for cp in old_checkpoints:
218 old_cp_path = self.get_checkpoint_path_by_name(old_name, cp)
217 checkpoint_id = cp['checkpoint_id']
219 new_cp_path = self.get_checkpoint_path_by_name(new_name, cp)
218 old_cp_path = self.get_checkpoint_path_by_name(old_name, checkpoint_id)
219 new_cp_path = self.get_checkpoint_path_by_name(new_name, checkpoint_id)
220 if os.path.isfile(old_cp_path):
220 if os.path.isfile(old_cp_path):
221 self.log.debug("renaming %s -> %s", old_cp_path, new_cp_path)
221 self.log.debug("renaming checkpoint %s -> %s", old_cp_path, new_cp_path)
222 os.rename(old_cp_path, new_cp_path)
222 os.rename(old_cp_path, new_cp_path)
223
223
224 return notebook_id
224 return notebook_id
225
225
226 def delete_notebook(self, notebook_id):
226 def delete_notebook(self, notebook_id):
227 """Delete notebook by notebook_id."""
227 """Delete notebook by notebook_id."""
228 path = self.get_path(notebook_id)
228 nb_path = self.get_path(notebook_id)
229 if not os.path.isfile(path):
229 if not os.path.isfile(nb_path):
230 raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id)
230 raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id)
231 self.log.debug("unlinking %s", path)
232 os.unlink(path)
233
231
234 # clear checkpoints
232 # clear checkpoints
235 for checkpoint_id in self.list_checkpoints(notebook_id):
233 for checkpoint in self.list_checkpoints(notebook_id):
234 checkpoint_id = checkpoint['checkpoint_id']
236 path = self.get_checkpoint_path(notebook_id, checkpoint_id)
235 path = self.get_checkpoint_path(notebook_id, checkpoint_id)
236 self.log.debug(path)
237 if os.path.isfile(path):
237 if os.path.isfile(path):
238 self.log.debug("unlinking %s", path)
238 self.log.debug("unlinking checkpoint %s", path)
239 os.unlink(path)
239 os.unlink(path)
240
241 self.log.debug("unlinking notebook %s", nb_path)
242 os.unlink(nb_path)
240 self.delete_notebook_id(notebook_id)
243 self.delete_notebook_id(notebook_id)
241
244
242 def increment_filename(self, basename):
245 def increment_filename(self, basename):
General Comments 0
You need to be logged in to leave comments. Login now