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

29 statements  

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

1#!/usr/bin/env python3 

2"""Command to remove temporary files not affecting the platform state.""" 

3import sys 

4import argparse 

5import shutil 

6 

7from sparkle.CLI.help import logging as sl 

8from sparkle.CLI.help import global_variables as gv 

9from sparkle.CLI.help import argparse_custom as ac 

10from sparkle.CLI.help import snapshot_help as snh 

11 

12 

13def parser_function() -> argparse.ArgumentParser: 

14 """Define the command line arguments.""" 

15 parser = argparse.ArgumentParser() 

16 parser.add_argument(*ac.CleanupArgumentAll.names, **ac.CleanupArgumentAll.kwargs) 

17 parser.add_argument(*ac.CleanupArgumentRemove.names, 

18 **ac.CleanupArgumentRemove.kwargs) 

19 return parser 

20 

21 

22def remove_temporary_files() -> None: 

23 """Remove temporary files. Only removes files not affecting the sparkle state.""" 

24 shutil.rmtree(gv.settings().DEFAULT_log_output, ignore_errors=True) 

25 gv.settings().DEFAULT_log_output.mkdir() 

26 

27 

28if __name__ == "__main__": 

29 # Log command call 

30 sl.log_command(sys.argv) 

31 

32 # Define command line arguments 

33 parser = parser_function() 

34 

35 # Process command line arguments 

36 args = parser.parse_args() 

37 if args.all: 

38 shutil.rmtree(gv.settings().DEFAULT_output, ignore_errors=True) 

39 snh.create_working_dirs() 

40 print("Removed all output files from the platform!") 

41 elif args.remove: 

42 snh.remove_current_platform() 

43 snh.create_working_dirs() 

44 print("Cleaned platform of all files!") 

45 else: 

46 remove_temporary_files() 

47 print("Cleaned platform of temporary files!")