##// END OF EJS Templates
standard model changes
Zachary Sailer -
Show More
@@ -67,6 +67,11 b' class NamedNotebookHandler(IPythonHandler):'
67 mathjax_url=self.mathjax_url,
67 mathjax_url=self.mathjax_url,
68 )
68 )
69 )
69 )
70
71 @web.authenticated
72 def post(self, notebook_path):
73 nbm =self.notebook_manager
74 notebook_name = nbm.new_notebook()
70
75
71
76
72 class NotebookCopyHandler(IPythonHandler):
77 class NotebookCopyHandler(IPythonHandler):
@@ -6,7 +6,7 b' Authors:'
6 """
6 """
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2011 The IPython Development Team
9 # Copyright (C) 2013 The IPython Development Team
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
@@ -44,25 +44,32 b' class ContentManager(LoggingConfigurable):'
44 contents = List()
44 contents = List()
45
45
46 def get_content_names(self, content_path):
46 def get_content_names(self, content_path):
47 """List of dicts of files in content_path"""
47 names = glob.glob(os.path.join(self.content_dir, content_path,'*'))
48 names = glob.glob(os.path.join(self.content_dir, content_path,'*'))
48 content_names = list()
49 contents = list()
49 dir_names = list()
50 dirs = list()
51 notebooks = list()
50 for name in names:
52 for name in names:
51 if os.path.isdir(name) == True:
53 if os.path.isdir(name) == True:
52 dir_names.append(os.path.split(name)[1])
54 dirs.append(os.path.split(name)[1])
53 elif os.path.splitext(os.path.basename(name))[1] != '.ipynb':
55 elif os.path.splitext(name)[1] == '.ipynb':
54 content_names.append(os.path.split(name)[1])
56 notebooks.append(os.path.split(name)[1])
55 return dir_names, content_names
57 else:
56
58 contents.append(os.path.split(name)[1])
59 return dirs, notebooks, contents
60
57 def list_contents(self, content_path):
61 def list_contents(self, content_path):
58 """List all contents in the named path."""
62 """List all contents in the named path."""
59 dir_names, content_names = self.get_content_names(content_path)
63 dir_names, notebook_names, content_names = self.get_content_names(content_path)
60 content_mapping = []
64 content_mapping = []
61 for name in dir_names:
65 for name in dir_names:
62 model = self.directory_model(name, content_path)
66 model = self.content_model(name, content_path, type='dir')
63 content_mapping.append(model)
67 content_mapping.append(model)
64 for name in content_names:
68 for name in content_names:
65 model = self.content_model(name, content_path)
69 model = self.content_model(name, content_path, type='file')
70 content_mapping.append(model)
71 for name in notebook_names:
72 model = self.content_model(name, content_path, type='notebook')
66 content_mapping.append(model)
73 content_mapping.append(model)
67 return content_mapping
74 return content_mapping
68
75
@@ -71,32 +78,27 b' class ContentManager(LoggingConfigurable):'
71 path = os.path.join(self.content_dir, content_path, name)
78 path = os.path.join(self.content_dir, content_path, name)
72 return path
79 return path
73
80
74 def read_content(self, name, content_path):
81 def content_info(self, name, content_path):
82 """Read the content of a named file"""
75 file_type = os.path.splitext(os.path.basename(name))[1]
83 file_type = os.path.splitext(os.path.basename(name))[1]
76 #Collect contents of file
77 with open(name, 'rb') as file_content:
78 contents = file_content.read()
79 full_path = self.get_path_by_name(name, content_path)
84 full_path = self.get_path_by_name(name, content_path)
80 info = os.stat(full_path)
85 info = os.stat(full_path)
81 size = info.st_size
86 size = info.st_size
82 last_modified = tz.utcfromtimestamp(info.st_mtime)
87 last_modified = tz.utcfromtimestamp(info.st_mtime)
83 return last_modified, file_type, contents, size
88 return last_modified, file_type, size
84
85 def directory_model(self, name, content_path):
86 model = {"name": name,
87 "path": content_path,
88 "type": 'tree'}
89 return model
90
89
91 def content_model(self, name, content_path):
90 def content_model(self, name, content_path, type=None):
92 last_modified, file_type, contents, size = self.read_content(name, content_path)
91 """Create a dict standard model for any file (other than notebooks)"""
92 last_modified, file_type, size = self.content_info(name, content_path)
93 model = {"name": name,
93 model = {"name": name,
94 "path": content_path,
94 "path": content_path,
95 "type": file_type,
95 "type": type,
96 "MIME-type": "",
96 "last_modified": last_modified.ctime(),
97 "last_modified": last_modified.ctime(),
97 "size": size}
98 "size": size}
98 return model
99 return model
99
100
100 def delete_content(self, content_path):
101 def delete_content(self, content_path):
102 """Delete a file"""
101 os.unlink(os.path.join(self.content_dir, content_path))
103 os.unlink(os.path.join(self.content_dir, content_path))
102 No newline at end of file
104
@@ -6,7 +6,7 b' Authors:'
6 """
6 """
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
9 # Copyright (C) 2013 The IPython Development Team
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
@@ -89,7 +89,7 b' class FileNotebookManager(NotebookManager):'
89 notebook_names = self.get_notebook_names(path)
89 notebook_names = self.get_notebook_names(path)
90 notebook_mapping = []
90 notebook_mapping = []
91 for name in notebook_names:
91 for name in notebook_names:
92 model = self.notebook_model(name, path)
92 model = self.notebook_model(name, path, content=False)
93 notebook_mapping.append(model)
93 notebook_mapping.append(model)
94 return notebook_mapping
94 return notebook_mapping
95
95
@@ -114,13 +114,15 b' class NotebookManager(LoggingConfigurable):'
114 def notebook_exists(self, notebook_path):
114 def notebook_exists(self, notebook_path):
115 """Does a notebook exist?"""
115 """Does a notebook exist?"""
116
116
117 def notebook_model(self, notebook_name, notebook_path=None):
117
118 def notebook_model(self, notebook_name, notebook_path=None, content=True):
118 """ Creates the standard notebook model """
119 """ Creates the standard notebook model """
119 last_modified, content = self.read_notebook_object(notebook_name, notebook_path)
120 last_modified, contents = self.read_notebook_object(notebook_name, notebook_path)
120 model = {"notebook_name": notebook_name,
121 model = {"notebook_name": notebook_name,
121 "notebook_path": notebook_path,
122 "notebook_path": notebook_path,
122 "content": content,
123 "last_modified": last_modified.ctime()}
123 "last_modified": last_modified.ctime()}
124 if content == True:
125 model['content'] = contents
124 return model
126 return model
125
127
126 def get_notebook(self, notebook_name, notebook_path=None, format=u'json'):
128 def get_notebook(self, notebook_name, notebook_path=None, format=u'json'):
@@ -143,7 +145,7 b' class NotebookManager(LoggingConfigurable):'
143 raise NotImplementedError('must be implemented in a subclass')
145 raise NotImplementedError('must be implemented in a subclass')
144
146
145 def save_new_notebook(self, data, notebook_path = None, name=None, format=u'json'):
147 def save_new_notebook(self, data, notebook_path = None, name=None, format=u'json'):
146 """Save a new notebook and return its notebook_id.
148 """Save a new notebook and return its name.
147
149
148 If a name is passed in, it overrides any values in the notebook data
150 If a name is passed in, it overrides any values in the notebook data
149 and the value in the data is updated to use that value.
151 and the value in the data is updated to use that value.
@@ -1,4 +1,4 b''
1 """Tornado handlers for the notebooks web service.
1 """Tornado handlers for the sessions web service.
2
2
3 Authors:
3 Authors:
4
4
@@ -6,7 +6,7 b' Authors:'
6 """
6 """
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
9 # Copyright (C) 2013 The IPython Development Team
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
@@ -6,7 +6,7 b' Authors:'
6 """
6 """
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2011 The IPython Development Team
9 # Copyright (C) 2013 The IPython Development Team
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
@@ -53,6 +53,8 b' class SessionManager(LoggingConfigurable):'
53 notebook_name=notebook_name,
53 notebook_name=notebook_name,
54 notebook_path=notebook_path,
54 notebook_path=notebook_path,
55 kernel=kernel)
55 kernel=kernel)
56 if notebook_path == None:
57 model['notebook_path']=""
56 self.sessions.append(model)
58 self.sessions.append(model)
57 return model
59 return model
58
60
General Comments 0
You need to be logged in to leave comments. Login now