44
55import requests
66import math
7+ from enum import Enum , unique
78
89import requests .exceptions
910import 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
472477def _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
480485def _archive_data (data_path : str ) -> (str , str ):
0 commit comments