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.10, created at 2025-01-21 01:50 +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 ( 

18 open(fname_input, encoding="utf-8") as fh_tunables, 

19 open(fname_output, "w", encoding="utf-8", newline="") as fh_config, 

20 ): 

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

22 line = f"{key} {val}" 

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

24 print(line) 

25 

26 

27if __name__ == "__main__": 

28 parser = argparse.ArgumentParser( 

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

30 ) 

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

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

33 args = parser.parse_args() 

34 _main(args.input, args.output)