Coverage for mlos_bench/mlos_bench/config/environments/apps/redis/scripts/local/generate_redis_config.py: 38%

8 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 00:44 +0000

1#!/usr/bin/env python3 

2# 

3# Copyright (c) Microsoft Corporation. 

4# Licensed under the MIT License. 

5# 

6""" 

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

8 

9Run: `./generate_redis_config.py ./input-params.json ./output-redis.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"{key} {val}" 

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

23 print(line) 

24 

25 

26if __name__ == "__main__": 

27 parser = argparse.ArgumentParser( 

28 description="generate Redis config from tunable parameters JSON." 

29 ) 

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

31 parser.add_argument("output", help="Output Redis config file.") 

32 args = parser.parse_args() 

33 _main(args.input, args.output)