Skip to content

Commit

Permalink
feat: Make sure local copy works on Windows as well. #982
Browse files Browse the repository at this point in the history
  • Loading branch information
mturoci committed Jan 20, 2023
1 parent f3df20f commit 8f8ef8d
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions py/h2o_wave/core.py
Expand Up @@ -17,6 +17,7 @@
import json
import platform
import secrets
import shutil
import subprocess
from urllib.parse import urlparse
from uuid import uuid4
Expand Down Expand Up @@ -684,11 +685,13 @@ def upload(self, files: List[str]) -> List[str]:
dst = os.path.join(_waved_dir, _data_dir, 'f', uuid)
os.makedirs(dst, exist_ok=True)

args = [cp_command, f, dst]
if is_windows:
args.append('/K/O/X')
if is_windows and shutil.which('robocopy'):
src = os.path.dirname(f) or os.getcwd()
args = ['robocopy', src, dst, os.path.basename(f), '/J/W:0']
else:
args = [cp_command, f, dst]

_, err = subprocess.Popen(args, stderr=subprocess.PIPE).communicate()
_, err = subprocess.Popen(args, stderr=subprocess.PIPE, stdout=subprocess.DEVNULL).communicate()
if err:
raise ValueError(err.decode())
uploaded_files.append(f'{_base_url}_f/{uuid}/{os.path.basename(f)}')
Expand Down Expand Up @@ -966,11 +969,13 @@ async def upload(self, files: List[str]) -> List[str]:
dst = os.path.join(_waved_dir, _data_dir, 'f', uuid)
os.makedirs(dst, exist_ok=True)

args = [cp_command, f, dst]
if is_windows:
args.append('/K/O/X')
if is_windows and shutil.which('robocopy'):
src = os.path.dirname(f) or os.getcwd()
args = ['robocopy', src, dst, os.path.basename(f), '/J/W:0']
else:
args = [cp_command, f, dst]

_, err = subprocess.Popen(args, stderr=subprocess.PIPE).communicate()
_, err = subprocess.Popen(args, stderr=subprocess.PIPE, stdout=subprocess.DEVNULL).communicate()
if err:
raise ValueError(err.decode())
uploaded_files.append(f'{_base_url}_f/{uuid}/{os.path.basename(f)}')
Expand Down

0 comments on commit 8f8ef8d

Please sign in to comment.