Coverage for sparkle/CLI/cleanup.py: 78%
32 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"""Command to remove temporary files not affecting the platform state."""
3import sys
4import argparse
5import shutil
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
13def parser_function() -> argparse.ArgumentParser:
14 """Define the command line arguments."""
15 parser = argparse.ArgumentParser(description="Command to clean files from the "
16 "platform.")
17 parser.add_argument(*ac.CleanupArgumentAll.names, **ac.CleanupArgumentAll.kwargs)
18 parser.add_argument(*ac.CleanupArgumentRemove.names,
19 **ac.CleanupArgumentRemove.kwargs)
20 return parser
23def remove_temporary_files() -> None:
24 """Remove temporary files. Only removes files not affecting the sparkle state."""
25 shutil.rmtree(gv.settings().DEFAULT_log_output, ignore_errors=True)
26 gv.settings().DEFAULT_log_output.mkdir()
29def main(argv: list[str]) -> None:
30 """Main function of the cleanup command."""
31 # Log command call
32 sl.log_command(sys.argv)
34 # Define command line arguments
35 parser = parser_function()
37 # Process command line arguments
38 args = parser.parse_args(argv)
39 if args.all:
40 shutil.rmtree(gv.settings().DEFAULT_output, ignore_errors=True)
41 snh.create_working_dirs()
42 print("Removed all output files from the platform!")
43 elif args.remove:
44 snh.remove_current_platform()
45 snh.create_working_dirs()
46 print("Cleaned platform of all files!")
47 else:
48 remove_temporary_files()
49 print("Cleaned platform of temporary files!")
50 sys.exit(0)
53if __name__ == "__main__":
54 main(sys.argv[1:])