##// END OF EJS Templates
standard model changes
Zachary Sailer -
Show More
@@ -68,6 +68,11 b' class NamedNotebookHandler(IPythonHandler):'
68 68 )
69 69 )
70 70
71 @web.authenticated
72 def post(self, notebook_path):
73 nbm =self.notebook_manager
74 notebook_name = nbm.new_notebook()
75
71 76
72 77 class NotebookCopyHandler(IPythonHandler):
73 78
@@ -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 11 # Distributed under the terms of the BSD License. The full license is in
12 12 # the file COPYING, distributed as part of this software.
@@ -44,25 +44,32 b' class ContentManager(LoggingConfigurable):'
44 44 contents = List()
45 45
46 46 def get_content_names(self, content_path):
47 """List of dicts of files in content_path"""
47 48 names = glob.glob(os.path.join(self.content_dir, content_path,'*'))
48 content_names = list()
49 dir_names = list()
49 contents = list()
50 dirs = list()
51 notebooks = list()
50 52 for name in names:
51 53 if os.path.isdir(name) == True:
52 dir_names.append(os.path.split(name)[1])
53 elif os.path.splitext(os.path.basename(name))[1] != '.ipynb':
54 content_names.append(os.path.split(name)[1])
55 return dir_names, content_names
54 dirs.append(os.path.split(name)[1])
55 elif os.path.splitext(name)[1] == '.ipynb':
56 notebooks.append(os.path.split(name)[1])
57 else:
58 contents.append(os.path.split(name)[1])
59 return dirs, notebooks, contents
56 60
57 61 def list_contents(self, content_path):
58 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 64 content_mapping = []
61 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 67 content_mapping.append(model)
64 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 73 content_mapping.append(model)
67 74 return content_mapping
68 75
@@ -71,32 +78,27 b' class ContentManager(LoggingConfigurable):'
71 78 path = os.path.join(self.content_dir, content_path, name)
72 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 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 84 full_path = self.get_path_by_name(name, content_path)
80 85 info = os.stat(full_path)
81 86 size = info.st_size
82 87 last_modified = tz.utcfromtimestamp(info.st_mtime)
83 return last_modified, file_type, contents, size
84
85 def directory_model(self, name, content_path):
86 model = {"name": name,
87 "path": content_path,
88 "type": 'tree'}
89 return model
88 return last_modified, file_type, size
90 89
91 def content_model(self, name, content_path):
92 last_modified, file_type, contents, size = self.read_content(name, content_path)
90 def content_model(self, name, content_path, type=None):
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 93 model = {"name": name,
94 94 "path": content_path,
95 "type": file_type,
95 "type": type,
96 "MIME-type": "",
96 97 "last_modified": last_modified.ctime(),
97 98 "size": size}
98 99 return model
99 100
100 101 def delete_content(self, content_path):
102 """Delete a file"""
101 103 os.unlink(os.path.join(self.content_dir, content_path))
102 104 No newline at end of file
@@ -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 11 # Distributed under the terms of the BSD License. The full license is in
12 12 # the file COPYING, distributed as part of this software.
@@ -89,7 +89,7 b' class FileNotebookManager(NotebookManager):'
89 89 notebook_names = self.get_notebook_names(path)
90 90 notebook_mapping = []
91 91 for name in notebook_names:
92 model = self.notebook_model(name, path)
92 model = self.notebook_model(name, path, content=False)
93 93 notebook_mapping.append(model)
94 94 return notebook_mapping
95 95
@@ -114,13 +114,15 b' class NotebookManager(LoggingConfigurable):'
114 114 def notebook_exists(self, notebook_path):
115 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 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 121 model = {"notebook_name": notebook_name,
121 122 "notebook_path": notebook_path,
122 "content": content,
123 123 "last_modified": last_modified.ctime()}
124 if content == True:
125 model['content'] = contents
124 126 return model
125 127
126 128 def get_notebook(self, notebook_name, notebook_path=None, format=u'json'):
@@ -143,7 +145,7 b' class NotebookManager(LoggingConfigurable):'
143 145 raise NotImplementedError('must be implemented in a subclass')
144 146
145 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 150 If a name is passed in, it overrides any values in the notebook data
149 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 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 11 # Distributed under the terms of the BSD License. The full license is in
12 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 11 # Distributed under the terms of the BSD License. The full license is in
12 12 # the file COPYING, distributed as part of this software.
@@ -53,6 +53,8 b' class SessionManager(LoggingConfigurable):'
53 53 notebook_name=notebook_name,
54 54 notebook_path=notebook_path,
55 55 kernel=kernel)
56 if notebook_path == None:
57 model['notebook_path']=""
56 58 self.sessions.append(model)
57 59 return model
58 60
General Comments 0
You need to be logged in to leave comments. Login now