Skip to content

Commit 03c58a2

Browse files
committed
changes in the download to support files
1 parent 505103f commit 03c58a2

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

python/fedml/api/modules/storage.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,26 @@ def download(data_name, api_key, service, dest_path, show_progress=True) -> FedM
110110
logging.error(error_message)
111111
return FedMLResponse(code=ResponseCode.FAILURE, message=error_message)
112112
download_url = metadata.download_url
113-
zip_file_name = data_name + ".zip"
114-
path_local = os.path.abspath(zip_file_name)
113+
given_extension = os.path.splitext(data_name)[1]
114+
is_file = True
115+
if(given_extension is None or given_extension ==""):
116+
is_file = False
117+
118+
if not is_file:
119+
download_file_name = data_name + ".zip"
120+
else:
121+
download_file_name = data_name
122+
path_local = os.path.abspath(download_file_name)
115123
dest_path = os.path.abspath(dest_path) if dest_path else data_name
116-
if _download_using_presigned_url(download_url, zip_file_name, show_progress=show_progress):
124+
if _download_using_presigned_url(download_url, download_file_name, show_progress=show_progress):
117125
try:
118-
shutil.unpack_archive(path_local, dest_path)
119-
os.remove(path_local)
126+
if not is_file:
127+
shutil.unpack_archive(path_local, dest_path)
128+
os.remove(path_local)
129+
else:
130+
if not os.path.exists(dest_path):
131+
os.makedirs(dest_path)
132+
shutil.move(path_local,dest_path)
120133
abs_dest_path = os.path.abspath(dest_path)
121134
return FedMLResponse(code=ResponseCode.SUCCESS, message=f"Successfully downloaded and unzipped data at "
122135
f"{abs_dest_path}", data=abs_dest_path)

python/fedml/cli/modules/storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def validate_argument(ctx, param, value):
4747
@click.help_option("--help", "-h")
4848
@click.argument("data_path", nargs=1, callback=validate_argument)
4949
@click.option("--name", "-n", type=str, help="Name your data to store. If not provided, the name will be the same as "
50-
"the data file or directory name.")
50+
"the data file or directory name. For files, extension need not be mentioned!")
5151
@click.option("--description", "-d", type=str, help="Add description to your data to store. If not provided, "
5252
"the description will be empty.")
5353
@click.option("--user_metadata", "-um", type=str, help="User-defined metadata in the form of a dictionary, for instance, "

0 commit comments

Comments
 (0)