|
22 | 22 | # limitations under the License. |
23 | 23 |
|
24 | 24 | import os |
| 25 | +import re |
25 | 26 | from base64 import b64encode, b64decode |
26 | 27 |
|
27 | 28 | import click |
|
35 | 36 | NOTEBOOK = 'NOTEBOOK' |
36 | 37 | LIBRARY = 'LIBRARY' |
37 | 38 | REPO = 'REPO' |
| 39 | +LOCAL_OS_COMPATIBLE_PATH_REGEX = r'[^\w\-_\. ]' + re.escape(os.sep) |
38 | 40 |
|
39 | 41 |
|
40 | 42 | class WorkspaceFileInfo(object): |
@@ -166,15 +168,16 @@ def import_workspace_dir(self, source_path, target_path, overwrite, exclude_hidd |
166 | 168 | 'continue.').format(cur_src, extensions)) |
167 | 169 |
|
168 | 170 | def export_workspace_dir(self, source_path, target_path, overwrite, headers=None): |
169 | | - if os.path.isfile(target_path): |
| 171 | + os_compatible_target_path = re.sub(LOCAL_OS_COMPATIBLE_PATH_REGEX, '_', target_path) |
| 172 | + if os.path.isfile(os_compatible_target_path): |
170 | 173 | click.echo('{} exists as a file. Skipping this subtree {}' |
171 | | - .format(target_path, source_path)) |
| 174 | + .format(os_compatible_target_path, source_path)) |
172 | 175 | return |
173 | | - if not os.path.isdir(target_path): |
174 | | - os.makedirs(target_path) |
| 176 | + if not os.path.isdir(os_compatible_target_path): |
| 177 | + os.makedirs(os_compatible_target_path) |
175 | 178 | for obj in self.list_objects(source_path, headers=headers): |
176 | 179 | cur_src = obj.path |
177 | | - cur_dst = os.path.join(target_path, obj.basename) |
| 180 | + cur_dst = os.path.join(os_compatible_target_path, obj.basename) |
178 | 181 | if obj.is_dir: |
179 | 182 | self.export_workspace_dir(cur_src, cur_dst, overwrite, headers=headers) |
180 | 183 | elif obj.is_notebook: |
|
0 commit comments