File: validate_json.py

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb11u3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,245,360 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (41 lines) | stat: -rwxr-xr-x 1,233 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python

import os
import sys
import json


def find_redirect_map_file(folder, errors):
    for root, _dirs, files in os.walk(folder):
        for name in files:
            if not name.endswith("redirect-map.json"):
                continue
            with open(os.path.join(root, name)) as f:
                data = json.load(f)
            with open("expected.json") as f:
                expected = json.load(f)
            for key in expected:
                if expected[key] != data.get(key):
                    errors.append("Expected `{}` for key `{}`, found: `{}`".format(
                        expected[key], key, data.get(key)))
                else:
                    del data[key]
            for key in data:
                errors.append("Extra data not expected: key: `{}`, data: `{}`".format(
                    key, data[key]))
            return True
    return False


if len(sys.argv) != 2:
    print("Expected doc directory to check!")
    sys.exit(1)

errors = []
if not find_redirect_map_file(sys.argv[1], errors):
    print("Didn't find the map file in `{}`...".format(sys.argv[1]))
    sys.exit(1)
for err in errors:
    print("=> {}".format(err))
if len(errors) != 0:
    sys.exit(1)