1+ import os
12import storage
23import microcontroller
3- import os
44
55# Get all files in the format of .env.xxxxxxxxxx
66def enumerate_env_files ():
7- env_files = []
7+ found_files = []
88 all_files = os .listdir ("/" )
9- for file in all_files :
10- if file [:4 ] == ".env" and len (file ) > 4 :
11- env_files .append (file )
12- return env_files
9+ for current_file in all_files :
10+ if current_file [:4 ] == ".env" and len (current_file ) > 4 :
11+ found_files .append (current_file )
12+ return found_files
13+
1314
1415# Compare .env to enumerated env files
15- def get_current_env_file (env_files ):
16- with open (' .env' ) as env :
16+ def get_current_env_file (enumerated_files ):
17+ with open (" .env" ) as env :
1718 env_lines = env .readlines ()
18- for env_file in env_files :
19+ for env_file in enumerated_files :
1920 with open (env_file ) as f :
2021 lines = f .readlines ()
2122 if len (env_lines ) != len (lines ):
@@ -30,12 +31,13 @@ def get_current_env_file(env_files):
3031 return env_file
3132 return None
3233
34+
3335# Erase .env then write the contents of the new env file
3436def change_env_file (env_file ):
3537 try :
3638 storage .remount ("/" , False )
37- open (' .env' , 'w' ).close ()
38- with open (' .env' , 'w' ) as env , open (env_file ) as f :
39+ open (" .env" , "w" ).close ()
40+ with open (" .env" , "w" ) as env , open (env_file ) as f :
3941 for line in f .readlines ():
4042 env .write (line )
4143 env .close ()
@@ -44,6 +46,7 @@ def change_env_file(env_file):
4446 except RuntimeError :
4547 print ("You can't change the env file with this script while USB is mounted" )
4648
49+
4750# Return a prettier name than the env file
4851def pretty_name (env_file ):
4952 name = env_file [5 :]
@@ -62,16 +65,16 @@ def pretty_name(env_file):
6265if len (env_files ) == 1 :
6366 answer = input (f"Change to { pretty_name (env_files [0 ])} ? " )
6467 answer = answer .lower ()
65- if answer == "y" or answer == "yes" :
68+ if answer in ( "y" , "yes" ) :
6669 change_env_file (env_files [0 ])
6770else :
6871 valid_selection = False
6972 while not valid_selection :
7073 print ("Select an option:" )
7174 for index , file in enumerate (env_files ):
7275 print (f"{ index + 1 } : { pretty_name (file )} " )
73- answer = input (f "Which option would you like? " )
76+ answer = input ("Which option would you like? " )
7477 if answer .isdigit () and 0 < int (answer ) <= len (env_files ):
7578 valid_selection = True
7679 change_env_file (env_files [int (answer ) - 1 ])
77- print (f"{ answer } was an invalid selection.\n " )
80+ print (f"{ answer } was an invalid selection.\n " )
0 commit comments