summaryrefslogtreecommitdiff
path: root/scripts/build-component-versions
blob: 5362dbdd4246920cc920ce421ca776282cfe8740 (plain)
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
42
43
44
45
46
47
#!/usr/bin/env python3

import sys
import os
import argparse
import json

from lxml import etree as ET

parser = argparse.ArgumentParser()
parser.add_argument('INPUT_DIR', type=str,
                    help="Directory containing XML interface definition files")
parser.add_argument('OUTPUT_DIR', type=str,
                    help="Output directory for JSON file")

args = parser.parse_args()

input_dir = args.INPUT_DIR
output_dir = args.OUTPUT_DIR

version_dict = {}

for filename in os.listdir(input_dir):
    filepath = os.path.join(input_dir, filename)
    print(filepath)
    try:
        xml = ET.parse(filepath)
    except Exception as e:
        print("Failed to load interface definition file {0}".format(filename))
        print(e)
        sys.exit(1)

    root = xml.getroot()
    version_data = root.iterfind("syntaxVersion")
    for ver in version_data:
        component = ver.get("component")
        version = int(ver.get("version"))

        v = version_dict.get(component)
        if v is None:
            version_dict[component] = version
        elif version > v:
            version_dict[component] = version

out_file = os.path.join(output_dir, 'component-versions.json')
with open(out_file, 'w') as f:
    json.dump(version_dict, f, indent=4, sort_keys=True)