diff --git a/IPython/html/notebook/handlers.py b/IPython/html/notebook/handlers.py index be27df5..c3a8cfd 100644 --- a/IPython/html/notebook/handlers.py +++ b/IPython/html/notebook/handlers.py @@ -67,6 +67,11 @@ class NamedNotebookHandler(IPythonHandler): mathjax_url=self.mathjax_url, ) ) + + @web.authenticated + def post(self, notebook_path): + nbm =self.notebook_manager + notebook_name = nbm.new_notebook() class NotebookCopyHandler(IPythonHandler): diff --git a/IPython/html/services/contents/contentmanager.py b/IPython/html/services/contents/contentmanager.py index 5f02c2b..0dc55fe 100644 --- a/IPython/html/services/contents/contentmanager.py +++ b/IPython/html/services/contents/contentmanager.py @@ -6,7 +6,7 @@ Authors: """ #----------------------------------------------------------------------------- -# Copyright (C) 2011 The IPython Development Team +# Copyright (C) 2013 The IPython Development Team # # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. @@ -44,25 +44,32 @@ class ContentManager(LoggingConfigurable): contents = List() def get_content_names(self, content_path): + """List of dicts of files in content_path""" names = glob.glob(os.path.join(self.content_dir, content_path,'*')) - content_names = list() - dir_names = list() + contents = list() + dirs = list() + notebooks = list() for name in names: if os.path.isdir(name) == True: - dir_names.append(os.path.split(name)[1]) - elif os.path.splitext(os.path.basename(name))[1] != '.ipynb': - content_names.append(os.path.split(name)[1]) - return dir_names, content_names - + dirs.append(os.path.split(name)[1]) + elif os.path.splitext(name)[1] == '.ipynb': + notebooks.append(os.path.split(name)[1]) + else: + contents.append(os.path.split(name)[1]) + return dirs, notebooks, contents + def list_contents(self, content_path): """List all contents in the named path.""" - dir_names, content_names = self.get_content_names(content_path) + dir_names, notebook_names, content_names = self.get_content_names(content_path) content_mapping = [] for name in dir_names: - model = self.directory_model(name, content_path) + model = self.content_model(name, content_path, type='dir') content_mapping.append(model) for name in content_names: - model = self.content_model(name, content_path) + model = self.content_model(name, content_path, type='file') + content_mapping.append(model) + for name in notebook_names: + model = self.content_model(name, content_path, type='notebook') content_mapping.append(model) return content_mapping @@ -71,32 +78,27 @@ class ContentManager(LoggingConfigurable): path = os.path.join(self.content_dir, content_path, name) return path - def read_content(self, name, content_path): + def content_info(self, name, content_path): + """Read the content of a named file""" file_type = os.path.splitext(os.path.basename(name))[1] - #Collect contents of file - with open(name, 'rb') as file_content: - contents = file_content.read() full_path = self.get_path_by_name(name, content_path) info = os.stat(full_path) size = info.st_size last_modified = tz.utcfromtimestamp(info.st_mtime) - return last_modified, file_type, contents, size - - def directory_model(self, name, content_path): - model = {"name": name, - "path": content_path, - "type": 'tree'} - return model + return last_modified, file_type, size - def content_model(self, name, content_path): - last_modified, file_type, contents, size = self.read_content(name, content_path) + def content_model(self, name, content_path, type=None): + """Create a dict standard model for any file (other than notebooks)""" + last_modified, file_type, size = self.content_info(name, content_path) model = {"name": name, "path": content_path, - "type": file_type, + "type": type, + "MIME-type": "", "last_modified": last_modified.ctime(), "size": size} return model def delete_content(self, content_path): + """Delete a file""" os.unlink(os.path.join(self.content_dir, content_path)) \ No newline at end of file diff --git a/IPython/html/services/contents/handlers.py b/IPython/html/services/contents/handlers.py index 3214773..c3084ee 100644 --- a/IPython/html/services/contents/handlers.py +++ b/IPython/html/services/contents/handlers.py @@ -6,7 +6,7 @@ Authors: """ #----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The IPython Development Team +# Copyright (C) 2013 The IPython Development Team # # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. diff --git a/IPython/html/services/notebooks/filenbmanager.py b/IPython/html/services/notebooks/filenbmanager.py index a38eb0b..f9140c7 100644 --- a/IPython/html/services/notebooks/filenbmanager.py +++ b/IPython/html/services/notebooks/filenbmanager.py @@ -89,7 +89,7 @@ class FileNotebookManager(NotebookManager): notebook_names = self.get_notebook_names(path) notebook_mapping = [] for name in notebook_names: - model = self.notebook_model(name, path) + model = self.notebook_model(name, path, content=False) notebook_mapping.append(model) return notebook_mapping diff --git a/IPython/html/services/notebooks/nbmanager.py b/IPython/html/services/notebooks/nbmanager.py index 42300e1..d51e865 100644 --- a/IPython/html/services/notebooks/nbmanager.py +++ b/IPython/html/services/notebooks/nbmanager.py @@ -114,13 +114,15 @@ class NotebookManager(LoggingConfigurable): def notebook_exists(self, notebook_path): """Does a notebook exist?""" - def notebook_model(self, notebook_name, notebook_path=None): + + def notebook_model(self, notebook_name, notebook_path=None, content=True): """ Creates the standard notebook model """ - last_modified, content = self.read_notebook_object(notebook_name, notebook_path) + last_modified, contents = self.read_notebook_object(notebook_name, notebook_path) model = {"notebook_name": notebook_name, "notebook_path": notebook_path, - "content": content, "last_modified": last_modified.ctime()} + if content == True: + model['content'] = contents return model def get_notebook(self, notebook_name, notebook_path=None, format=u'json'): @@ -143,7 +145,7 @@ class NotebookManager(LoggingConfigurable): raise NotImplementedError('must be implemented in a subclass') def save_new_notebook(self, data, notebook_path = None, name=None, format=u'json'): - """Save a new notebook and return its notebook_id. + """Save a new notebook and return its name. If a name is passed in, it overrides any values in the notebook data and the value in the data is updated to use that value. diff --git a/IPython/html/services/sessions/handlers.py b/IPython/html/services/sessions/handlers.py index 60dfdbe..2cc4179 100644 --- a/IPython/html/services/sessions/handlers.py +++ b/IPython/html/services/sessions/handlers.py @@ -1,4 +1,4 @@ -"""Tornado handlers for the notebooks web service. +"""Tornado handlers for the sessions web service. Authors: @@ -6,7 +6,7 @@ Authors: """ #----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The IPython Development Team +# Copyright (C) 2013 The IPython Development Team # # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. diff --git a/IPython/html/services/sessions/sessionmanager.py b/IPython/html/services/sessions/sessionmanager.py index 358f7b1..0f55793 100644 --- a/IPython/html/services/sessions/sessionmanager.py +++ b/IPython/html/services/sessions/sessionmanager.py @@ -6,7 +6,7 @@ Authors: """ #----------------------------------------------------------------------------- -# Copyright (C) 2011 The IPython Development Team +# Copyright (C) 2013 The IPython Development Team # # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. @@ -53,6 +53,8 @@ class SessionManager(LoggingConfigurable): notebook_name=notebook_name, notebook_path=notebook_path, kernel=kernel) + if notebook_path == None: + model['notebook_path']="" self.sessions.append(model) return model