okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-1402-w' into f-140253623e56f

main
1.1 KiB43 linesraw
1#!/usr/bin/env python3
2"""Build a server config: the current install config plus extra args/env.
3
4The same builder scripts/ab-run.sh uses inline, factored out so the report's own
5configs (the soak's, interleave500's B arm) can be reproduced from the script.
6
7Usage:
8  build_cfg.py OUT [--arg NAME VALUE]... [--env NAME=VALUE]...
9"""
10import json
11import sys
12from pathlib import Path
13
14ROOT = Path(__file__).resolve().parents[4]
15BASE = ROOT / 'strata-coder-iq1_m.json'
16
17
18def main():
19    out = sys.argv[1]
20    extras = sys.argv[2:]
21    cfg = json.loads(BASE.read_text())
22    args = list(cfg['args'])
23    env = dict(cfg.get('env') or {})
24    i = 0
25    while i < len(extras):
26        if extras[i] == '--env':
27            k, _, v = extras[i + 1].partition('=')
28            env[k] = v
29            i += 2
30        elif extras[i] == '--arg':
31            args += [extras[i + 1], extras[i + 2]]
32            i += 3
33        else:
34            raise SystemExit(f'unknown extra {extras[i]!r}')
35    cfg['args'] = args
36    if env:
37        cfg['env'] = env
38    Path(out).write_text(json.dumps(cfg, indent=2) + '\n')
39    print(f'{out}: +args {extras}')
40
41
42if __name__ == '__main__':
43    main()