Coverage for sparkle/CLI/remove_feature_extractor.py: 85%
40 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-05 14:48 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-05 14:48 +0000
1#!/usr/bin/env python3
2"""Sparkle command to remove a feature extractor from the Sparkle platform."""
4import sys
5import argparse
6import shutil
8from sparkle.platform import file_help as sfh
9from sparkle.CLI.help import global_variables as gv
10from sparkle.structures import FeatureDataFrame
11from sparkle.CLI.help import logging as sl
12from sparkle.platform import CommandName, COMMAND_DEPENDENCIES
13from sparkle.CLI.initialise import check_for_initialise
14from sparkle.CLI.help import argparse_custom as ac
15from sparkle.CLI.help.nicknames import resolve_object_name
16from sparkle.solver import Extractor
19def parser_function() -> argparse.ArgumentParser:
20 """Define the command line arguments."""
21 parser = argparse.ArgumentParser(description="Remove a feature extractor "
22 "from the platform.")
23 parser.add_argument(*ac.ExtractorPathArgument.names,
24 **ac.ExtractorPathArgument.kwargs)
25 return parser
28def main(argv: list[str]) -> None:
29 """Main function of the remove feature extractor command."""
30 # Log command call
31 sl.log_command(sys.argv)
33 # Define command line arguments
34 parser = parser_function()
36 # Process command line arguments
37 args = parser.parse_args(argv)
38 extractor_nicknames = gv.file_storage_data_mapping[gv.extractor_nickname_list_path]
39 extractor = resolve_object_name(
40 args.extractor_path,
41 extractor_nicknames,
42 gv.settings().DEFAULT_extractor_dir,
43 class_name=Extractor)
45 check_for_initialise(COMMAND_DEPENDENCIES[CommandName.REMOVE_FEATURE_EXTRACTOR])
47 if extractor is None:
48 print(f'Feature extractor path "{args.extractor_path}" does not exist!')
49 sys.exit(-1)
51 print(f"Starting removing feature extractor {extractor.name} ...")
53 for key in extractor_nicknames:
54 if extractor_nicknames == extractor.directory:
55 sfh.add_remove_platform_item(
56 None,
57 gv.extractor_nickname_list_path,
58 extractor_nicknames,
59 key=key,
60 remove=True)
61 break
63 if gv.settings().DEFAULT_feature_data_path.exists():
64 feature_data = FeatureDataFrame(gv.settings().DEFAULT_feature_data_path)
65 feature_data.remove_extractor(extractor.name)
66 feature_data.save_csv()
67 shutil.rmtree(extractor.directory)
69 print(f"Removing feature extractor {extractor.name} done!")
70 sys.exit(0)
73if __name__ == "__main__":
74 main(sys.argv[1:])