Skip to content

Commit 2170797

Browse files
committed
\Adding Enum for data type
1 parent 394906e commit 2170797

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

python/fedml/api/modules/storage.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import requests
66
import math
7+
from enum import Enum, unique
78

89
import requests.exceptions
910
import tqdm
@@ -26,6 +27,10 @@ def __init__(self, data: dict):
2627
self.tag_list = data.get("tags", None)
2728
self.download_url = data.get("fileUrl", None)
2829

30+
class DataType(Enum):
31+
FILE = "file"
32+
DIRECTORY = "directory"
33+
INVALID = "invalid"
2934

3035
# Todo (alaydshah): Store service name in metadata
3136
# Todo (alaydshah): If data already exists, don't upload again. Instead suggest to use update command
@@ -41,10 +46,10 @@ def upload(data_path, api_key, name, description, tag_list, service, show_progre
4146

4247
data_type = _get_data_type(data_path)
4348

44-
if(data_type == "invalid"):
49+
if(data_type == DataType.INVALID):
4550
return FedMLResponse(code=ResponseCode.FAILURE,message="Invalid data path")
4651

47-
if(data_type == "dir"):
52+
if(data_type == DataType.DIRECTORY):
4853
to_upload_path, message = _archive_data(data_path)
4954
name = os.path.splitext(os.path.basename(to_upload_path))[0] if name is None else name
5055
file_name = name + ".zip"
@@ -471,10 +476,10 @@ def _get_storage_service(service):
471476

472477
def _get_data_type(data_path):
473478
if os.path.isdir(data_path):
474-
return "dir"
479+
return DataType.DIRECTORY
475480
elif os.path.isfile(data_path):
476-
return "file"
477-
return "invalid"
481+
return DataType.FILE
482+
return DataType.INVALID
478483

479484

480485
def _archive_data(data_path: str) -> (str, str):

0 commit comments

Comments
 (0)