44
55from xdg .BaseDirectory import xdg_config_home
66
7- if os .getenv ("FIREFLY_CLI_CONFIG" ):
8- config_file_path = Path (os .environ ["FIREFLY_CLI_CONFIG" ])
9- else :
10- config_file_path = Path (xdg_config_home ).joinpath ("firefly-cli" , "firefly-cli.ini" )
117
12- # Create dir if not exists
13- config_file_path .parent .mkdir (parents = True , exist_ok = True )
8+ def config_file_path ():
9+ if os .getenv ("FIREFLY_CLI_CONFIG" ):
10+ config_file_path = Path (os .environ ["FIREFLY_CLI_CONFIG" ])
11+ else :
12+ config_file_path = Path (xdg_config_home ).joinpath (
13+ "firefly-cli" , "firefly-cli.ini"
14+ )
15+
16+ # Create dir if not exists
17+ config_file_path .parent .mkdir (parents = True , exist_ok = True )
18+
19+ return config_file_path
1420
1521
1622def load_configs ():
1723 configs = configparser .ConfigParser ()
1824
1925 # No config file loaded because it was not available/not existent
20- if len (configs .read (config_file_path )) < 1 :
26+ if len (configs .read (config_file_path () )) < 1 :
2127 print ("File not found, creating the file.." )
2228
23- with open (config_file_path , "w" ) as f :
29+ with open (config_file_path () , "w" ) as f :
2430 configs ["firefly-cli" ] = {}
2531 save_configs_to_file (configs )
2632
@@ -29,12 +35,12 @@ def load_configs():
2935
3036def save_configs_to_file (configs ):
3137 try :
32- with open (config_file_path , "w" ) as f :
38+ with open (config_file_path () , "w" ) as f :
3339 configs .write (f )
34- print ("Config file saved at {}" .format (str (config_file_path )))
40+ print ("Config file saved at {}" .format (str (config_file_path () )))
3541 except :
3642 print (
3743 "An error has occurred while saving file to {}" .format (
38- str (config_file_path )
44+ str (config_file_path () )
3945 )
4046 )
0 commit comments