22import json
33import re
44from pathlib import Path
5- from typing import Optional , get_type_hints
5+ from typing import Any , Optional , get_type_hints
66
77import yaml
88from pydantic import ValidationError
@@ -104,7 +104,9 @@ def populate_field(key: str, field: ModelField, debug: bool = False):
104104 console .print ("Invalid input. Please try again." , style = "red" )
105105
106106
107- def add_calibrations (key : str , field : ModelField , debug : bool = False ) -> dict :
107+ def add_calibrations (
108+ key : str , field : ModelField , debug : bool = False
109+ ) -> dict [str , dict ]:
108110 """
109111 Populate the 'calibrations' field with dictionaries.
110112 """
@@ -194,7 +196,7 @@ def get_calibration():
194196 return {}
195197
196198
197- def add_software_packages (config : dict , debug : bool = False ):
199+ def add_software_packages (config : dict , debug : bool = False ) -> dict [ str , Any ] :
198200 def ask_about_xml_path () -> bool :
199201 message = (
200202 "Does this software package have a settings file that needs modification? "
@@ -215,6 +217,7 @@ def get_software_name() -> str:
215217 prompt (
216218 "What is the name of the software package? Supported options: 'autotem', "
217219 "'epu', 'leica', 'serialem', 'tomo'" ,
220+ style = "yellow" ,
218221 )
219222 .lower ()
220223 .strip ()
@@ -297,7 +300,9 @@ def get_file_substring() -> str:
297300 return ""
298301 return substring
299302
300- # Start of get_extensions_and_substrings
303+ """
304+ Start of get_extensions_and_substrings
305+ """
301306 unsorted_dict : dict = {}
302307 add_extension = ask_for_input ("file extension" , False )
303308 while add_extension is True :
@@ -322,40 +327,62 @@ def get_file_substring() -> str:
322327 sorted_dict [key ] = unsorted_dict [key ]
323328 return sorted_dict
324329
325- # Start of add_software_packages
326- console .print ("acquisition_software" , style = "bold bright_cyan" )
330+ """
331+ Start of add_software_packages
332+ """
327333 console .print (
328- "This is where aquisition software packages present on the instrument "
329- "machine can be set." ,
330- style = "bright_cyan" ,
334+ "Acquisition Software (acquisition_software)" ,
335+ style = "bold bright_cyan" ,
331336 )
332337 console .print (
333- "Options: 'epu', 'tomo', 'serialem', 'autotem', 'leica'" ,
334- style = "bright_cyan" ,
338+ "This is where aquisition software packages present on the instrument machine "
339+ "can be specified, along with the output file names and extensions that are of "
340+ "interest." ,
341+ style = "italic bright_cyan" ,
335342 )
336343 package_info : dict = {}
337344 category = "software package"
338345 add_input = ask_for_input (category , again = False )
339346 while add_input :
340347 # Collect inputs
341- console .print ("acquisition_software" , style = "bold bright_cyan" )
348+ console .print (
349+ "Acquisition Software (acquisition_software)" ,
350+ style = "bold bright_cyan" ,
351+ )
352+ console .print (
353+ "Name of the acquisition software installed on this instrument." ,
354+ style = "italic bright_cyan" ,
355+ )
356+ console .print (
357+ "Options: 'autotem', 'epu', 'leica', 'serialem', 'tomo'" ,
358+ style = "bright_cyan" ,
359+ )
342360 name = get_software_name ()
343361 if name in package_info .keys ():
344362 if confirm_overwrite (name ) is False :
345363 add_input = ask_for_input (category , False )
346364 continue
347365
366+ console .print (
367+ "Software Versions (software_versions)" ,
368+ style = "bold bright_cyan" ,
369+ )
348370 version = prompt (
349371 "What is the version number of this software package? Press Enter to leave "
350372 "it blank if you're unsure." ,
351373 style = "yellow" ,
352374 )
353375
354- console .print ("software_settings_output_directories" , style = "bold bright_cyan" )
376+ console .print (
377+ "Software Settings Output Directories (software_settings_output_directories)" ,
378+ style = "bold bright_cyan" ,
379+ )
355380 console .print (
356381 "Some software packages will have settings files that require modification "
357- "in order to ensure files are saved to the desired folders." ,
358- style = "bright_cyan" ,
382+ "in order to ensure files are saved to the desired folders. The paths to "
383+ "the files and the path to the nodes in the settings files both need to be "
384+ "provided." ,
385+ style = "italic bright_cyan" ,
359386 )
360387 if ask_about_xml_path () is True :
361388 xml_file = get_xml_file ()
@@ -364,12 +391,15 @@ def get_file_substring() -> str:
364391 xml_file = None
365392 xml_tree_path = ""
366393
367- console .print ("data_required_substrings" , style = "bold bright_cyan" )
394+ console .print (
395+ "Data Required Substrings (data_required_substrings)" ,
396+ style = "bold bright_cyan" ,
397+ )
368398 console .print (
369399 "Different software packages will generate different output files. Only "
370400 "files with certain extensions and keywords in their filenames are needed "
371401 "for data processing. They are listed out here." ,
372- style = "bright_cyan" ,
402+ style = "italic bright_cyan" ,
373403 )
374404 file_ext_ss = get_extensions_and_substrings ()
375405
@@ -435,6 +465,73 @@ def get_file_substring() -> str:
435465 return config
436466
437467
468+ def add_data_directories (
469+ key : str , field : ModelField , debug : bool = False
470+ ) -> dict [str , str ]:
471+ def get_directory () -> Optional [Path ]:
472+ answer = prompt (
473+ "What is the full file path to the data directory you wish to add?" ,
474+ style = "yellow" ,
475+ )
476+ # Convert "" into None
477+ if not answer :
478+ return None
479+ return Path (answer )
480+
481+ def get_directory_type ():
482+ answer = prompt (
483+ "What type of data is stored in this directory? Options: 'microscope', "
484+ "'detector'" ,
485+ style = "yellow" ,
486+ ).lower ()
487+ if answer not in ("microscope" , "detector" ):
488+ console .print ("Invalid directory type." , style = "red" )
489+ if ask_for_input ("directory type" , True ) is True :
490+ return get_directory_type ()
491+ return ""
492+ return answer
493+
494+ """
495+ Start of add_data_directories
496+ """
497+ print_field_info (field )
498+ data_directories : dict [str , str ] = {}
499+ category = "data directory"
500+ add_directory = ask_for_input (category , False )
501+ while add_directory is True :
502+ directory = get_directory ()
503+ # Move on to next loop or exit if no directory provided
504+ if not directory :
505+ console .print ("No directory added" , style = "red" )
506+ add_directory = ask_for_input (category , True )
507+ continue
508+
509+ # Get the directory type
510+ directory_type = get_directory_type ()
511+ if not directory_type :
512+ console .print ("No directory type provided" , style = "red" )
513+
514+ # Add to dictionary
515+ data_directories [str (directory )] = directory_type
516+
517+ # Check if more need to be added
518+ add_directory = ask_for_input (category , True )
519+ continue
520+
521+ # Validate and return
522+ validated_data_directories , error = field .validate (data_directories , {}, loc = key )
523+ if not error :
524+ console .print (f"Validated { key !r} successfully" , style = "bright_green" )
525+ if debug :
526+ console .print (f"{ type (validated_data_directories )} " )
527+ console .print (f"{ validated_data_directories } " )
528+ return data_directories
529+ console .print (f"Failed to validate { key !r} " , style = "red" )
530+ if ask_for_input (category , True ) is True :
531+ return add_data_directories (key , field , debug )
532+ return {}
533+
534+
438535def set_up_data_transfer (config : dict , debug : bool = False ) -> dict :
439536 return config
440537
@@ -478,6 +575,7 @@ def set_up_machine_config(debug: bool = False):
478575
479576 if key == "data_directories" :
480577 # TODO
578+ new_config [key ] = add_data_directories (key , field , debug )
481579 continue
482580 if key == "create_directories" :
483581 # TODO
0 commit comments