##// END OF EJS Templates
Fixing minor things for the Azure backed nb storage.
Brian Granger -
Show More
@@ -49,7 +49,7 b' class AzureNotebookManager(BaseNotebookManager):'
49 return BlobService(account_name=self.account_name, account_key=self.account_key)
49 return BlobService(account_name=self.account_name, account_key=self.account_key)
50
50
51 def __init__(self, **kwargs):
51 def __init__(self, **kwargs):
52 super(BaseNotebookManager,self).__init__(**kwargs)
52 super(AzureNotebookManager, self).__init__(**kwargs)
53 self._update_service_host_base(self.blob_service_host_base)
53 self._update_service_host_base(self.blob_service_host_base)
54 self._create_container()
54 self._create_container()
55
55
@@ -138,3 +138,6 b' class AzureNotebookManager(BaseNotebookManager):'
138 raise web.HTTPError(400, u'Unexpected error while deleting notebook: %s' % e)
138 raise web.HTTPError(400, u'Unexpected error while deleting notebook: %s' % e)
139 else:
139 else:
140 self.delete_notebook_id(notebook_id)
140 self.delete_notebook_id(notebook_id)
141
142 def log_info(self):
143 self.log.info("Serving notebooks from Azure storage: %s, %s", self.account_name, self.container)
@@ -16,13 +16,14 b' Authors:'
16 # Imports
16 # Imports
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18
18
19 import os
19 import uuid
20 import uuid
20
21
21 from tornado import web
22 from tornado import web
22
23
23 from IPython.config.configurable import LoggingConfigurable
24 from IPython.config.configurable import LoggingConfigurable
24 from IPython.nbformat import current
25 from IPython.nbformat import current
25 from IPython.utils.traitlets import List, Dict
26 from IPython.utils.traitlets import List, Dict, Unicode, TraitError
26
27
27 #-----------------------------------------------------------------------------
28 #-----------------------------------------------------------------------------
28 # Classes
29 # Classes
@@ -30,6 +31,26 b' from IPython.utils.traitlets import List, Dict'
30
31
31 class BaseNotebookManager(LoggingConfigurable):
32 class BaseNotebookManager(LoggingConfigurable):
32
33
34 # Todo:
35 # The notebook_dir attribute is used to mean a couple of different things:
36 # 1. Where the notebooks are stored if FileNotebookManager is used.
37 # 2. The cwd of the kernel for a project.
38 # Right now we use this attribute in a number of different places and
39 # we are going to have to disentagle all of this.
40 notebook_dir = Unicode(os.getcwdu(), config=True, help="""
41 The directory to use for notebooks.
42 """)
43 def _notebook_dir_changed(self, name, old, new):
44 """do a bit of validation of the notebook dir"""
45 if os.path.exists(new) and not os.path.isdir(new):
46 raise TraitError("notebook dir %r is not a directory" % new)
47 if not os.path.exists(new):
48 self.log.info("Creating notebook dir %s", new)
49 try:
50 os.mkdir(new)
51 except:
52 raise TraitError("Couldn't create notebook dir %r" % new)
53
33 allowed_formats = List([u'json',u'py'])
54 allowed_formats = List([u'json',u'py'])
34
55
35 # Map notebook_ids to notebook names
56 # Map notebook_ids to notebook names
@@ -179,3 +200,6 b' class BaseNotebookManager(LoggingConfigurable):'
179 nb.metadata.name = name
200 nb.metadata.name = name
180 notebook_id = self.write_notebook_object(nb)
201 notebook_id = self.write_notebook_object(nb)
181 return notebook_id
202 return notebook_id
203
204 def log_info(self):
205 self.log.info("Serving notebooks") No newline at end of file
@@ -32,20 +32,6 b' from IPython.utils.traitlets import Unicode, Dict, Bool, TraitError'
32 #-----------------------------------------------------------------------------
32 #-----------------------------------------------------------------------------
33
33
34 class FileNotebookManager(BaseNotebookManager):
34 class FileNotebookManager(BaseNotebookManager):
35
36 notebook_dir = Unicode(os.getcwdu(), config=True, help="""
37 The directory to use for notebooks.
38 """)
39 def _notebook_dir_changed(self, name, old, new):
40 """do a bit of validation of the notebook dir"""
41 if os.path.exists(new) and not os.path.isdir(new):
42 raise TraitError("notebook dir %r is not a directory" % new)
43 if not os.path.exists(new):
44 self.log.info("Creating notebook dir %s", new)
45 try:
46 os.mkdir(new)
47 except:
48 raise TraitError("Couldn't create notebook dir %r" % new)
49
35
50 save_script = Bool(False, config=True,
36 save_script = Bool(False, config=True,
51 help="""Automatically create a Python script when saving the notebook.
37 help="""Automatically create a Python script when saving the notebook.
@@ -86,19 +72,19 b' class FileNotebookManager(BaseNotebookManager):'
86
72
87 def new_notebook_id(self, name):
73 def new_notebook_id(self, name):
88 """Generate a new notebook_id for a name and store its mappings."""
74 """Generate a new notebook_id for a name and store its mappings."""
89 notebook_id = super(BaseNotebookManager, self).new_notebook_id(name)
75 notebook_id = super(FileNotebookManager, self).new_notebook_id(name)
90 self.rev_mapping[name] = notebook_id
76 self.rev_mapping[name] = notebook_id
91 return notebook_id
77 return notebook_id
92
78
93 def delete_notebook_id(self, notebook_id):
79 def delete_notebook_id(self, notebook_id):
94 """Delete a notebook's id in the mapping."""
80 """Delete a notebook's id in the mapping."""
95 super(BaseNotebookManager, self).delete_notebook_id(notebook_id)
96 name = self.mapping[notebook_id]
81 name = self.mapping[notebook_id]
82 super(FileNotebookManager, self).delete_notebook_id(notebook_id)
97 del self.rev_mapping[name]
83 del self.rev_mapping[name]
98
84
99 def notebook_exists(self, notebook_id):
85 def notebook_exists(self, notebook_id):
100 """Does a notebook exist?"""
86 """Does a notebook exist?"""
101 exists = super(BaseNotebookManager, self).notebook_exists(notebook_id)
87 exists = super(FileNotebookManager, self).notebook_exists(notebook_id)
102 if not exists:
88 if not exists:
103 return False
89 return False
104 path = self.get_path_by_name(self.mapping[notebook_id])
90 path = self.get_path_by_name(self.mapping[notebook_id])
@@ -205,3 +191,6 b' class FileNotebookManager(BaseNotebookManager):'
205 else:
191 else:
206 i = i+1
192 i = i+1
207 return name
193 return name
194
195 def log_info(self):
196 self.log.info("Serving notebooks from local directory: %s", self.notebook_manager.notebook_dir)
@@ -408,7 +408,7 b' class NotebookApp(BaseIPythonApplication):'
408 else:
408 else:
409 self.log.info("Using MathJax: %s", new)
409 self.log.info("Using MathJax: %s", new)
410
410
411 notebook_manager_class = DottedObjectName('IPython.frontend.html.notebook.notebookmanager.NotebookManager',
411 notebook_manager_class = DottedObjectName('IPython.frontend.html.notebook.filenbmanager.FileNotebookManager',
412 config=True,
412 config=True,
413 help='The notebook manager class to use.')
413 help='The notebook manager class to use.')
414
414
@@ -440,7 +440,7 b' class NotebookApp(BaseIPythonApplication):'
440 )
440 )
441 kls = import_item(self.notebook_manager_class)
441 kls = import_item(self.notebook_manager_class)
442 self.notebook_manager = kls(config=self.config, log=self.log)
442 self.notebook_manager = kls(config=self.config, log=self.log)
443 self.log.info("Serving notebooks from %s", self.notebook_manager.notebook_dir)
443 self.notebook_manager.log_info()
444 self.notebook_manager.load_notebook_names()
444 self.notebook_manager.load_notebook_names()
445 self.cluster_manager = ClusterManager(config=self.config, log=self.log)
445 self.cluster_manager = ClusterManager(config=self.config, log=self.log)
446 self.cluster_manager.update_profiles()
446 self.cluster_manager.update_profiles()
General Comments 0
You need to be logged in to leave comments. Login now