Coverage for sparkle/CLI/load_snapshot.py: 96%
26 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-07 15:22 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-07 15:22 +0000
1#!/usr/bin/env python3
2"""Sparkle command to load a Sparkle platform from a .zip file."""
3import sys
4import argparse
5from pathlib import Path
7from sparkle.CLI.help import snapshot_help
8from sparkle.CLI.help import logging as sl
9from sparkle.CLI.help import argparse_custom as ac
10from sparkle.CLI.help import global_variables as gv
13def parser_function() -> argparse.ArgumentParser:
14 """Define the command line arguments."""
15 parser = argparse.ArgumentParser(description="Load a platform from a zip file.")
16 parser.add_argument(*ac.SnapshotArgument.names,
17 **ac.SnapshotArgument.kwargs)
18 return parser
21def main(argv: list[str]) -> None:
22 """Main function of the command."""
23 # Log command call
24 sl.log_command(sys.argv)
26 # Define command line arguments
27 parser = parser_function()
28 # Process command line arguments
29 args = parser.parse_args(argv)
30 snapshot_help.load_snapshot(Path(args.snapshot_file_path))
31 # Make sure we have Solver execution rights again after unpacking
32 for solver in gv.settings().DEFAULT_solver_dir.iterdir():
33 if solver.is_dir():
34 for file in solver.iterdir():
35 if file.is_file():
36 file.chmod(0o755)
37 # Reset Global variables as they should be re-read from snapshot
38 gv.__settings = None
39 gv.__latest_scenario = None
40 sys.exit(0)
43if __name__ == "__main__":
44 main(sys.argv[1:])