Coverage for mlos_bench/mlos_bench/config/environments/os/linux/boot/scripts/local/generate_grub_config.py: 38%

8 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-22 01:18 +0000

1#!/usr/bin/env python3 

2# 

3# Copyright (c) Microsoft Corporation. 

4# Licensed under the MIT License. 

5# 

6""" 

7Helper script to generate GRUB config from tunable parameters JSON. 

8 

9Run: `./generate_grub_config.py ./input-boot-params.json ./output-grub.cfg` 

10""" 

11 

12import argparse 

13import json 

14 

15 

16def _main(fname_input: str, fname_output: str) -> None: 

17 with open(fname_input, "rt", encoding="utf-8") as fh_tunables, open( 

18 fname_output, "wt", encoding="utf-8", newline="" 

19 ) as fh_config: 

20 for key, val in json.load(fh_tunables).items(): 

21 line = f'GRUB_CMDLINE_LINUX_DEFAULT="${ GRUB_CMDLINE_LINUX_DEFAULT} {key}={val}"' 

22 fh_config.write(line + "\n") 

23 print(line) 

24 

25 

26if __name__ == "__main__": 

27 parser = argparse.ArgumentParser( 

28 description="Generate GRUB config from tunable parameters JSON." 

29 ) 

30 parser.add_argument("input", help="JSON file with tunable parameters.") 

31 parser.add_argument("output", help="Output shell script to configure GRUB.") 

32 args = parser.parse_args() 

33 _main(args.input, args.output)