##// END OF EJS Templates
Addressing review comments....
Brian E. Granger -
Show More
@@ -159,12 +159,17 b' class FileNotebookManager(NotebookManager):'
159 159 """List the directories for a given API style path."""
160 160 path = path.strip('/')
161 161 os_path = self.get_os_path('', path)
162 if not os.path.isdir(os_path):
163 raise web.HTTPError(404, u'diretory does not exist: %r' % os_path)
162 164 dir_names = os.listdir(os_path)
163 165 dirs = []
164 166 for name in dir_names:
165 167 os_path = self.get_os_path(name, path)
166 168 if os.path.isdir(os_path) and not name.startswith('.'):
169 try:
167 170 model = self.get_dir_model(name, path)
171 except IOError:
172 pass
168 173 dirs.append(model)
169 174 dirs = sorted(dirs, key=lambda item: item['name'])
170 175 return dirs
@@ -206,16 +211,8 b' class FileNotebookManager(NotebookManager):'
206 211 """
207 212 path = path.strip('/')
208 213 notebook_names = self.get_notebook_names(path)
209 index = []
210 notebooks = []
211 for name in notebook_names:
212 model = self.get_notebook_model(name, path, content=False)
213 if name.lower() == 'index.ipynb':
214 index.append(model)
215 else:
216 notebooks.append(model)
214 notebooks = [self.get_notebook_model(name, path, content=False) for name in notebook_names]
217 215 notebooks = sorted(notebooks, key=lambda item: item['name'])
218 notebooks = index + self.list_dirs(path) + notebooks
219 216 return notebooks
220 217
221 218 def get_notebook_model(self, name, path='', content=True):
@@ -248,6 +245,7 b' class FileNotebookManager(NotebookManager):'
248 245 model['path'] = path
249 246 model['last_modified'] = last_modified
250 247 model['created'] = created
248 model['type'] = 'notebook'
251 249 if content:
252 250 with io.open(os_path, 'r', encoding='utf-8') as f:
253 251 try:
@@ -69,8 +69,18 b' class NotebookHandler(IPythonHandler):'
69 69 nbm = self.notebook_manager
70 70 # Check to see if a notebook name was given
71 71 if name is None:
72 # List notebooks in 'path'
73 notebooks = nbm.list_notebooks(path)
72 # TODO: Remove this after we create the contents web service and directories are
73 # no longer listed by the notebook web service. This should only handle notebooks
74 # and not directories.
75 dirs = nbm.list_dirs(path)
76 notebooks = []
77 index = []
78 for nb in nbm.list_notebooks(path):
79 if nb['name'].lower() == 'index.ipynb':
80 index.append(nb)
81 else:
82 notebooks.append(nb)
83 notebooks = index + dirs + notebooks
74 84 self.finish(json.dumps(notebooks, default=date_default))
75 85 return
76 86 # get and return notebook representation
@@ -112,6 +112,26 b' class NotebookManager(LoggingConfigurable):'
112 112 """
113 113 return basename
114 114
115 # TODO: Remove this after we create the contents web service and directories are
116 # no longer listed by the notebook web service.
117 def list_dirs(self, path):
118 """List the directory models for a given API style path."""
119 raise NotImplementedError('must be implemented in a subclass')
120
121 # TODO: Remove this after we create the contents web service and directories are
122 # no longer listed by the notebook web service.
123 def get_dir_model(self, name, path=''):
124 """Get the directory model given a directory name and its API style path.
125
126 The keys in the model should be:
127 * name
128 * path
129 * last_modified
130 * created
131 * type='directory'
132 """
133 raise NotImplementedError('must be implemented in a subclass')
134
115 135 def list_notebooks(self, path=''):
116 136 """Return a list of notebook dicts without content.
117 137
@@ -24,7 +24,7 b' from IPython.utils.data import uniq_stable'
24 24 # TODO: Remove this after we create the contents web service and directories are
25 25 # no longer listed by the notebook web service.
26 26 def notebooks_only(nb_list):
27 return [nb for nb in nb_list if 'type' not in nb]
27 return [nb for nb in nb_list if nb['type']=='notebook']
28 28
29 29
30 30 class NBAPI(object):
General Comments 0
You need to be logged in to leave comments. Login now