1414from .utils .config import get_config_data
1515
1616
17- def not_empty (key : str , value : str ) -> None | NoReturn :
18- if value == "" or value == "." :
19- title , message = ConfigError .field_emty_error
20- echo_error ((title .format (key ), message .format (key )))
17+ def not_empty (
18+ key : str , value : str , section : str = "FCLOUD" , quit_afer : bool = True
19+ ) -> None | NoReturn :
20+ if not (value == "" or value == "." ):
21+ return
22+
23+ title , message = ConfigError .field_emty_error
24+ echo_error (
25+ (title .format (key ), message .format (section , key )),
26+ need_to_quit = quit_afer ,
27+ )
2128
2229
2330def read_config (available_clouds : list [str ], path : Optional [Path ] = None ) -> Config :
@@ -26,29 +33,32 @@ def read_config(available_clouds: list[str], path: Optional[Path] = None) -> Con
2633
2734 if not path .exists ():
2835 echo_error (ConfigError .config_not_found )
29-
3036 config = configparser .ConfigParser ()
3137 config .read (path , encoding = "utf-8" )
3238
39+ # service
3340 cloud = get_config_data (
3441 "FCLOUD" , "service" , error = ConfigError .service_error , config = config
3542 ).lower ()
3643 if cloud not in available_clouds :
3744 title , message = DriverError .driver_error
3845 echo_error ((title , message .format (cloud )))
3946
40- cloud_settings = get_config_data (
41- cloud .upper (), error = ConfigError .section_error , config = config
42- )
43-
47+ # cfl_extension
4448 cfl_extension = get_config_data ("FCLOUD" , "cfl_extension" , config = config )
4549
50+ # main_folder
4651 main_folder = Path (
4752 get_config_data (
4853 "FCLOUD" , "main_folder" , error = ConfigError .main_folder_error , config = config
4954 )
5055 ).as_posix ()
5156
57+ # Section, for cloud storage settings
58+ cloud_settings = get_config_data (
59+ cloud .upper (), error = ConfigError .section_error , config = config
60+ )
61+
5262 auth_model = AuthData [cloud .lower ()].value
5363
5464 fields = {
@@ -57,7 +67,8 @@ def read_config(available_clouds: list[str], path: Optional[Path] = None) -> Con
5767 "main_folder" : main_folder ,
5868 }
5969 for key , value in (fields | dict (cloud_settings )).items ():
60- not_empty (key , value )
70+ section = "FCLOUD" if key in fields else cloud
71+ not_empty (key , value , section .upper ())
6172
6273 return Config (
6374 service = cloud ,
0 commit comments