66from pathlib import Path
77from shutil import move
88from tempfile import TemporaryDirectory
9- from warnings import simplefilter
109
1110import requests
1211from cmem .cmempy .api import config , get_access_token
2928from cmem_plugin_base .dataintegration .utils import setup_cmempy_user_access
3029from filesplit .split import Split
3130from pathvalidate import is_valid_filepath
32- from urllib3 .exceptions import InsecureRequestWarning
3331
3432from cmem_plugin_splitfile .doc import SPLITFILE_DOC
3533from cmem_plugin_splitfile .resource_parameter_type import ResourceParameterType
3634
37- simplefilter ("ignore" , category = InsecureRequestWarning )
35+ DEFAULT_PROJECT_DIR = "/data/datalake"
36+ SIZE_UNIT_KB = "kb"
37+ SIZE_UNIT_MB = "mb"
38+ SIZE_UNIT_GB = "gb"
39+ SIZE_UNIT_LINES = "lines"
40+ SIZE_UNIT_PARAMETER_CHOICES = OrderedDict (
41+ {
42+ SIZE_UNIT_KB : "KB" ,
43+ SIZE_UNIT_MB : "MB" ,
44+ SIZE_UNIT_GB : "GB" ,
45+ SIZE_UNIT_LINES : "lines" ,
46+ }
47+ )
3848
3949
4050@Plugin (
5666 description = "The maximum size of the chunk files." ,
5767 ),
5868 PluginParameter (
59- param_type = ChoiceParameterType (
60- OrderedDict ({"KB" : "KB" , "MB" : "MB" , "GB" : "GB" , "lines" : "Lines" })
61- ),
69+ param_type = ChoiceParameterType (SIZE_UNIT_PARAMETER_CHOICES ),
6270 name = "size_unit" ,
6371 label = "Size unit" ,
6472 description = """The unit of the size value: kilobyte (KB), megabyte (MB), gigabyte (GB),
96104 label = "Internal projects directory" ,
97105 description = """The path to the internal projects directory. If "Use internal projects
98106 directory" is disabled, this parameter has no effect.""" ,
99- default_value = "/data/datalake" ,
107+ default_value = DEFAULT_PROJECT_DIR ,
100108 advanced = True ,
101109 ),
102110 ],
@@ -108,26 +116,28 @@ def __init__( # noqa: C901 PLR0913
108116 self ,
109117 input_filename : str ,
110118 chunk_size : float ,
111- size_unit : str = "MB" ,
119+ size_unit : str = SIZE_UNIT_MB ,
112120 include_header : bool = False ,
113121 delete_file : bool = False ,
114122 use_directory : bool = False ,
115- projects_path : str = "/data/datalake" ,
123+ projects_path : str = DEFAULT_PROJECT_DIR ,
116124 ) -> None :
117125 errors = ""
118126 if not is_valid_filepath (input_filename ):
119127 errors += 'Invalid filename for parameter "Input filename". '
120128
121129 self .lines = False
122- match size_unit .lower ():
123- case "kb" :
124- chunk_size *= 1024
125- case "mb" :
126- chunk_size *= 1048576
127- case "gb" :
128- chunk_size *= 1073741824
129- case "lines" :
130- self .lines = True
130+ size_unit = size_unit .lower ()
131+ if size_unit == SIZE_UNIT_KB :
132+ chunk_size *= 1024
133+ elif size_unit == SIZE_UNIT_MB :
134+ chunk_size *= 1048576
135+ elif size_unit == SIZE_UNIT_GB :
136+ chunk_size *= 1073741824
137+ elif size_unit == SIZE_UNIT_LINES :
138+ self .lines = True
139+ else :
140+ errors += "Invalid size unit. "
131141
132142 if self .lines :
133143 if int (chunk_size ) != chunk_size or chunk_size < 1 :
0 commit comments