Skip to content

Commit c695b8d

Browse files
authored
Sample - Fix exports from Workspace to Windows FS (#448)
1 parent ef1266e commit c695b8d

File tree

1 file changed

+8
-5
lines changed
  • databricks_cli/workspace

1 file changed

+8
-5
lines changed

databricks_cli/workspace/api.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# limitations under the License.
2323

2424
import os
25+
import re
2526
from base64 import b64encode, b64decode
2627

2728
import click
@@ -35,6 +36,7 @@
3536
NOTEBOOK = 'NOTEBOOK'
3637
LIBRARY = 'LIBRARY'
3738
REPO = 'REPO'
39+
LOCAL_OS_COMPATIBLE_PATH_REGEX = r'[^\w\-_\. ]' + re.escape(os.sep)
3840

3941

4042
class WorkspaceFileInfo(object):
@@ -166,15 +168,16 @@ def import_workspace_dir(self, source_path, target_path, overwrite, exclude_hidd
166168
'continue.').format(cur_src, extensions))
167169

168170
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):
170173
click.echo('{} exists as a file. Skipping this subtree {}'
171-
.format(target_path, source_path))
174+
.format(os_compatible_target_path, source_path))
172175
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)
175178
for obj in self.list_objects(source_path, headers=headers):
176179
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)
178181
if obj.is_dir:
179182
self.export_workspace_dir(cur_src, cur_dst, overwrite, headers=headers)
180183
elif obj.is_notebook:

0 commit comments

Comments
 (0)