##// END OF EJS Templates
Addressing review comments....
Brian E. Granger -
Show More
@@ -159,12 +159,17 b' class FileNotebookManager(NotebookManager):'
159 """List the directories for a given API style path."""
159 """List the directories for a given API style path."""
160 path = path.strip('/')
160 path = path.strip('/')
161 os_path = self.get_os_path('', path)
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 dir_names = os.listdir(os_path)
164 dir_names = os.listdir(os_path)
163 dirs = []
165 dirs = []
164 for name in dir_names:
166 for name in dir_names:
165 os_path = self.get_os_path(name, path)
167 os_path = self.get_os_path(name, path)
166 if os.path.isdir(os_path) and not name.startswith('.'):
168 if os.path.isdir(os_path) and not name.startswith('.'):
169 try:
167 model = self.get_dir_model(name, path)
170 model = self.get_dir_model(name, path)
171 except IOError:
172 pass
168 dirs.append(model)
173 dirs.append(model)
169 dirs = sorted(dirs, key=lambda item: item['name'])
174 dirs = sorted(dirs, key=lambda item: item['name'])
170 return dirs
175 return dirs
@@ -206,16 +211,8 b' class FileNotebookManager(NotebookManager):'
206 """
211 """
207 path = path.strip('/')
212 path = path.strip('/')
208 notebook_names = self.get_notebook_names(path)
213 notebook_names = self.get_notebook_names(path)
209 index = []
214 notebooks = [self.get_notebook_model(name, path, content=False) for name in notebook_names]
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)
217 notebooks = sorted(notebooks, key=lambda item: item['name'])
215 notebooks = sorted(notebooks, key=lambda item: item['name'])
218 notebooks = index + self.list_dirs(path) + notebooks
219 return notebooks
216 return notebooks
220
217
221 def get_notebook_model(self, name, path='', content=True):
218 def get_notebook_model(self, name, path='', content=True):
@@ -248,6 +245,7 b' class FileNotebookManager(NotebookManager):'
248 model['path'] = path
245 model['path'] = path
249 model['last_modified'] = last_modified
246 model['last_modified'] = last_modified
250 model['created'] = created
247 model['created'] = created
248 model['type'] = 'notebook'
251 if content:
249 if content:
252 with io.open(os_path, 'r', encoding='utf-8') as f:
250 with io.open(os_path, 'r', encoding='utf-8') as f:
253 try:
251 try:
@@ -69,8 +69,18 b' class NotebookHandler(IPythonHandler):'
69 nbm = self.notebook_manager
69 nbm = self.notebook_manager
70 # Check to see if a notebook name was given
70 # Check to see if a notebook name was given
71 if name is None:
71 if name is None:
72 # List notebooks in 'path'
72 # TODO: Remove this after we create the contents web service and directories are
73 notebooks = nbm.list_notebooks(path)
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 self.finish(json.dumps(notebooks, default=date_default))
84 self.finish(json.dumps(notebooks, default=date_default))
75 return
85 return
76 # get and return notebook representation
86 # get and return notebook representation
@@ -112,6 +112,26 b' class NotebookManager(LoggingConfigurable):'
112 """
112 """
113 return basename
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 def list_notebooks(self, path=''):
135 def list_notebooks(self, path=''):
116 """Return a list of notebook dicts without content.
136 """Return a list of notebook dicts without content.
117
137
@@ -24,7 +24,7 b' from IPython.utils.data import uniq_stable'
24 # TODO: Remove this after we create the contents web service and directories are
24 # TODO: Remove this after we create the contents web service and directories are
25 # no longer listed by the notebook web service.
25 # no longer listed by the notebook web service.
26 def notebooks_only(nb_list):
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 class NBAPI(object):
30 class NBAPI(object):
General Comments 0
You need to be logged in to leave comments. Login now