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

28 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-21 15:31 +0000

1#!/usr/bin/env python3 

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

3 

4import sys 

5import itertools 

6import argparse 

7from pathlib import Path 

8 

9from sparkle.CLI.help import snapshot_help 

10from sparkle.CLI.help import logging as sl 

11from sparkle.CLI.help import argparse_custom as ac 

12from sparkle.CLI.help import global_variables as gv 

13 

14 

15def parser_function() -> argparse.ArgumentParser: 

16 """Define the command line arguments.""" 

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

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

19 return parser 

20 

21 

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

23 """Main function of the command.""" 

24 # Log command call 

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

26 

27 # Define command line arguments 

28 parser = parser_function() 

29 # Process command line arguments 

30 args = parser.parse_args(argv) 

31 snapshot_help.load_snapshot(Path(args.snapshot_file_path)) 

32 # Make sure we have Solver/Extractor execution rights again after unpacking 

33 for executable_dir in itertools.chain( 

34 gv.settings().DEFAULT_solver_dir.iterdir(), 

35 gv.settings().DEFAULT_extractor_dir.iterdir(), 

36 ): 

37 if executable_dir.is_dir(): 

38 for file in executable_dir.iterdir(): 

39 if file.is_file(): 

40 file.chmod(0o755) 

41 

42 # Reset Global variables as they should be re-read from snapshot 

43 gv.__settings = None 

44 gv.__configuration_scenarios = None 

45 gv.__selection_scenarios = None 

46 sys.exit(0) 

47 

48 

49if __name__ == "__main__": 

50 main(sys.argv[1:])