@@ -327,7 +327,7 @@ def get_file_substring() -> str:
327327 name = get_software_name ()
328328 if name in package_info .keys ():
329329 if confirm_overwrite (name ) is False :
330- add_input (category , False )
330+ add_input = ask_for_input (category , False )
331331 continue
332332
333333 version = prompt (
@@ -525,38 +525,52 @@ def run():
525525 print ("Validation failed" )
526526 exit ()
527527
528- # Save the config
528+ # Save config under its instrument name
529+ master_config : dict [str , dict ] = {new_config ["instrument_name" ]: new_config }
530+
531+ # Create save path for config
529532 config_name = prompt (
530533 "Machine config successfully validated. What would you like to name the file? "
531534 "(E.g. 'my_machine_config')"
532535 )
533536 config_path = Path (prompt ("Where would you like to save this config?" ))
534537 config_file = config_path / f"{ config_name } .yaml"
535- # Create save directory
536538 config_path .mkdir (parents = True , exist_ok = True )
537539
538540 # Check if config file already exists at the location
539541 if config_file .exists ():
540- # Check if the settings at this machine already exist
541542 with open (config_file ) as existing_file :
542543 try :
543544 old_config : dict [str , dict ] = yaml .safe_load (existing_file )
544545 except yaml .YAMLError as error :
545546 console .print (error , style = "red" )
547+ # Provide option to quit or try again
548+ if ask_for_input ("machine configuration" , True ) is True :
549+ return run ()
550+ console .print ("Exiting machine configuration setup guide" )
546551 exit ()
547- for key in new_config .keys ():
552+ # Check if settings already exist for this machine
553+ for key in master_config .keys ():
548554 if key in old_config .keys ():
549- if confirm_overwrite () is False :
555+ if confirm_overwrite (key ) is False :
550556 old_config [key ].update (new_config [key ])
551557 else :
552558 old_config [key ] = new_config [key ]
553559 else :
554560 old_config [key ] = new_config [key ]
555561 # Overwrite
556- new_config = old_config
562+ master_config = old_config
557563 with open (config_file , "w" ) as save_file :
558- yaml .dump (new_config , save_file , default_flow_style = False )
564+ yaml .dump (master_config , save_file , default_flow_style = False )
559565 console .print (
560- f"Machine config file successfully created at { str (config_path )} " , styel = "green"
566+ f"Machine configuration for { new_config ['instrument_name' ]!r} "
567+ f"successfully saved as { str (config_file )!r} " ,
568+ style = "green" ,
561569 )
562- console .print ("Machine config setup complete" , style = "green" )
570+ console .print ("Machine configuration complete" , style = "green" )
571+
572+ # Provide option to set up another machine configuration
573+ if ask_for_input ("machine configuration" , True ) is True :
574+ return run ()
575+ console .print ("Exiting machine configuration setup guide" )
576+ exit ()
0 commit comments