Coverage for sparkle/CLI/load_snapshot.py: 96%

26 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-09-29 10:17 +0000

1#!/usr/bin/env python3 

2"""Sparkle command to load a Sparkle platform from a .zip file.""" 

3 

4import sys 

5import argparse 

6from pathlib import Path 

7 

8from sparkle.CLI.help import snapshot_help 

9from sparkle.CLI.help import logging as sl 

10from sparkle.CLI.help import argparse_custom as ac 

11from sparkle.CLI.help import global_variables as gv 

12 

13 

14def parser_function() -> argparse.ArgumentParser: 

15 """Define the command line arguments.""" 

16 parser = argparse.ArgumentParser(description="Load a platform from a zip file.") 

17 parser.add_argument(*ac.SnapshotArgument.names, **ac.SnapshotArgument.kwargs) 

18 return parser 

19 

20 

21def main(argv: list[str]) -> None: 

22 """Main function of the command.""" 

23 # Log command call 

24 sl.log_command(sys.argv, gv.settings().random_state) 

25 

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) 

41 

42 

43if __name__ == "__main__": 

44 main(sys.argv[1:])