github.com/letsencrypt/boulder@v0.20251208.0/test/format-configs.py (about) 1 #!/usr/bin/env python3 2 3 import argparse 4 import glob 5 import json 6 import sys 7 8 parser = argparse.ArgumentParser() 9 parser.add_argument('globs', nargs='+', help='List of JSON file globs') 10 parser.add_argument('--write', action='store_true', help='Write out formatted files') 11 args = parser.parse_args() 12 13 needs_format = [] 14 15 for pattern in args.globs: 16 for cfg in glob.glob(pattern): 17 with open(cfg, "r") as fr: 18 existing = fr.read() 19 j = json.loads(existing) 20 new = json.dumps(j, indent="\t") 21 new += "\n" 22 if new != existing: 23 if args.write: 24 with open(cfg, "w") as fw: 25 fw.write(new) 26 else: 27 needs_format.append(cfg) 28 29 if len(needs_format) > 0: 30 print("Files need reformatting:") 31 for file in needs_format: 32 print(f"\t{file}") 33 print("Run ./test/format-configs.py --write 'test/config*/*.json'") 34 sys.exit(1)