From 20f2b0391ec95131d0a7c5870ff9fd79d0a7217e 2012-08-11 00:43:25
From: Brian Granger <ellisonbg@gmail.com>
Date: 2012-08-11 00:43:25
Subject: [PATCH] Fixing minor things for the Azure backed nb storage.

---

diff --git a/IPython/frontend/html/notebook/azurenbmanager.py b/IPython/frontend/html/notebook/azurenbmanager.py
index 9e251c9..bc0d6ee 100644
--- a/IPython/frontend/html/notebook/azurenbmanager.py
+++ b/IPython/frontend/html/notebook/azurenbmanager.py
@@ -49,7 +49,7 @@ class AzureNotebookManager(BaseNotebookManager):
         return BlobService(account_name=self.account_name, account_key=self.account_key)
 
     def __init__(self, **kwargs):
-        super(BaseNotebookManager,self).__init__(**kwargs)
+        super(AzureNotebookManager, self).__init__(**kwargs)
         self._update_service_host_base(self.blob_service_host_base)
         self._create_container()
 
@@ -138,3 +138,6 @@ class AzureNotebookManager(BaseNotebookManager):
             raise web.HTTPError(400, u'Unexpected error while deleting notebook: %s' % e)
         else:
             self.delete_notebook_id(notebook_id)
+
+    def log_info(self):
+        self.log.info("Serving notebooks from Azure storage: %s, %s", self.account_name, self.container)
diff --git a/IPython/frontend/html/notebook/basenbmanager.py b/IPython/frontend/html/notebook/basenbmanager.py
index b9a72c3..b7e9297 100644
--- a/IPython/frontend/html/notebook/basenbmanager.py
+++ b/IPython/frontend/html/notebook/basenbmanager.py
@@ -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")
\ No newline at end of file
diff --git a/IPython/frontend/html/notebook/filenbmanager.py b/IPython/frontend/html/notebook/filenbmanager.py
index eb0c062..6389ec1 100644
--- a/IPython/frontend/html/notebook/filenbmanager.py
+++ b/IPython/frontend/html/notebook/filenbmanager.py
@@ -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)
diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py
index 4fd525c..3980443 100644
--- a/IPython/frontend/html/notebook/notebookapp.py
+++ b/IPython/frontend/html/notebook/notebookapp.py
@@ -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()