Skip to content

Commit a8e66eb

Browse files
committed
Replaced parts of 'add_software_package' with the generic list and dict constructors
1 parent 24f3a49 commit a8e66eb

File tree

1 file changed

+20
-48
lines changed

1 file changed

+20
-48
lines changed

src/murfey/cli/generate_config.py

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -457,52 +457,6 @@ def get_xml_tree_path() -> str:
457457
# TODO: Currently no test cases for this method
458458
return xml_tree_path
459459

460-
def get_extensions_and_substrings() -> dict[str, list[str]]:
461-
def get_file_extension() -> str:
462-
message = (
463-
"Please enter the extension of a file produced by this package "
464-
"that is to be analysed (e.g., '.tiff', '.eer', etc.)."
465-
)
466-
extension = prompt(message, style="yellow").strip().lower()
467-
# Validate
468-
if not (extension.startswith(".") and extension.replace(".", "").isalnum()):
469-
console.print(
470-
"This is an invalid file extension. Please try again. ",
471-
style="red",
472-
)
473-
return get_file_extension()
474-
if extension in extension_dict.keys():
475-
console.print("This extension has already been provided")
476-
return ""
477-
return extension
478-
479-
"""
480-
Start of get_extensions_and_substrings
481-
"""
482-
extension_dict: dict = {}
483-
add_extension = ask_for_input("file extension", False)
484-
while add_extension is True:
485-
extension = get_file_extension()
486-
if not extension:
487-
add_extension = ask_for_input("file extension", True)
488-
continue
489-
substrings: list[str] = construct_list(
490-
"file substring",
491-
allow_empty=False,
492-
allow_eval=False,
493-
many_types=False,
494-
restrict_to_types=str,
495-
sort_values=True,
496-
)
497-
extension_dict[extension] = substrings
498-
add_extension = ask_for_input("file extension", True)
499-
continue
500-
501-
extension_dict = {
502-
key: extension_dict[key] for key in sorted(extension_dict.keys())
503-
}
504-
return extension_dict
505-
506460
"""
507461
Start of add_software_packages
508462
"""
@@ -580,14 +534,32 @@ def get_file_extension() -> str:
580534
"for data processing. They are listed out here.",
581535
style="italic bright_cyan",
582536
)
583-
file_ext_ss = get_extensions_and_substrings()
537+
extensions_and_substrings = construct_dict(
538+
dict_name="file extension configuration",
539+
key_name="file extension",
540+
value_name="file substrings",
541+
value_method=construct_list,
542+
value_method_args={
543+
"value_name": "file substring",
544+
"allow_empty": False,
545+
"allow_eval": False,
546+
"many_types": False,
547+
"restrict_to_types": str,
548+
"sort_values": True,
549+
},
550+
allow_empty_key=False,
551+
allow_empty_value=False,
552+
allow_eval=False,
553+
sort_keys=True,
554+
restrict_to_types=list,
555+
)
584556

585557
# Compile keys for this package as a dict
586558
package_info[name] = {
587559
"version": version,
588560
"xml_file": xml_file,
589561
"xml_tree_path": xml_tree_path,
590-
"extensions_and_substrings": file_ext_ss,
562+
"extensions_and_substrings": extensions_and_substrings,
591563
}
592564
add_input = ask_for_input(category, again=True)
593565
continue

0 commit comments

Comments
 (0)