Fixing minor things for the Azure backed nb storage.

pull/37/head
Brian Granger 14 years ago
parent 9784a2ac52
commit 8df2d331a7

@ -16,13 +16,14 @@ Authors:
# Imports
#-----------------------------------------------------------------------------
import os
import uuid
from tornado import web
from IPython.config.configurable import LoggingConfigurable
from IPython.nbformat import current
from IPython.utils.traitlets import List, Dict
from IPython.utils.traitlets import List, Dict, Unicode, TraitError
#-----------------------------------------------------------------------------
# Classes
@ -30,6 +31,26 @@ from IPython.utils.traitlets import List, Dict
class BaseNotebookManager(LoggingConfigurable):
# Todo:
# The notebook_dir attribute is used to mean a couple of different things:
# 1. Where the notebooks are stored if FileNotebookManager is used.
# 2. The cwd of the kernel for a project.
# Right now we use this attribute in a number of different places and
# we are going to have to disentagle all of this.
notebook_dir = Unicode(os.getcwdu(), config=True, help="""
The directory to use for notebooks.
""")
def _notebook_dir_changed(self, name, old, new):
"""do a bit of validation of the notebook dir"""
if os.path.exists(new) and not os.path.isdir(new):
raise TraitError("notebook dir %r is not a directory" % new)
if not os.path.exists(new):
self.log.info("Creating notebook dir %s", new)
try:
os.mkdir(new)
except:
raise TraitError("Couldn't create notebook dir %r" % new)
allowed_formats = List([u'json',u'py'])
# Map notebook_ids to notebook names
@ -179,3 +200,6 @@ class BaseNotebookManager(LoggingConfigurable):
nb.metadata.name = name
notebook_id = self.write_notebook_object(nb)
return notebook_id
def log_info(self):
self.log.info("Serving notebooks")

@ -32,20 +32,6 @@ from IPython.utils.traitlets import Unicode, Dict, Bool, TraitError
#-----------------------------------------------------------------------------
class FileNotebookManager(BaseNotebookManager):
notebook_dir = Unicode(os.getcwdu(), config=True, help="""
The directory to use for notebooks.
""")
def _notebook_dir_changed(self, name, old, new):
"""do a bit of validation of the notebook dir"""
if os.path.exists(new) and not os.path.isdir(new):
raise TraitError("notebook dir %r is not a directory" % new)
if not os.path.exists(new):
self.log.info("Creating notebook dir %s", new)
try:
os.mkdir(new)
except:
raise TraitError("Couldn't create notebook dir %r" % new)
save_script = Bool(False, config=True,
help="""Automatically create a Python script when saving the notebook.
@ -86,19 +72,19 @@ class FileNotebookManager(BaseNotebookManager):
def new_notebook_id(self, name):
"""Generate a new notebook_id for a name and store its mappings."""
notebook_id = super(BaseNotebookManager, self).new_notebook_id(name)
notebook_id = super(FileNotebookManager, self).new_notebook_id(name)
self.rev_mapping[name] = notebook_id
return notebook_id
def delete_notebook_id(self, notebook_id):
"""Delete a notebook's id in the mapping."""
super(BaseNotebookManager, self).delete_notebook_id(notebook_id)
name = self.mapping[notebook_id]
super(FileNotebookManager, self).delete_notebook_id(notebook_id)
del self.rev_mapping[name]
def notebook_exists(self, notebook_id):
"""Does a notebook exist?"""
exists = super(BaseNotebookManager, self).notebook_exists(notebook_id)
exists = super(FileNotebookManager, self).notebook_exists(notebook_id)
if not exists:
return False
path = self.get_path_by_name(self.mapping[notebook_id])
@ -205,3 +191,6 @@ class FileNotebookManager(BaseNotebookManager):
else:
i = i+1
return name
def log_info(self):
self.log.info("Serving notebooks from local directory: %s", self.notebook_manager.notebook_dir)

@ -408,7 +408,7 @@ class NotebookApp(BaseIPythonApplication):
else:
self.log.info("Using MathJax: %s", new)
notebook_manager_class = DottedObjectName('IPython.frontend.html.notebook.notebookmanager.NotebookManager',
notebook_manager_class = DottedObjectName('IPython.frontend.html.notebook.filenbmanager.FileNotebookManager',
config=True,
help='The notebook manager class to use.')
@ -440,7 +440,7 @@ class NotebookApp(BaseIPythonApplication):
)
kls = import_item(self.notebook_manager_class)
self.notebook_manager = kls(config=self.config, log=self.log)
self.log.info("Serving notebooks from %s", self.notebook_manager.notebook_dir)
self.notebook_manager.log_info()
self.notebook_manager.load_notebook_names()
self.cluster_manager = ClusterManager(config=self.config, log=self.log)
self.cluster_manager.update_profiles()

Loading…
Cancel
Save