Coverage for sparkle/CLI/remove_feature_extractor.py: 0%

37 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-27 09:10 +0000

1#!/usr/bin/env python3 

2"""Sparkle command to remove a feature extractor from the Sparkle platform.""" 

3 

4import sys 

5import argparse 

6import shutil 

7 

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 

17 

18 

19def parser_function() -> argparse.ArgumentParser: 

20 """Define the command line arguments.""" 

21 parser = argparse.ArgumentParser() 

22 parser.add_argument(*ac.ExtractorPathArgument.names, 

23 **ac.ExtractorPathArgument.kwargs) 

24 return parser 

25 

26 

27if __name__ == "__main__": 

28 # Log command call 

29 sl.log_command(sys.argv) 

30 

31 # Define command line arguments 

32 parser = parser_function() 

33 

34 # Process command line arguments 

35 args = parser.parse_args() 

36 extractor_nicknames = gv.file_storage_data_mapping[gv.extractor_nickname_list_path] 

37 extractor = resolve_object_name( 

38 args.extractor_path, 

39 extractor_nicknames, 

40 gv.settings().DEFAULT_extractor_dir, 

41 class_name=Extractor) 

42 

43 check_for_initialise(COMMAND_DEPENDENCIES[CommandName.REMOVE_FEATURE_EXTRACTOR]) 

44 

45 if extractor is None: 

46 print(f'Feature extractor path "{args.extractor_path}" does not exist!') 

47 sys.exit(-1) 

48 

49 print(f"Starting removing feature extractor {extractor.name} ...") 

50 

51 for key in extractor_nicknames: 

52 if extractor_nicknames == extractor.directory: 

53 sfh.add_remove_platform_item( 

54 None, 

55 gv.extractor_nickname_list_path, 

56 extractor_nicknames, 

57 key=key, 

58 remove=True) 

59 break 

60 

61 if gv.settings().DEFAULT_feature_data_path.exists(): 

62 feature_data = FeatureDataFrame(gv.settings().DEFAULT_feature_data_path) 

63 feature_data.remove_extractor(extractor.name) 

64 feature_data.save_csv() 

65 shutil.rmtree(extractor.directory) 

66 

67 print(f"Removing feature extractor {extractor.name} done!")