Show More
@@ -153,6 +153,38 b' class FileNotebookManager(NotebookManager):' | |||
|
153 | 153 | nbpath = self.get_os_path(name, path=path) |
|
154 | 154 | return os.path.isfile(nbpath) |
|
155 | 155 | |
|
156 | def list_dirs(self, path): | |
|
157 | """List the directories for a given API style path.""" | |
|
158 | path = path.strip('/') | |
|
159 | os_path = self.get_os_path('', path) | |
|
160 | dir_names = os.listdir(os_path) | |
|
161 | dirs = [] | |
|
162 | for name in dir_names: | |
|
163 | os_path = self.get_os_path(name, path) | |
|
164 | if os.path.isdir(os_path) and not name.startswith('.'): | |
|
165 | model = self.get_dir_model(name, path) | |
|
166 | dirs.append(model) | |
|
167 | dirs = sorted(dirs, key=lambda item: item['name']) | |
|
168 | return dirs | |
|
169 | ||
|
170 | def get_dir_model(self, name, path=''): | |
|
171 | """Get the directory model given a directory name and its API style path""" | |
|
172 | path = path.strip('/') | |
|
173 | os_path = self.get_os_path(name, path) | |
|
174 | if not os.path.isdir(os_path): | |
|
175 | raise IOError('directory does not exist: %r' % os_path) | |
|
176 | info = os.stat(os_path) | |
|
177 | last_modified = tz.utcfromtimestamp(info.st_mtime) | |
|
178 | created = tz.utcfromtimestamp(info.st_ctime) | |
|
179 | # Create the notebook model. | |
|
180 | model ={} | |
|
181 | model['name'] = name | |
|
182 | model['path'] = path | |
|
183 | model['last_modified'] = last_modified | |
|
184 | model['created'] = created | |
|
185 | model['type'] = 'directory' | |
|
186 | return model | |
|
187 | ||
|
156 | 188 | def list_notebooks(self, path): |
|
157 | 189 | """Returns a list of dictionaries that are the standard model |
|
158 | 190 | for all notebooks in the relative 'path'. |
@@ -175,6 +207,7 b' class FileNotebookManager(NotebookManager):' | |||
|
175 | 207 | model = self.get_notebook_model(name, path, content=False) |
|
176 | 208 | notebooks.append(model) |
|
177 | 209 | notebooks = sorted(notebooks, key=lambda item: item['name']) |
|
210 | notebooks = self.list_dirs(path) + notebooks | |
|
178 | 211 | return notebooks |
|
179 | 212 | |
|
180 | 213 | def get_notebook_model(self, name, path='', content=True): |
General Comments 0
You need to be logged in to leave comments.
Login now