Show More
@@ -92,11 +92,49 b' class FileNotebookManager(NotebookManager):' | |||||
92 | i = i+1 |
|
92 | i = i+1 | |
93 | return name |
|
93 | return name | |
94 |
|
94 | |||
95 |
def |
|
95 | def path_exists(self, path): | |
96 | """Check that the given file system path is valid on this machine.""" |
|
96 | """Does the API-style path (directory) actually exist? | |
97 | if os.path.exists(path) is False: |
|
|||
98 | raise web.HTTPError(404, "No file or directory found.") |
|
|||
99 |
|
|
97 | ||
|
98 | Parameters | |||
|
99 | ---------- | |||
|
100 | path : string | |||
|
101 | The path to check. This is an API path (`/` separated, | |||
|
102 | relative to base notebook-dir). | |||
|
103 | ||||
|
104 | Returns | |||
|
105 | ------- | |||
|
106 | exists : bool | |||
|
107 | Whether the path is indeed a directory. | |||
|
108 | """ | |||
|
109 | os_path = self.get_os_path(path=path) | |||
|
110 | return os.path.isdir(os_path) | |||
|
111 | ||||
|
112 | def get_os_path(self, name=None, path=''): | |||
|
113 | """Given a notebook name and a URL path, return its file system | |||
|
114 | path. | |||
|
115 | ||||
|
116 | Parameters | |||
|
117 | ---------- | |||
|
118 | name : string | |||
|
119 | The name of a notebook file with the .ipynb extension | |||
|
120 | path : string | |||
|
121 | The relative URL path (with '/' as separator) to the named | |||
|
122 | notebook. | |||
|
123 | ||||
|
124 | Returns | |||
|
125 | ------- | |||
|
126 | path : string | |||
|
127 | A file system path that combines notebook_dir (location where | |||
|
128 | server started), the relative path, and the filename with the | |||
|
129 | current operating system's url. | |||
|
130 | """ | |||
|
131 | parts = path.strip('/').split('/') | |||
|
132 | parts = [p for p in parts if p != ''] # remove duplicate splits | |||
|
133 | if name is not None: | |||
|
134 | parts.append(name) | |||
|
135 | path = os.path.join(self.notebook_dir, *parts) | |||
|
136 | return path | |||
|
137 | ||||
100 | def notebook_exists(self, name, path=''): |
|
138 | def notebook_exists(self, name, path=''): | |
101 | """Returns a True if the notebook exists. Else, returns False. |
|
139 | """Returns a True if the notebook exists. Else, returns False. | |
102 |
|
140 |
@@ -49,7 +49,7 b' class NotebookManager(LoggingConfigurable):' | |||||
49 | def path_exists(self, path): |
|
49 | def path_exists(self, path): | |
50 | """Does the API-style path (directory) actually exist? |
|
50 | """Does the API-style path (directory) actually exist? | |
51 |
|
51 | |||
52 |
Override this method |
|
52 | Override this method in subclasses. | |
53 |
|
53 | |||
54 | Parameters |
|
54 | Parameters | |
55 | ---------- |
|
55 | ---------- | |
@@ -61,36 +61,8 b' class NotebookManager(LoggingConfigurable):' | |||||
61 | exists : bool |
|
61 | exists : bool | |
62 | Whether the path does indeed exist. |
|
62 | Whether the path does indeed exist. | |
63 | """ |
|
63 | """ | |
64 | os_path = self.get_os_path(name, path) |
|
64 | raise NotImplementedError | |
65 | return os.path.exists(os_path) |
|
|||
66 |
|
||||
67 |
|
65 | |||
68 | def get_os_path(self, name=None, path=''): |
|
|||
69 | """Given a notebook name and a URL path, return its file system |
|
|||
70 | path. |
|
|||
71 |
|
||||
72 | Parameters |
|
|||
73 | ---------- |
|
|||
74 | name : string |
|
|||
75 | The name of a notebook file with the .ipynb extension |
|
|||
76 | path : string |
|
|||
77 | The relative URL path (with '/' as separator) to the named |
|
|||
78 | notebook. |
|
|||
79 |
|
||||
80 | Returns |
|
|||
81 | ------- |
|
|||
82 | path : string |
|
|||
83 | A file system path that combines notebook_dir (location where |
|
|||
84 | server started), the relative path, and the filename with the |
|
|||
85 | current operating system's url. |
|
|||
86 | """ |
|
|||
87 | parts = path.strip('/').split('/') |
|
|||
88 | parts = [p for p in parts if p != ''] # remove duplicate splits |
|
|||
89 | if name is not None: |
|
|||
90 | parts.append(name) |
|
|||
91 | path = os.path.join(self.notebook_dir, *parts) |
|
|||
92 | return path |
|
|||
93 |
|
||||
94 | def _notebook_dir_changed(self, name, old, new): |
|
66 | def _notebook_dir_changed(self, name, old, new): | |
95 | """Do a bit of validation of the notebook dir.""" |
|
67 | """Do a bit of validation of the notebook dir.""" | |
96 | if not os.path.isabs(new): |
|
68 | if not os.path.isabs(new): |
General Comments 0
You need to be logged in to leave comments.
Login now